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
69bf9241
Commit
69bf9241
authored
Jan 27, 2021
by
Quang-Minh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor rack attack test assessments
parent
0abeefaf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
19 deletions
+19
-19
spec/lib/gitlab/rack_attack/instrumented_cache_store_spec.rb
spec/lib/gitlab/rack_attack/instrumented_cache_store_spec.rb
+18
-18
spec/requests/rack_attack_global_spec.rb
spec/requests/rack_attack_global_spec.rb
+1
-1
No files found.
spec/lib/gitlab/rack_attack/instrumented_cache_store_spec.rb
View file @
69bf9241
...
...
@@ -29,15 +29,11 @@ RSpec.describe Gitlab::RackAttack::InstrumentedCacheStore do
with_them
do
it
'publishes a notification'
do
published
=
false
event
=
nil
begin
subscriber
=
ActiveSupport
::
Notifications
.
subscribe
(
"redis.rack_attack"
)
do
|*
args
|
published
=
true
event
=
ActiveSupport
::
Notifications
::
Event
.
new
(
*
args
)
expect
(
event
.
name
).
to
eq
(
"redis.rack_attack"
)
expect
(
event
.
duration
).
to
be_a
(
Float
).
and
(
be
>
0.0
)
expect
(
event
.
payload
[
:operation
]).
to
eql
(
operation
)
end
subject
.
send
(
operation
,
*
params
)
{}
...
...
@@ -45,35 +41,39 @@ RSpec.describe Gitlab::RackAttack::InstrumentedCacheStore do
ActiveSupport
::
Notifications
.
unsubscribe
(
subscriber
)
if
subscriber
end
expect
(
published
).
to
be
(
true
)
expect
(
event
).
not_to
be_nil
expect
(
event
.
name
).
to
eq
(
"redis.rack_attack"
)
expect
(
event
.
duration
).
to
be_a
(
Float
).
and
(
be
>
0.0
)
expect
(
event
.
payload
[
:operation
]).
to
eql
(
operation
)
end
it
'publishes a notification even if the cache store returns an error'
do
allow
(
store
).
to
receive
(
operation
).
and_raise
(
"Some thing went wrong"
)
published
=
false
exception
=
false
allow
(
store
).
to
receive
(
operation
).
and_raise
(
'Something went wrong'
)
event
=
nil
exception
=
nil
begin
subscriber
=
ActiveSupport
::
Notifications
.
subscribe
(
"redis.rack_attack"
)
do
|*
args
|
published
=
true
event
=
ActiveSupport
::
Notifications
::
Event
.
new
(
*
args
)
expect
(
event
.
name
).
to
eq
(
"redis.rack_attack"
)
expect
(
event
.
duration
).
to
be_a
(
Float
).
and
(
be
>
0.0
)
expect
(
event
.
payload
[
:operation
]).
to
eql
(
operation
)
end
begin
subject
.
send
(
operation
,
*
params
)
{}
rescue
# Ignore the error
exception
=
true
rescue
=>
e
exception
=
e
end
ensure
ActiveSupport
::
Notifications
.
unsubscribe
(
subscriber
)
if
subscriber
end
expect
(
published
).
to
be
(
true
)
expect
(
exception
).
to
be
(
true
)
expect
(
event
).
not_to
be_nil
expect
(
event
.
name
).
to
eq
(
"redis.rack_attack"
)
expect
(
event
.
duration
).
to
be_a
(
Float
).
and
(
be
>
0.0
)
expect
(
event
.
payload
[
:operation
]).
to
eql
(
operation
)
expect
(
exception
).
not_to
be_nil
expect
(
exception
.
message
).
to
eql
(
'Something went wrong'
)
end
it
'delegates to the upstream store'
do
...
...
spec/requests/rack_attack_global_spec.rb
View file @
69bf9241
...
...
@@ -158,7 +158,7 @@ RSpec.describe 'Rack Attack global throttles', :use_clean_rails_memory_store_cac
matched:
'throttle_unauthenticated'
})
expect
(
Gitlab
::
AuthLogger
).
to
receive
(
:error
).
with
(
arguments
)
.
at_least
(
:once
)
expect
(
Gitlab
::
AuthLogger
).
to
receive
(
:error
).
with
(
arguments
)
get
url_that_does_not_require_authentication
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