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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
01cac53d
Commit
01cac53d
authored
Jul 23, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it easier to stub authentication metrics
parent
68547bc0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
15 deletions
+31
-15
lib/gitlab/auth/activity.rb
lib/gitlab/auth/activity.rb
+15
-11
spec/support/helpers/stub_metrics.rb
spec/support/helpers/stub_metrics.rb
+16
-4
No files found.
lib/gitlab/auth/activity.rb
View file @
01cac53d
...
...
@@ -23,35 +23,35 @@ module Gitlab
end
def
user_authentication_failed!
self
.
class
.
user_unauthenticated_counter
.
increment
self
.
class
.
user_unauthenticated_counter
_increment!
case
@opts
[
:message
]
when
:not_found_in_database
self
.
class
.
user_not_found_counter
.
increment
self
.
class
.
user_not_found_counter
_increment!
when
:invalid
self
.
class
.
user_password_invalid_counter
.
increment
self
.
class
.
user_password_invalid_counter
_increment!
end
if
@user
.
present?
&&
@user
.
blocked?
self
.
class
.
user_blocked_counter
.
increment
self
.
class
.
user_blocked_counter
_increment!
end
end
def
user_authenticated!
self
.
class
.
user_authenticated_counter
.
increment
self
.
class
.
user_authenticated_counter
_increment!
end
def
user_session_override!
self
.
class
.
user_authenticated_counter
.
increment
self
.
class
.
user_session_override_counter
.
increment
self
.
class
.
user_authenticated_counter
_increment!
self
.
class
.
user_session_override_counter
_increment!
if
@opts
[
:message
]
==
:two_factor_authenticated
self
.
class
.
user_two_factor_authenticated_counter
.
increment
self
.
class
.
user_two_factor_authenticated_counter
_increment!
end
end
def
user_signed_out!
self
.
class
.
user_signed_out_counter
.
increment
self
.
class
.
user_signed_out_counter
_increment!
end
def
self
.
each_counter
...
...
@@ -62,10 +62,14 @@ module Gitlab
each_counter
do
|
counter
,
metric
,
description
|
define_singleton_method
(
counter
)
do
strong_memoize
(
metric
)
do
Gitlab
::
Metrics
.
counter
(
"gitlab_auth_
#{
metric
}
_total"
.
to_sym
,
description
)
strong_memoize
(
counter
)
do
Gitlab
::
Metrics
.
counter
(
"gitlab_auth_
#{
metric
}
_total"
,
description
)
end
end
define_singleton_method
(
"
#{
counter
}
_increment!"
)
do
public_send
(
counter
).
increment
# rubocop:disable GitlabSecurity/PublicSend
end
end
end
end
...
...
spec/support/helpers/stub_metrics.rb
View file @
01cac53d
...
...
@@ -6,11 +6,23 @@ module StubMetrics
def
stub_authentication_activity_metrics
(
debug:
false
)
authentication_metrics
.
each_counter
do
|
name
,
metric
,
description
|
double
(
"
#{
metric
}
-
#{
description
}
"
).
tap
do
|
counter
|
allow
(
counter
).
to
receive
(
:increment
)
do
puts
"Authentication activity metric incremented:
#{
metric
}
"
end
allow
(
authentication_metrics
).
to
receive
(
name
).
and_return
(
counter
)
allow
(
counter
).
to
receive
(
:increment
)
# TODO, require expectations
end
end
debug_authentication_activity_metrics
if
debug
end
def
debug_authentication_activity_metrics
authentication_metrics
.
tap
do
|
metrics
|
metrics
.
each_counter
do
|
name
,
metric
|
"
#{
name
}
_increment!"
.
tap
do
|
incrementer
|
allow
(
metrics
).
to
receive
(
incrementer
).
and_wrap_original
do
|
method
|
puts
"Authentication activity metric incremented:
#{
name
}
"
method
.
call
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