2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec . describe 'No Password Alert' do
2021-12-11 22:18:48 +05:30
let_it_be ( :message_password_auth_enabled ) { 'Your account is authenticated with SSO or SAML. To push and pull over HTTP with Git using this account, you must set a password or set up a Personal Access Token to use instead of a password. For more information, see Clone with HTTPS.' }
let_it_be ( :message_password_auth_disabled ) { 'Your account is authenticated with SSO or SAML. To push and pull over HTTP with Git using this account, you must set up a Personal Access Token to use instead of a password. For more information, see Clone with HTTPS.' }
2017-09-10 17:25:29 +05:30
let ( :project ) { create ( :project , :repository , namespace : user . namespace ) }
context 'with internal auth enabled' do
before do
sign_in ( user )
visit project_path ( project )
end
context 'when user has a password' do
let ( :user ) { create ( :user ) }
it 'shows no alert' do
2021-12-11 22:18:48 +05:30
expect ( page ) . not_to have_content message_password_auth_enabled
2017-09-10 17:25:29 +05:30
end
end
context 'when user has password automatically set' do
let ( :user ) { create ( :user , password_automatically_set : true ) }
it 'shows a password alert' do
2021-12-11 22:18:48 +05:30
expect ( page ) . to have_content message_password_auth_enabled
2017-09-10 17:25:29 +05:30
end
end
end
context 'with internal auth disabled' do
let ( :user ) { create ( :omniauth_user , extern_uid : 'my-uid' , provider : 'saml' ) }
before do
2018-03-17 18:26:18 +05:30
stub_application_setting ( password_authentication_enabled_for_git? : false )
2017-09-10 17:25:29 +05:30
stub_omniauth_saml_config ( enabled : true , auto_link_saml_user : true , allow_single_sign_on : [ 'saml' ] , providers : [ mock_saml_config ] )
end
context 'when user has no personal access tokens' do
it 'has a personal access token alert' do
gitlab_sign_in_via ( 'saml' , user , 'my-uid' )
visit project_path ( project )
2021-12-11 22:18:48 +05:30
expect ( page ) . to have_content message_password_auth_disabled
2017-09-10 17:25:29 +05:30
end
end
context 'when user has a personal access token' do
it 'shows no alert' do
create ( :personal_access_token , user : user )
gitlab_sign_in_via ( 'saml' , user , 'my-uid' )
visit project_path ( project )
2021-12-11 22:18:48 +05:30
expect ( page ) . not_to have_content message_password_auth_disabled
2017-09-10 17:25:29 +05:30
end
end
end
context 'when user is ldap user' do
let ( :user ) { create ( :omniauth_user , password_automatically_set : true ) }
before do
sign_in ( user )
visit project_path ( project )
end
it 'shows no alert' do
2021-02-22 17:27:13 +05:30
expect ( page ) . not_to have_content " You won't be able to pull or push repositories via HTTP until you "
2017-09-10 17:25:29 +05:30
end
end
end