diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-07 00:09:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-07 00:09:01 +0300 |
commit | ca3ff7f842fb1e4bf124356a6faccd3e65b7aba3 (patch) | |
tree | befb345c84e172b0592378ca17298f7a0c955a06 /spec/support/helpers | |
parent | 1287690a3678ad0ec21c9b2f3b21ae18257d5e22 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/helpers')
-rw-r--r-- | spec/support/helpers/ldap_helpers.rb | 26 | ||||
-rw-r--r-- | spec/support/helpers/login_helpers.rb | 10 |
2 files changed, 36 insertions, 0 deletions
diff --git a/spec/support/helpers/ldap_helpers.rb b/spec/support/helpers/ldap_helpers.rb index 2f5f8be518c..48b593fb3d1 100644 --- a/spec/support/helpers/ldap_helpers.rb +++ b/spec/support/helpers/ldap_helpers.rb @@ -69,6 +69,32 @@ module LdapHelpers allow_any_instance_of(Gitlab::Auth::Ldap::Adapter) .to receive(:ldap_search).and_raise(Gitlab::Auth::Ldap::LdapConnectionError) end + + def stub_ldap_access(user, provider, provider_label) + ldap_server_config = + { + 'label' => provider_label, + 'provider_name' => provider, + 'attributes' => {}, + 'encryption' => 'plain', + 'uid' => 'uid', + 'base' => 'dc=example,dc=com' + } + uid = 'my-uid' + allow(::Gitlab::Auth::Ldap::Config).to receive_messages(enabled: true, servers: [ldap_server_config]) + allow(Gitlab::Auth::OAuth::Provider).to receive_messages(providers: [provider.to_sym]) + + Ldap::OmniauthCallbacksController.define_providers! + Rails.application.reload_routes! + + mock_auth_hash(provider, uid, user.email) + allow(Gitlab::Auth::Ldap::Access).to receive(:allowed?).with(user).and_return(true) + + allow_next_instance_of(ActionDispatch::Routing::RoutesProxy) do |instance| + allow(instance).to receive(:"user_#{provider}_omniauth_callback_path") + .and_return("/users/auth/#{provider}/callback") + end + end end LdapHelpers.include_mod_with('LdapHelpers') diff --git a/spec/support/helpers/login_helpers.rb b/spec/support/helpers/login_helpers.rb index 87a1f5459ec..44237b821c3 100644 --- a/spec/support/helpers/login_helpers.rb +++ b/spec/support/helpers/login_helpers.rb @@ -119,6 +119,16 @@ module LoginHelpers click_button "oauth-login-#{provider}" end + def sign_in_using_ldap!(user, ldap_tab, ldap_name) + visit new_user_session_path + click_link ldap_tab + fill_in 'username', with: user.username + fill_in 'password', with: user.password + within("##{ldap_name}") do + click_button 'Sign in' + end + end + def register_via(provider, uid, email, additional_info: {}) mock_auth_hash(provider, uid, email, additional_info: additional_info) visit new_user_registration_path |