diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-04-06 21:10:23 +0200 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-04-06 21:10:23 +0200 |
commit | b368c7502931aa06121ecad8a97193b1f17cf90a (patch) | |
tree | 2b598363926388d30a4c5c6197436b46f6d4610a /spec/lib | |
parent | 00c9363f07081e0149533023992fba47dd905384 (diff) | |
parent | dd4c156f33a24b8bb89b45b2697aa4036c3ae5be (diff) |
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `app/controllers/concerns/sign_in_token_authentication_concern.rb`: Upstream removed this file, while glitch-soc had changes to deal with its theming system. Removed the file like upstream did.
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/suspicious_sign_in_detector_spec.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/lib/suspicious_sign_in_detector_spec.rb b/spec/lib/suspicious_sign_in_detector_spec.rb new file mode 100644 index 000000000..101a18aa0 --- /dev/null +++ b/spec/lib/suspicious_sign_in_detector_spec.rb @@ -0,0 +1,57 @@ +require 'rails_helper' + +RSpec.describe SuspiciousSignInDetector do + describe '#suspicious?' do + let(:user) { Fabricate(:user, current_sign_in_at: 1.day.ago) } + let(:request) { double(remote_ip: remote_ip) } + let(:remote_ip) { nil } + + subject { described_class.new(user).suspicious?(request) } + + context 'when user has 2FA enabled' do + before do + user.update!(otp_required_for_login: true) + end + + it 'returns false' do + expect(subject).to be false + end + end + + context 'when exact IP has been used before' do + let(:remote_ip) { '1.1.1.1' } + + before do + user.update!(sign_up_ip: remote_ip) + end + + it 'returns false' do + expect(subject).to be false + end + end + + context 'when similar IP has been used before' do + let(:remote_ip) { '1.1.2.2' } + + before do + user.update!(sign_up_ip: '1.1.1.1') + end + + it 'returns false' do + expect(subject).to be false + end + end + + context 'when IP is completely unfamiliar' do + let(:remote_ip) { '2.2.2.2' } + + before do + user.update!(sign_up_ip: '1.1.1.1') + end + + it 'returns true' do + expect(subject).to be true + end + end + end +end |