diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-13 03:08:26 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-13 03:08:26 +0000 |
commit | 2fc7740f3ca1ca5e5a88f9f4136d631f7650bac7 (patch) | |
tree | 7cf264cf713a0372160954b055d5b27227e5e375 /spec/support | |
parent | 8dc1e72e2b5cb6112d5468194580edb186de4659 (diff) | |
download | gitlab-ce-2fc7740f3ca1ca5e5a88f9f4136d631f7650bac7.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/shared_examples/controllers/known_sign_in_shared_examples.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/support/shared_examples/controllers/known_sign_in_shared_examples.rb b/spec/support/shared_examples/controllers/known_sign_in_shared_examples.rb new file mode 100644 index 00000000000..60abb76acec --- /dev/null +++ b/spec/support/shared_examples/controllers/known_sign_in_shared_examples.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'known sign in' do + def stub_remote_ip(ip) + request.remote_ip = ip + end + + def stub_user_ip(ip) + user.update!(current_sign_in_ip: ip) + end + + context 'with a valid post' do + context 'when remote IP does not match user last sign in IP' do + before do + stub_user_ip('127.0.0.1') + stub_remote_ip('169.0.0.1') + end + + it 'notifies the user' do + expect_next_instance_of(NotificationService) do |instance| + expect(instance).to receive(:unknown_sign_in) + end + + post_action + end + end + + context 'when remote IP matches an active session' do + before do + existing_sessions = ActiveSession.session_ids_for_user(user.id) + existing_sessions.each { |sessions| ActiveSession.destroy(user, sessions) } + + stub_user_ip('169.0.0.1') + stub_remote_ip('127.0.0.1') + + ActiveSession.set(user, request) + end + + it 'does not notify the user' do + expect_any_instance_of(NotificationService).not_to receive(:unknown_sign_in) + + post_action + end + end + + context 'when remote IP address matches last sign in IP' do + before do + stub_user_ip('127.0.0.1') + stub_remote_ip('127.0.0.1') + end + + it 'does not notify the user' do + expect_any_instance_of(NotificationService).not_to receive(:unknown_sign_in) + + post_action + end + end + end +end |