#3928 administrator tests handle password constants
This commit is contained in:
parent
8d3e3baabc
commit
44efa5a1b1
1 changed files with 21 additions and 17 deletions
|
@ -72,29 +72,33 @@ describe Administrateur, type: :model do
|
|||
it { expect(administrateur.feature_enabled?(:test_a)).to be_truthy }
|
||||
end
|
||||
|
||||
describe "#password_complexity" do
|
||||
let(:administrateur) { build(:administrateur, password: password) }
|
||||
describe '#password_complexity' do
|
||||
let(:email) { 'mail@beta.gouv.fr' }
|
||||
let(:passwords) { ['pass', '12pass23', 'démarches ', 'démarches-simple', 'démarches-simplifiées-pwd'] }
|
||||
let(:administrateur) { build(:administrateur, email: email, password: password) }
|
||||
let(:min_complexity) { PASSWORD_COMPLEXITY_FOR_ADMIN }
|
||||
|
||||
subject do
|
||||
administrateur.save
|
||||
administrateur.errors[:password]
|
||||
administrateur.errors.full_messages
|
||||
end
|
||||
|
||||
context "with a strong password" do
|
||||
let(:password) { "la démat c'est simple" }
|
||||
context 'when password is too short' do
|
||||
let(:password) { 's' * (PASSWORD_MIN_LENGTH - 1) }
|
||||
|
||||
it { expect(subject).to eq(["Le mot de passe est trop court"]) }
|
||||
end
|
||||
|
||||
context 'when password is too simple' do
|
||||
let(:password) { passwords[min_complexity - 1] }
|
||||
|
||||
it { expect(subject).to eq(["Le mot de passe n'est pas assez complexe"]) }
|
||||
end
|
||||
|
||||
context 'when password is acceptable' do
|
||||
let(:password) { passwords[min_complexity] }
|
||||
|
||||
it { expect(subject).to eq([]) }
|
||||
end
|
||||
|
||||
context "with a weak password" do
|
||||
let(:password) { "12345678" }
|
||||
it { expect(subject).to include "n'est pas assez complexe" }
|
||||
it { expect(subject).not_to include "est trop court" }
|
||||
end
|
||||
|
||||
context "with a short password" do
|
||||
let(:password) { "1" }
|
||||
it { expect(subject).to include "est trop court" }
|
||||
it { expect(subject).not_to include "n'est pas assez complexe" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue