Permalink
Browse files

Integration tests complete

  • Loading branch information...
1 parent c81ec62 commit e59184eaaf4a60536ccbaff5a984330f6307f4fd Christian Frichot committed Jan 28, 2012
Showing with 6,524 additions and 1 deletion.
  1. +1 −1 .gitignore
  2. +95 −0 test/integration/gauth_test.rb
  3. +40 −0 test/integration_tests_helper.rb
  4. +6,388 −0 test/rails_app/log/test.log
View
@@ -48,6 +48,6 @@ pkg
#*.rbc
# For Project
-test/rails_app/log
+test/rails_app/log/*
test/rails_app/db/*.sqlite3
Gemfile.lock
@@ -0,0 +1,95 @@
+require 'test_helper'
+require 'integration_tests_helper'
+
+class InvitationTest < ActionDispatch::IntegrationTest
+ def teardown
+ Capybara.reset_sessions!
+ end
+
+ test 'register new user - confirm that we get a display qr page after registering' do
+ visit new_user_registration_path
+ fill_in 'user_email', :with => 'test@test.com'
+ fill_in 'user_password', :with => 'password'
+ fill_in 'user_password_confirmation', :with => 'password'
+ click_button 'Sign up'
+
+ assert_equal user_displayqr_path, current_path
+
+ click_button 'Continue...'
+
+ assert_equal root_path, current_path
+ end
+
+ test 'a new user should be able to sign in without using their token' do
+ create_full_user
+
+ visit new_user_session_path
+ fill_in 'user_email', :with => 'fulluser@test.com'
+ fill_in 'user_password', :with => '123456'
+ click_button 'Sign in'
+
+ assert_equal root_path, current_path
+ end
+
+ test 'a new user should be able to sign in and change their qr code to enabled' do
+ sign_in_as_user
+
+ visit user_displayqr_path
+
+ check 'user_gauth_enabled'
+ click_button 'Continue...'
+
+ assert_equal root_path, current_path
+ end
+
+ test 'a new user should be able to sign in change their qr to enabled and be prompted for their token' do
+ create_and_signin_gauth_user
+
+ assert_equal user_checkga_path, current_path
+ end
+
+ test 'fail token authentication' do
+ create_and_signin_gauth_user
+ fill_in 'user_token', :with => '1'
+ click_button 'Check Token'
+
+ assert_equal new_user_session_path, current_path
+ end
+
+ test 'successfull token authentication' do
+ testuser = create_and_signin_gauth_user
+ fill_in 'user_token', :with => ROTP::TOTP.new(testuser.get_qr).at(Time.now)
+ click_button 'Check Token'
+
+ assert_equal root_path, current_path
+ end
+
+ test 'unsuccessful login - if ga_timeout is short' do
+ old_ga_timeout = User.ga_timeout
+ User.ga_timeout = 1.second
+
+ testuser = create_and_signin_gauth_user
+
+ sleep(5)
+
+ fill_in 'user_token', :with => ROTP::TOTP.new(testuser.get_qr).at(Time.now)
+ click_button 'Check Token'
+
+ User.ga_timeout = old_ga_timeout
+
+ assert_equal new_user_session_path, current_path
+ end
+
+ test 'unsuccessful login - if ga_timedrift is short' do
+ old_ga_timedrift = User.ga_timedrift
+ User.ga_timedrift = 1
+
+ testuser = create_and_signin_gauth_user
+ fill_in 'user_token', :with => ROTP::TOTP.new(testuser.get_qr).at(Time.now.in(60))
+ click_button 'Check Token'
+
+ User.ga_timedrift = old_ga_timedrift
+
+ assert_equal new_user_session_path, current_path
+ end
+end
@@ -0,0 +1,40 @@
+class ActionController::IntegrationTest
+
+ def warden
+ request.env['warden']
+ end
+
+ def create_full_user
+ @user ||= begin
+ user = User.create!(
+ :username => 'usertest',
+ :email => 'fulluser@test.com',
+ :password => '123456',
+ :password_confirmation => '123456'
+ )
+ user
+ end
+ end
+
+ def create_and_signin_gauth_user
+ testuser = create_full_user
+ sign_in_as_user(testuser)
+ visit user_displayqr_path
+ check 'user_gauth_enabled'
+ click_button 'Continue...'
+
+ Capybara.reset_sessions!
+
+ sign_in_as_user(testuser)
+ testuser
+ end
+
+ def sign_in_as_user(user = nil)
+ user ||= create_full_user
+ resource_name = user.class.name.underscore
+ visit send("new_#{resource_name}_session_path")
+ fill_in "#{resource_name}_email", :with => user.email
+ fill_in "#{resource_name}_password", :with => user.password
+ click_button 'Sign in'
+ end
+end
Oops, something went wrong.

0 comments on commit e59184e

Please sign in to comment.