special_character_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'lib/password_policy/error_examples'
  4. RSpec.describe PasswordPolicy::SpecialCharacter do
  5. it_behaves_like 'declaring an error'
  6. describe '.applicable?' do
  7. it "returns false when Setting 'password_need_special_character' is disabled" do
  8. Setting.set('password_need_special_character', 0)
  9. expect(described_class).not_to be_applicable
  10. end
  11. it "returns true when Setting 'password_need_digit' is enabled" do
  12. Setting.set('password_need_special_character', 1)
  13. expect(described_class).to be_applicable
  14. end
  15. end
  16. describe '#valid?' do
  17. it 'valid when special character is included' do
  18. instance = described_class.new('gütenTag')
  19. expect(instance).to be_valid
  20. end
  21. it 'not valid when only letters' do
  22. instance = described_class.new('notsogoodpw')
  23. expect(instance).not_to be_valid
  24. end
  25. it 'not valid when includes digit' do
  26. instance = described_class.new('notsogoodpw123')
  27. expect(instance).not_to be_valid
  28. end
  29. end
  30. end