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
98bd48c6
Commit
98bd48c6
authored
Feb 22, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup test phases by introducing request_from_ip and operation_from_ip helers
parent
2ff139dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
21 deletions
+19
-21
spec/support/unique_ip_check_shared_examples.rb
spec/support/unique_ip_check_shared_examples.rb
+19
-21
No files found.
spec/support/unique_ip_check_shared_examples.rb
View file @
98bd48c6
...
@@ -16,6 +16,17 @@ shared_context 'unique ips sign in limit' do
...
@@ -16,6 +16,17 @@ shared_context 'unique ips sign in limit' do
def
change_ip
(
ip
)
def
change_ip
(
ip
)
allow
(
Gitlab
::
RequestContext
).
to
receive
(
:client_ip
).
and_return
(
ip
)
allow
(
Gitlab
::
RequestContext
).
to
receive
(
:client_ip
).
and_return
(
ip
)
end
end
def
request_from_ip
(
ip
)
change_ip
(
ip
)
request
response
end
def
operation_from_ip
(
ip
)
change_ip
(
ip
)
operation
end
end
end
shared_examples
'user login operation with unique ip limit'
do
shared_examples
'user login operation with unique ip limit'
do
...
@@ -23,17 +34,13 @@ shared_examples 'user login operation with unique ip limit' do
...
@@ -23,17 +34,13 @@ shared_examples 'user login operation with unique ip limit' do
before
{
current_application_settings
.
update!
(
unique_ips_limit_per_user:
1
)
}
before
{
current_application_settings
.
update!
(
unique_ips_limit_per_user:
1
)
}
it
'allows user authenticating from the same ip'
do
it
'allows user authenticating from the same ip'
do
change_ip
(
'ip'
)
expect
{
operation_from_ip
(
'ip'
)
}.
not_to
raise_error
expect
{
operation
}.
not_to
raise_error
expect
{
operation_from_ip
(
'ip'
)
}.
not_to
raise_error
expect
{
operation
}.
not_to
raise_error
end
end
it
'blocks user authenticating from two distinct ips'
do
it
'blocks user authenticating from two distinct ips'
do
change_ip
(
'ip'
)
expect
{
operation_from_ip
(
'ip'
)
}.
not_to
raise_error
expect
{
operation
}.
not_to
raise_error
expect
{
operation_from_ip
(
'ip2'
)
}.
to
raise_error
(
Gitlab
::
Auth
::
TooManyIps
)
change_ip
(
'ip2'
)
expect
{
operation
}.
to
raise_error
(
Gitlab
::
Auth
::
TooManyIps
)
end
end
end
end
end
end
...
@@ -43,22 +50,13 @@ shared_examples 'user login request with unique ip limit' do |success_status = 2
...
@@ -43,22 +50,13 @@ shared_examples 'user login request with unique ip limit' do |success_status = 2
before
{
current_application_settings
.
update!
(
unique_ips_limit_per_user:
1
)
}
before
{
current_application_settings
.
update!
(
unique_ips_limit_per_user:
1
)
}
it
'allows user authenticating from the same ip'
do
it
'allows user authenticating from the same ip'
do
change_ip
(
'ip'
)
expect
(
request_from_ip
(
'ip'
)).
to
have_http_status
(
success_status
)
request
expect
(
request_from_ip
(
'ip'
)).
to
have_http_status
(
success_status
)
expect
(
response
).
to
have_http_status
(
success_status
)
request
expect
(
response
).
to
have_http_status
(
success_status
)
end
end
it
'blocks user authenticating from two distinct ips'
do
it
'blocks user authenticating from two distinct ips'
do
change_ip
(
'ip'
)
expect
(
request_from_ip
(
'ip'
)).
to
have_http_status
(
success_status
)
request
expect
(
request_from_ip
(
'ip2'
)).
to
have_http_status
(
403
)
expect
(
response
).
to
have_http_status
(
success_status
)
change_ip
(
'ip2'
)
request
expect
(
response
).
to
have_http_status
(
403
)
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