This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from rbCAS/integration-tests
Integration tests, fixes #1
- Loading branch information
Showing
10 changed files
with
205 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Login' do | ||
include CASino::Engine.routes.url_helpers | ||
|
||
subject { page } | ||
|
||
context 'with two-factor authentication enabled' do | ||
before do | ||
in_browser(:other) do | ||
sign_in | ||
@totp = enable_two_factor_authentication | ||
end | ||
end | ||
|
||
context 'with valid username and password' do | ||
before { sign_in } | ||
|
||
it { should_not have_button('Login') } | ||
it { should have_button('Continue') } | ||
its(:current_path) { should == login_path } | ||
|
||
context 'when filling in the correct otp' do | ||
before do | ||
fill_in :otp, with: @totp.now | ||
click_button 'Continue' | ||
end | ||
|
||
it { should_not have_button('Login') } | ||
it { should_not have_button('Continue') } | ||
its(:current_path) { should == sessions_path } | ||
end | ||
|
||
context 'when filling in an incorrect otp' do | ||
before do | ||
fill_in :otp, with: 'aaaaa' | ||
click_button 'Continue' | ||
end | ||
|
||
it { should have_text('The one-time password you entered is not correct') } | ||
it { should have_button('Continue') } | ||
end | ||
end | ||
end | ||
|
||
context 'with two-factor authentication disabled' do | ||
context 'with valid username and password' do | ||
before { sign_in } | ||
|
||
it { should_not have_button('Login') } | ||
its(:current_path) { should == sessions_path } | ||
end | ||
end | ||
|
||
context 'with invalid username' do | ||
before { sign_in username: 'lalala', password: 'foobar123' } | ||
|
||
it { should have_button('Login') } | ||
it { should have_text('Incorrect username or password') } | ||
end | ||
|
||
context 'with blank password' do | ||
before { sign_in password: '' } | ||
|
||
it { should have_button('Login') } | ||
it { should have_text('Incorrect username or password') } | ||
end | ||
|
||
context 'with german locale' do | ||
before do | ||
page.driver.header 'Accept-Language', 'de' | ||
visit login_path | ||
end | ||
|
||
it { should have_text('Benutzername') } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Logout' do | ||
include CASino::Engine.routes.url_helpers | ||
|
||
subject { page } | ||
|
||
context 'when logged in' do | ||
before do | ||
sign_in | ||
click_link 'Logout' | ||
end | ||
|
||
it { should have_content('logged out') } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Session overview' do | ||
include CASino::Engine.routes.url_helpers | ||
|
||
subject { page } | ||
|
||
context 'when logged in' do | ||
before do | ||
sign_in | ||
visit sessions_path | ||
end | ||
|
||
it { should have_link('Logout', href: logout_path) } | ||
it { should have_text('Your Active Sessions') } | ||
it { should have_text('Active Session') } | ||
|
||
context 'without other sessions' do | ||
it { should_not have_link('End session') } | ||
end | ||
|
||
context 'when other sessions exist' do | ||
before do | ||
in_browser(:other) do | ||
sign_in | ||
end | ||
visit sessions_path | ||
end | ||
it { should have_link('End session') } | ||
end | ||
|
||
context 'with two-factor authentication disabled' do | ||
before do | ||
in_browser(:other) do | ||
sign_in | ||
end | ||
visit sessions_path | ||
end | ||
it { should have_link('Enable', href: new_two_factor_authenticator_path) } | ||
it { should_not have_link('Disable') } | ||
end | ||
|
||
context 'with two-factor authentication enabled' do | ||
before { enable_two_factor_authentication } | ||
it { should_not have_link('Enable', href: new_two_factor_authenticator_path) } | ||
it { should have_link('Disable') } | ||
end | ||
end | ||
|
||
context 'when not logged in' do | ||
before { visit sessions_path } | ||
|
||
it { should have_button('Login') } | ||
its(:current_path) { should == login_path } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module FeatureHelpers | ||
def in_browser(name) | ||
original_browser = Capybara.session_name | ||
Capybara.session_name = name | ||
yield | ||
Capybara.session_name = original_browser | ||
end | ||
|
||
def sign_in(options = {}) | ||
visit login_path | ||
fill_in 'username', with: options[:username] || 'testuser' | ||
fill_in 'password', with: options[:password] || 'foobar123' | ||
click_button 'Login' | ||
end | ||
|
||
def enable_two_factor_authentication | ||
visit new_two_factor_authenticator_path | ||
secret = find('p#secret').text.gsub(/^Secret:\s*/, '') | ||
ROTP::TOTP.new(secret).tap do |totp| | ||
fill_in 'otp', with: "#{totp.now}" | ||
click_button 'Verify and enable' | ||
end | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.include FeatureHelpers, type: :feature | ||
end |
This file was deleted.
Oops, something went wrong.