2019-08-14 17:33:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe SessionsHelper do
|
2021-06-27 23:07:37 -04:00
|
|
|
describe '#recently_confirmed_com?' do
|
|
|
|
subject { helper.recently_confirmed_com? }
|
|
|
|
|
|
|
|
context 'when on .com' do
|
|
|
|
before do
|
2022-03-10 22:08:14 -05:00
|
|
|
allow(Gitlab).to receive(:com?).and_return(true)
|
2021-06-27 23:07:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'when flash notice is empty it is false' do
|
|
|
|
flash[:notice] = nil
|
|
|
|
expect(subject).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'when flash notice is anything it is false' do
|
|
|
|
flash[:notice] = 'hooray!'
|
|
|
|
expect(subject).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'when flash notice is devise confirmed message it is true' do
|
|
|
|
flash[:notice] = t(:confirmed, scope: [:devise, :confirmations])
|
|
|
|
expect(subject).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not on .com' do
|
|
|
|
before do
|
2022-03-10 22:08:14 -05:00
|
|
|
allow(Gitlab).to receive(:com?).and_return(false)
|
2021-06-27 23:07:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'when flash notice is devise confirmed message it is false' do
|
|
|
|
flash[:notice] = t(:confirmed, scope: [:devise, :confirmations])
|
|
|
|
expect(subject).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-14 17:33:39 -04:00
|
|
|
describe '#unconfirmed_email?' do
|
|
|
|
it 'returns true when the flash alert contains a devise failure unconfirmed message' do
|
|
|
|
flash[:alert] = t(:unconfirmed, scope: [:devise, :failure])
|
|
|
|
expect(helper.unconfirmed_email?).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when the flash alert does not contain a devise failure unconfirmed message' do
|
|
|
|
flash[:alert] = 'something else'
|
|
|
|
expect(helper.unconfirmed_email?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
2022-07-01 11:08:30 -04:00
|
|
|
|
|
|
|
describe '#send_rate_limited?' do
|
|
|
|
let_it_be(:user) { build(:user) }
|
|
|
|
|
|
|
|
subject { helper.send_rate_limited?(user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(::Gitlab::ApplicationRateLimiter)
|
|
|
|
.to receive(:peek)
|
|
|
|
.with(:email_verification_code_send, scope: user)
|
|
|
|
.and_return(rate_limited)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when rate limited' do
|
|
|
|
let(:rate_limited) { true }
|
|
|
|
|
|
|
|
it { is_expected.to eq(true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not rate limited' do
|
|
|
|
let(:rate_limited) { false }
|
|
|
|
|
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#obfuscated_email' do
|
|
|
|
subject { helper.obfuscated_email(email) }
|
|
|
|
|
|
|
|
context 'when an email address is normal length' do
|
|
|
|
let(:email) { 'alex@gitlab.com' }
|
|
|
|
|
|
|
|
it { is_expected.to eq('al**@g*****.com') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an email address contains multiple top level domains' do
|
|
|
|
let(:email) { 'alex@gl.co.uk' }
|
|
|
|
|
|
|
|
it { is_expected.to eq('al**@g****.uk') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an email address is very short' do
|
2022-09-22 14:11:12 -04:00
|
|
|
let(:email) { 'a@b.c' }
|
|
|
|
|
|
|
|
it { is_expected.to eq('a@b.c') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an email address is even shorter' do
|
2022-07-01 11:08:30 -04:00
|
|
|
let(:email) { 'a@b' }
|
|
|
|
|
|
|
|
it { is_expected.to eq('a@b') }
|
|
|
|
end
|
|
|
|
end
|
2019-08-14 17:33:39 -04:00
|
|
|
end
|