Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
14053e9f
Commit
14053e9f
authored
Sep 30, 2020
by
Michał Zając
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create CalculateFindingUUID service object
parent
e07e69c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
0 deletions
+73
-0
ee/lib/gitlab/vulnerabilities/calculate_finding_uuid.rb
ee/lib/gitlab/vulnerabilities/calculate_finding_uuid.rb
+28
-0
ee/spec/lib/gitlab/vulnerabilities/calculate_finding_uuid_spec.rb
...lib/gitlab/vulnerabilities/calculate_finding_uuid_spec.rb
+45
-0
No files found.
ee/lib/gitlab/vulnerabilities/calculate_finding_uuid.rb
0 → 100644
View file @
14053e9f
# frozen_string_literal: true
module
Gitlab
module
Vulnerabilities
class
CalculateFindingUUID
FINDING_NAMESPACES_IDS
=
{
development:
"a143e9e2-41b3-47bc-9a19-081d089229f4"
,
test:
"a143e9e2-41b3-47bc-9a19-081d089229f4"
,
staging:
"a6930898-a1b2-4365-ab18-12aa474d9b26"
,
production:
"58dc0f06-936c-43b3-93bb-71693f1b6570"
}.
freeze
NAMESPACE_REGEX
=
/(\h{8})-(\h{4})-(\h{4})-(\h{4})-(\h{4})(\h{8})/
.
freeze
PACK_PATTERN
=
"NnnnnN"
.
freeze
def
self
.
call
(
value
)
Digest
::
UUID
.
uuid_v5
(
namespace_id
,
value
)
end
def
self
.
namespace_id
namespace_uuid
=
FINDING_NAMESPACES_IDS
.
fetch
(
Rails
.
env
.
to_sym
)
# Digest::UUID is broken when using an UUID in namespace_id
# https://github.com/rails/rails/issues/37681#issue-520718028
namespace_uuid
.
scan
(
NAMESPACE_REGEX
).
flatten
.
map
{
|
s
|
s
.
to_i
(
16
)
}.
pack
(
PACK_PATTERN
)
end
end
end
end
ee/spec/lib/gitlab/vulnerabilities/calculate_finding_uuid_spec.rb
0 → 100644
View file @
14053e9f
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Vulnerabilities
::
CalculateFindingUUID
do
let_it_be
(
:value
)
{
"GitLab"
}
subject
{
described_class
.
call
(
value
)
}
context
'in development'
do
let_it_be
(
:development_proper_uuid
)
{
"5b593e54-90f5-504b-8805-5394a4d14b94"
}
before
do
allow
(
Rails
).
to
receive
(
:env
).
and_return
(
:development
)
end
it
{
is_expected
.
to
eq
(
development_proper_uuid
)
}
end
context
'in test'
do
let_it_be
(
:test_proper_uuid
)
{
"5b593e54-90f5-504b-8805-5394a4d14b94"
}
it
{
is_expected
.
to
eq
(
test_proper_uuid
)
}
end
context
'in staging'
do
let_it_be
(
:staging_proper_uuid
)
{
"dd190b37-7754-5c7c-80a0-85621a5823ad"
}
before
do
allow
(
Rails
).
to
receive
(
:env
).
and_return
(
:staging
)
end
it
{
is_expected
.
to
eq
(
staging_proper_uuid
)
}
end
context
'in production'
do
let_it_be
(
:production_proper_uuid
)
{
"4961388b-9d8e-5da0-a499-3ef5da58daf0"
}
before
do
allow
(
Rails
).
to
receive
(
:env
).
and_return
(
:production
)
end
it
{
is_expected
.
to
eq
(
production_proper_uuid
)
}
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment