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
42a4f238
Commit
42a4f238
authored
Feb 10, 2020
by
Michał Zając
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use FactoryBot to create objects
parent
66e8b9af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
49 deletions
+45
-49
ee/db/fixtures/development/20_vulnerabilities.rb
ee/db/fixtures/development/20_vulnerabilities.rb
+45
-49
No files found.
ee/db/fixtures/development/20_vulnerabilities.rb
View file @
42a4f238
...
...
@@ -36,55 +36,55 @@ class Gitlab::Seeder::Vulnerabilities
private
def
create_vulnerability
vulnerability
=
project
.
vulnerabilities
.
build
(
state_symbol
=
::
Vulnerability
.
states
.
keys
.
sample
.
to_sym
vulnerability
=
build_vulnerability
(
state_symbol
)
case
state_symbol
when
:resolved
vulnerability
.
resolved_by
=
author
when
:dismissed
vulnerability
.
closed_by
=
author
end
vulnerability
.
tap
(
&
:save!
)
end
def
build_vulnerability
(
state_symbol
)
FactoryBot
.
build
(
:vulnerability
,
state_symbol
,
project:
project
,
author:
author
,
title:
'Cypher with no integrity'
,
severity:
random_severity_level
,
confidence:
random_confidence_level
,
report_type:
random_report_type
)
vulnerability
=
set_random_vulnerability_state
(
vulnerability
)
vulnerability
.
save!
vulnerability
end
def
set_random_vulnerability_state
(
vulnerability
)
state
=
::
Vulnerability
.
states
.
keys
.
sample
vulnerability
.
state
=
state
case
state
when
"resolved"
vulnerability
.
resolved_by
=
vulnerability
.
author
vulnerability
.
resolved_at
=
Time
.
now
when
"dismissed"
vulnerability
.
closed_by
=
vulnerability
.
author
vulnerability
.
closed_at
=
Time
.
now
end
vulnerability
end
def
create_occurrence
(
vulnerability
,
rank
,
primary_identifier
)
project
.
vulnerability_findings
.
create!
(
FactoryBot
.
create
(
:vulnerabilities_occurrence
,
project:
project
,
vulnerability:
vulnerability
,
uuid:
random_uuid
,
name:
'Cipher with no integrity'
,
report_type: :sast
,
severity:
random_severity_level
,
confidence:
random_confidence_level
,
primary_identifier:
primary_identifier
,
project_fingerprint:
random_fingerprint
,
location_fingerprint:
random_fingerprint
,
primary_identifier:
primary_identifier
,
raw_metadata:
metadata
(
rank
).
to_json
,
metadata_version:
'sast:1.0'
,
scanner:
scanner
)
raw_metadata:
metadata
(
rank
).
to_json
)
end
def
create_identifier
(
rank
)
project
.
vulnerability_identifiers
.
create!
(
FactoryBot
.
create
(
:vulnerability_identifier
,
external_type:
"SECURITY_ID"
,
external_id:
"SECURITY_
#{
rank
}
"
,
fingerprint:
random_fingerprint
,
name:
"SECURITY_IDENTIFIER
#{
rank
}
"
,
url:
"https://security.example.com/
#{
rank
}
"
url:
"https://security.example.com/
#{
rank
}
"
,
project:
project
)
end
...
...
@@ -94,33 +94,33 @@ class Gitlab::Seeder::Vulnerabilities
create_vulnerability_issue_link
(
vulnerability
,
issue
)
end
project
.
vulnerability_feedback
.
create!
(
FactoryBot
.
create
(
:vulnerability_feedback
,
feedback_type:
type
,
category:
'sast'
,
project:
project
,
author:
author
,
issue:
issue
,
pipeline:
pipeline
,
project_fingerprint:
occurrence
.
project_fingerprint
,
vulnerability_data:
{
category:
'sast'
})
end
def
create_vulnerability_issue_link
(
vulnerability
,
issue
)
::
Vulnerabilities
::
IssueLink
.
create!
(
vulnerability:
vulnerability
,
issue:
issue
,
link_type: :created
project_fingerprint:
occurrence
.
project_fingerprint
)
end
def
scanner
@scanner
||=
project
.
vulnerability_scanners
.
create!
(
def
create_issue
(
title
)
FactoryBot
.
create
(
:issue
,
project:
project
,
external_id:
'security-scanner'
,
name:
'Security Scanner'
)
author:
author
,
title:
title
)
end
def
create_issue
(
title
)
project
.
issues
.
create!
(
author:
author
,
title:
title
)
def
create_vulnerability_issue_link
(
vulnerability
,
issue
)
FactoryBot
.
create
(
:vulnerabilities_issue_link
,
:created
,
vulnerability:
vulnerability
,
issue:
issue
)
end
def
random_confidence_level
...
...
@@ -155,10 +155,6 @@ class Gitlab::Seeder::Vulnerabilities
}
end
def
random_uuid
SecureRandom
.
hex
(
18
)
end
def
random_fingerprint
SecureRandom
.
hex
(
20
)
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