BigW Consortium Gitlab

password_spec.rb 2.17 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Profile > Password' do
4 5
  context 'Password authentication enabled' do
    let(:user) { create(:user, password_automatically_set: true) }
6

7 8 9 10
    before do
      sign_in(user)
      visit edit_profile_password_path
    end
11

12 13 14
    def fill_passwords(password, confirmation)
      fill_in 'New password',          with: password
      fill_in 'Password confirmation', with: confirmation
15

16 17 18 19 20 21 22
      click_button 'Save password'
    end

    context 'User with password automatically set' do
      describe 'User puts different passwords in the field and in the confirmation' do
        it 'shows an error message' do
          fill_passwords('mypassword', 'mypassword2')
23

24 25 26 27 28 29 30
          page.within('.alert-danger') do
            expect(page).to have_content("Password confirmation doesn't match Password")
          end
        end

        it 'does not contain the current password field after an error' do
          fill_passwords('mypassword', 'mypassword2')
31

32
          expect(page).to have_no_field('user[current_password]')
33 34 35
        end
      end

36 37 38
      describe 'User puts the same passwords in the field and in the confirmation' do
        it 'shows a success message' do
          fill_passwords('mypassword', 'mypassword')
39

40 41 42 43
          page.within('.flash-notice') do
            expect(page).to have_content('Password was successfully updated. Please login with it')
          end
        end
44 45
      end
    end
46
  end
47

48 49 50 51
  context 'Password authentication unavailable' do
    before do
      gitlab_sign_in(user)
    end
52

53 54 55
    context 'Regular user' do
      let(:user) { create(:user) }

56 57 58
      it 'renders 404 when password authentication is disabled for the web interface and Git' do
        stub_application_setting(password_authentication_enabled_for_web: false)
        stub_application_setting(password_authentication_enabled_for_git: false)
59 60 61

        visit edit_profile_password_path

62
        expect(page).to have_gitlab_http_status(404)
63 64 65 66 67 68 69 70 71
      end
    end

    context 'LDAP user' do
      let(:user) { create(:omniauth_user, provider: 'ldapmain') }

      it 'renders 404' do
        visit edit_profile_password_path

72
        expect(page).to have_gitlab_http_status(404)
73 74 75 76
      end
    end
  end
end