Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Test login with two-factor authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
pencil committed Apr 21, 2013
1 parent 8b84a11 commit 6c55fb5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
48 changes: 44 additions & 4 deletions spec/features/login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,51 @@

subject { page }

context 'with valid username and password' do
before { sign_in }
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

it { should_not have_button('Login') }
its(:current_path) { should == sessions_path }
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
Expand Down
7 changes: 4 additions & 3 deletions spec/support/features_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ def sign_in(options = {})
def enable_two_factor_authentication
visit new_two_factor_authenticator_path
secret = find('p#secret').text.gsub(/^Secret:\s*/, '')
totp = ROTP::TOTP.new(secret)
fill_in 'otp', with: "#{totp.now}"
click_button 'Verify and enable'
ROTP::TOTP.new(secret).tap do |totp|
fill_in 'otp', with: "#{totp.now}"
click_button 'Verify and enable'
end
end
end

Expand Down

0 comments on commit 6c55fb5

Please sign in to comment.