internal_spec.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. require 'rails_helper'
  2. require 'lib/auth/backend_examples'
  3. RSpec.describe Auth::Internal do
  4. let(:password) { 'zammad' }
  5. let(:user) { create(:user, password: password) }
  6. let(:instance) { described_class.new({ adapter: described_class.name }) }
  7. context '#valid?' do
  8. it_behaves_like 'Auth backend'
  9. it 'authenticates via password' do
  10. result = instance.valid?(user, password)
  11. expect(result).to be true
  12. end
  13. it "doesn't authenticate via plain password" do
  14. result = instance.valid?(user, user.password)
  15. expect(result).to be_falsy
  16. end
  17. it 'converts legacy sha2 passwords' do
  18. sha2 = PasswordHash.sha2(password)
  19. user = create(:user, password: sha2)
  20. expect(PasswordHash.crypted?(user.password)).to be true
  21. expect(PasswordHash.legacy?(user.password, password)).to be true
  22. result = instance.valid?(user, password)
  23. expect(result).to be true
  24. expect(PasswordHash.legacy?(user.password, password)).to be false
  25. expect(PasswordHash.crypted?(user.password)).to be true
  26. end
  27. end
  28. end