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
5188faea
Commit
5188faea
authored
Oct 21, 2021
by
Marcos Rocha
Committed by
Bob Van Landuyt
Oct 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Audit dast schedule owner updates
parent
1222dd09
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
18 deletions
+54
-18
ee/app/services/app_sec/dast/profile_schedules/audit/update_service.rb
...es/app_sec/dast/profile_schedules/audit/update_service.rb
+1
-1
ee/app/services/app_sec/dast/profiles/update_service.rb
ee/app/services/app_sec/dast/profiles/update_service.rb
+10
-4
ee/spec/services/app_sec/dast/profiles/update_service_spec.rb
...pec/services/app_sec/dast/profiles/update_service_spec.rb
+43
-13
No files found.
ee/app/services/app_sec/dast/profile_schedules/audit/update_service.rb
View file @
5188faea
...
@@ -16,7 +16,7 @@ module AppSec
...
@@ -16,7 +16,7 @@ module AppSec
author:
current_user
,
author:
current_user
,
scope:
project
,
scope:
project
,
target:
params
[
:dast_profile_schedule
],
target:
params
[
:dast_profile_schedule
],
message:
"Changed DAST profile schedule
#{
property
}
from
#{
old_value
}
to
#{
new_value
}
"
message:
"Changed DAST profile schedule
#{
property
}
from
#{
old_value
||
'nil'
}
to
#{
new_value
}
"
)
)
end
end
end
end
...
...
ee/app/services/app_sec/dast/profiles/update_service.rb
View file @
5188faea
...
@@ -52,9 +52,7 @@ module AppSec
...
@@ -52,9 +52,7 @@ module AppSec
def
update_or_create_schedule!
def
update_or_create_schedule!
if
schedule
if
schedule
attributes
=
schedule_input_params
schedule
.
update!
(
schedule_input_params
)
attributes
=
attributes
.
merge
(
user_id:
current_user
.
id
)
unless
schedule
.
owner_valid?
schedule
.
update!
(
attributes
)
else
else
::
Dast
::
ProfileSchedule
.
new
(
::
Dast
::
ProfileSchedule
.
new
(
dast_profile:
dast_profile
,
dast_profile:
dast_profile
,
...
@@ -93,9 +91,17 @@ module AppSec
...
@@ -93,9 +91,17 @@ module AppSec
end
end
def
schedule_input_params
def
schedule_input_params
@schedule_input_params
||=
build_schedule_input_params
end
def
build_schedule_input_params
return
unless
params
[
:dast_profile_schedule
]
# params[:dast_profile_schedule] is `Types::Dast::ProfileScheduleInputType` object.
# params[:dast_profile_schedule] is `Types::Dast::ProfileScheduleInputType` object.
# Using to_h method to convert object into equivalent hash.
# Using to_h method to convert object into equivalent hash.
@schedule_input_params
||=
params
[
:dast_profile_schedule
]
&
.
to_h
dast_profile_schedule_params
=
params
[
:dast_profile_schedule
]
dast_profile_schedule_params
[
:user_id
]
=
current_user
.
id
unless
schedule
&
.
owner_valid?
dast_profile_schedule_params
&
.
to_h
end
end
def
build_auditors!
def
build_auditors!
...
...
ee/spec/services/app_sec/dast/profiles/update_service_spec.rb
View file @
5188faea
...
@@ -63,6 +63,7 @@ RSpec.describe AppSec::Dast::Profiles::UpdateService do
...
@@ -63,6 +63,7 @@ RSpec.describe AppSec::Dast::Profiles::UpdateService do
project
.
add_users
([
user
,
scheduler_owner
],
:developer
)
project
.
add_users
([
user
,
scheduler_owner
],
:developer
)
end
end
context
'without dast_profile_schedule param'
do
it
'communicates success'
do
it
'communicates success'
do
expect
(
subject
.
status
).
to
eq
(
:success
)
expect
(
subject
.
status
).
to
eq
(
:success
)
end
end
...
@@ -78,6 +79,19 @@ RSpec.describe AppSec::Dast::Profiles::UpdateService do
...
@@ -78,6 +79,19 @@ RSpec.describe AppSec::Dast::Profiles::UpdateService do
end
end
end
end
it
'does not try to create or update the dast_profile_schedule'
do
subject
expect
{
subject
}.
not_to
change
{
dast_profile
.
reload
.
dast_profile_schedule
}.
from
(
nil
)
end
it
'ignores the dast_profile_schedule'
do
subject
expect
(
params
[
:dast_profile
]).
not_to
receive
(
:dast_profile_schedule
)
end
end
context
'with dast_profile_schedule param'
do
context
'with dast_profile_schedule param'
do
let_it_be
(
:time_zone
)
{
Time
.
zone
.
tzinfo
.
name
}
let_it_be
(
:time_zone
)
{
Time
.
zone
.
tzinfo
.
name
}
...
@@ -130,6 +144,16 @@ RSpec.describe AppSec::Dast::Profiles::UpdateService do
...
@@ -130,6 +144,16 @@ RSpec.describe AppSec::Dast::Profiles::UpdateService do
context
'when associated schedule is present'
do
context
'when associated schedule is present'
do
let_it_be_with_reload
(
:dast_profile_schedule
)
{
create
(
:dast_profile_schedule
,
project:
project
,
dast_profile:
dast_profile
,
owner:
scheduler_owner
)
}
let_it_be_with_reload
(
:dast_profile_schedule
)
{
create
(
:dast_profile_schedule
,
project:
project
,
dast_profile:
dast_profile
,
owner:
scheduler_owner
)
}
shared_examples
'audits the owner change'
do
it
'audits the owner change'
,
:sidekiq_inline
do
subject
messages
=
AuditEvent
.
where
(
target_id:
dast_profile
.
dast_profile_schedule
.
id
).
pluck
(
:details
).
pluck
(
:custom_message
)
old_owner
=
User
.
find_by
(
id:
scheduler_owner
.
id
)
expect
(
messages
).
to
include
(
"Changed DAST profile schedule user_id from
#{
old_owner
&
.
id
||
'nil'
}
to
#{
user
.
id
}
"
)
end
end
it
'updates the dast profile schedule'
do
it
'updates the dast profile schedule'
do
subject
subject
...
@@ -155,15 +179,17 @@ RSpec.describe AppSec::Dast::Profiles::UpdateService do
...
@@ -155,15 +179,17 @@ RSpec.describe AppSec::Dast::Profiles::UpdateService do
context
'when the owner was deleted'
do
context
'when the owner was deleted'
do
before
do
before
do
scheduler_
owner
.
destroy!
dast_profile_schedule
.
owner
.
destroy!
subject
.
payload
[
:dast_profile_schedule
]
.
reload
dast_profile_schedule
.
reload
end
end
it
'updates the schedule owner'
do
it
'updates the schedule owner'
do
subject
subject
expect
(
dast_profile_schedule
.
user_id
).
to
eq
(
user
.
id
)
expect
(
dast_profile_schedule
.
reload
.
user_id
).
to
eq
(
user
.
id
)
end
end
include_examples
'audits the owner change'
end
end
context
'when the owner permission was downgraded'
do
context
'when the owner permission was downgraded'
do
...
@@ -176,6 +202,8 @@ RSpec.describe AppSec::Dast::Profiles::UpdateService do
...
@@ -176,6 +202,8 @@ RSpec.describe AppSec::Dast::Profiles::UpdateService do
expect
(
dast_profile_schedule
.
user_id
).
to
eq
(
user
.
id
)
expect
(
dast_profile_schedule
.
user_id
).
to
eq
(
user
.
id
)
end
end
include_examples
'audits the owner change'
end
end
context
'when the owner was removed from the project'
do
context
'when the owner was removed from the project'
do
...
@@ -189,6 +217,8 @@ RSpec.describe AppSec::Dast::Profiles::UpdateService do
...
@@ -189,6 +217,8 @@ RSpec.describe AppSec::Dast::Profiles::UpdateService do
expect
(
dast_profile_schedule
.
user_id
).
to
eq
(
user
.
id
)
expect
(
dast_profile_schedule
.
user_id
).
to
eq
(
user
.
id
)
end
end
include_examples
'audits the owner change'
end
end
end
end
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