Skip to content

Commit

Permalink
add first login system spec. #696
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbaumann1 committed Oct 5, 2021
1 parent 5847c4a commit 4dc1f29
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/views/login/_login.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
.cell
.instructions.registered
With your institutional account
= link_to "With #{COMPETITIONS_CONFIG[:devise][:saml_authenticatable][:idp_entity_name]}", new_saml_user_session_path, class: 'saml-log-in button expanded'
= link_to "With #{COMPETITIONS_CONFIG[:devise][:saml_authenticatable][:idp_entity_name]}", new_saml_user_session_path, class: 'saml-log-in button expanded', id: 'saml_login_link_button'
.cell.or
OR
.cell
Expand Down
9 changes: 9 additions & 0 deletions config/competitions_config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ test:
- '.space'
- '.online'
# - <ANY OTHER EXTENSIONS YOU WOULD LIKE TO BLOCK>
test_saml_user: # - <ADD THE INFORMATION FOR ONE OF YOUR DEV/TEST SAML USERS>
# Below is an example from our testing instance.
# See the wiki for more information.
# https://github.com/NUARIG/competitions/wiki/Installation-and-configuration-of-test-saml-idp
first_name: 'Billy'
last_name: 'Zoom'
email: 'b-zoom@x.edu'
uid: 'bz1'
password: 'secret'
saml_authenticatable: # See https://github.com/apokalipto/devise_saml_authenticatable for more information.
idp_entity_id: ''
idp_entity_name: 'TEST ID'
Expand Down
99 changes: 76 additions & 23 deletions spec/system/login/login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

RSpec.describe 'Login', type: :system do

let(:test_saml_user) { create(:saml_user,
first_name: "#{COMPETITIONS_CONFIG[:devise][:test_saml_user][:first_name]}",
last_name: "#{COMPETITIONS_CONFIG[:devise][:test_saml_user][:last_name]}",
email: "#{COMPETITIONS_CONFIG[:devise][:test_saml_user][:email]}",
uid: "#{COMPETITIONS_CONFIG[:devise][:test_saml_user][:uid]}",
current_sign_in_at: Time.now) }

describe 'Home page', js: true do
scenario 'home page login link navigates to login page' do
visit root_path
Expand All @@ -14,35 +21,81 @@
end
end

describe 'Login page', js: true do
before(:each) do
visit login_index_path
end
context 'saml users' do
describe 'Login page', js: true do
before(:each) do
visit login_index_path
end

scenario 'login page has SAML ID login button' do
expect(page).to have_selector(:link_or_button, "With #{COMPETITIONS_CONFIG[:devise][:saml_authenticatable][:idp_entity_name]}")
end
scenario 'login page has SAML ID login button' do
expect(page).to have_selector(:link_or_button, "With #{COMPETITIONS_CONFIG[:devise][:saml_authenticatable][:idp_entity_name]}")
end

# The following specs runs against values set in the
# config/competitions_config.yml find(:css, "#username")
# and find(:css, "#password") are based on the
# dev/test set up according to our wiki
# (https://github.com/NUARIG/competitions/wiki/Installation-and-configuration-of-test-saml-idp).
# The css IDs might vary depending on whether you are using
# a similar docker SAML setup.
scenario 'login using SAML IDP authentication' do
expect(page).to have_selector(:link_or_button, "With #{COMPETITIONS_CONFIG[:devise][:saml_authenticatable][:idp_entity_name]}")
find("#saml_login_link_button").click

find(:css, "#username").set("#{COMPETITIONS_CONFIG[:devise][:test_saml_user][:uid]}")
find(:css, "#password").set("#{COMPETITIONS_CONFIG[:devise][:test_saml_user][:password]}")
click_button 'Login'

expect(page).to have_content 'Signed in successfully.'
expect(page).to have_content "#{COMPETITIONS_CONFIG[:devise][:test_saml_user][:first_name]} #{COMPETITIONS_CONFIG[:devise][:test_saml_user][:last_name]}"
end

# scenario 'logout using SAML IDP authentication' do

# end

scenario 'login page has Registered Account login form' do
expect(page).to have_selector('#registered_user_uid')
expect(page).to have_selector('#registered_user_password')
# scenario 'creates a new user if found in the SAML IDP' do
# find("#saml_login_link_button").click
# find(:css, "#username").set("#{COMPETITIONS_CONFIG[:devise][:test_saml_user][:uid]}")
# find(:css, "#password").set("#{COMPETITIONS_CONFIG[:devise][:test_saml_user][:password]}")
# click_button 'Login'

# expect(page).to have_content 'Signed in successfully.'
# expect(page).to have_content "#{COMPETITIONS_CONFIG[:devise][:test_saml_user][:first_name]} #{COMPETITIONS_CONFIG[:devise][:test_saml_user][:last_name]}"


# end
end
end

describe 'deep linking on log in', js: true do
let(:grant) { create(:open_grant_with_users_and_form_and_submission_and_reviewer) }
let(:registered_editor) { create(:registered_user) }
let(:editor_permission) { create(:grant_permission, grant: grant, user: registered_editor) }

context 'log in to grant reviews index' do
scenario 'it redirects to the deep link on login' do
editor_permission
visit grant_reviews_path(grant)
find(:css, "#registered_user_uid").set(registered_editor.email)
find(:css, "#registered_user_password").set(registered_editor.password)
click_button 'Log in'
expect(page).to have_current_path grant_reviews_path(grant)
context 'registered users' do
describe 'Login page', js: true do
before(:each) do
visit login_index_path
end

scenario 'login page has Registered Account login form' do
expect(page).to have_selector('#registered_user_uid')
expect(page).to have_selector('#registered_user_password')
end
end

describe 'deep linking on log in', js: true do
let(:grant) { create(:open_grant_with_users_and_form_and_submission_and_reviewer) }
let(:registered_editor) { create(:registered_user) }
let(:editor_permission) { create(:grant_permission, grant: grant, user: registered_editor) }

context 'log in to grant reviews index' do
scenario 'it redirects to the deep link on login' do
editor_permission
visit grant_reviews_path(grant)
find(:css, "#registered_user_uid").set(registered_editor.email)
find(:css, "#registered_user_password").set(registered_editor.password)
click_button 'Log in'
expect(page).to have_current_path grant_reviews_path(grant)
end
end
end
end

end

0 comments on commit 4dc1f29

Please sign in to comment.