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
33e11345
Commit
33e11345
authored
Jul 20, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add custom expectations for authentication activity metrics
parent
ac4b954c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
8 deletions
+31
-8
lib/gitlab/auth/activity.rb
lib/gitlab/auth/activity.rb
+8
-2
spec/features/users/login_spec.rb
spec/features/users/login_spec.rb
+5
-1
spec/lib/gitlab/auth/activity_spec.rb
spec/lib/gitlab/auth/activity_spec.rb
+2
-2
spec/support/helpers/stub_configuration.rb
spec/support/helpers/stub_configuration.rb
+11
-0
spec/support/prometheus/custom_matchers.rb
spec/support/prometheus/custom_matchers.rb
+5
-3
No files found.
lib/gitlab/auth/activity.rb
View file @
33e11345
...
...
@@ -47,8 +47,14 @@ module Gitlab
self
.
class
.
user_signed_out_counter
.
increment
end
def
self
.
each_counter
COUNTERS
.
each_pair
do
|
metric
,
description
|
define_singleton_method
(
"
#{
metric
}
_counter"
)
do
yield
"
#{
metric
}
_counter"
,
metric
,
description
end
end
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
)
end
...
...
spec/features/users/login_spec.rb
View file @
33e11345
...
...
@@ -3,6 +3,10 @@ require 'spec_helper'
describe
'Login'
do
include
TermsHelper
before
do
stub_authentication_activity_metrics
end
it
'Successful user signin invalidates password reset token'
do
user
=
create
(
:user
)
...
...
@@ -29,7 +33,6 @@ describe 'Login' do
User
.
delete_all
user
=
create
(
:admin
,
password_automatically_set:
true
)
expect
(
Gitlab
::
Auth
::
Activity
).
to
increment
(
:user_authenticated_counter
)
visit
root_path
expect
(
current_path
).
to
eq
edit_user_password_path
...
...
@@ -47,6 +50,7 @@ describe 'Login' do
click_button
'Sign in'
expect
(
current_path
).
to
eq
root_path
expect
(
authentication_metrics
).
to
have_incremented
(
:user_authenticated_counter
)
end
it
'does not show flash messages when login page'
do
...
...
spec/lib/gitlab/auth/activity_spec.rb
View file @
33e11345
...
...
@@ -3,8 +3,8 @@ require 'spec_helper'
describe
Gitlab
::
Auth
::
Activity
do
describe
'counters'
do
it
'has all static counters defined'
do
described_class
::
COUNTERS
.
each_key
do
|
metric
|
expect
(
described_class
).
to
respond_to
(
"
#{
metric
}
_counter"
)
described_class
.
each_counter
do
|
counter
|
expect
(
described_class
).
to
respond_to
(
counter
)
end
end
end
...
...
spec/support/helpers/stub_configuration.rb
View file @
33e11345
...
...
@@ -68,6 +68,17 @@ module StubConfiguration
allow
(
Gitlab
.
config
.
repositories
).
to
receive
(
:storages
).
and_return
(
Settingslogic
.
new
(
messages
))
end
def
authentication_metrics
Gitlab
::
Auth
::
Activity
end
def
stub_authentication_activity_metrics
authentication_metrics
.
each_counter
do
|
counter
,
metric
,
description
|
allow
(
authentication_metrics
).
to
receive
(
counter
)
.
and_return
(
spy
(
"
#{
metric
}
-
#{
description
}
"
))
end
end
private
# Modifies stubbed messages to also stub possible predicate versions
...
...
spec/support/prometheus/custom_matchers.rb
View file @
33e11345
RSpec
::
Matchers
.
define
:increment
do
|
counter
|
match
do
|
metric
|
expect
(
metric
.
send
(
counter
)).
to
receive
(
:increment
)
RSpec
::
Matchers
.
define
:have_incremented
do
|
counter
|
match
do
|
adapter
|
matcher
=
RSpec
::
Mocks
::
Matchers
::
HaveReceived
.
new
(
:increment
)
matcher
.
matches?
(
adapter
.
send
(
counter
))
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