Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ doc
# jeweler generated
pkg

# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
#
# * Create a file at ~/.gitignore
# * Include files you want ignored
Expand Down Expand Up @@ -50,6 +50,7 @@ pkg
# For Project
test/rails_app/log/
test/rails_app/db/*.sqlite3
test/rails_app/tmp/
Gemfile.lock
.ruby-version
.ruby-gemset
12 changes: 8 additions & 4 deletions app/controllers/devise/checkga_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def update
warden.manager._run_callbacks(:after_set_user, resource, warden, {:event => :authentication})
respond_with resource, :location => after_sign_in_path_for(resource)

if not resource.class.ga_remembertime.nil?
if not resource.class.ga_remembertime.nil?
cookies.signed[:gauth] = {
:value => resource.email << "," << Time.now.to_i.to_s,
:secure => !(Rails.env.test? || Rails.env.development?),
Expand All @@ -33,18 +33,22 @@ def update
end
else
set_flash_message(:error, :error)
redirect_to :root
redirect_to redirect_on_error_url
end

else
set_flash_message(:error, :error)
redirect_to :root
redirect_to redirect_on_error_url
end
end

def redirect_on_error_url
:root
end

private

def devise_resource
self.resource = resource_class.new
end
end
end
32 changes: 31 additions & 1 deletion test/integration/gauth_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ def teardown

end

test 'if resource is nil redirects back to custom url' do
User.stubs(:find_by_gauth_tmp).returns(nil)
Devise::CheckgaController.any_instance.stubs(:redirect_on_error_url).returns('/foo')
testuser = create_full_user

visit new_user_session_path
fill_in 'user_email', :with => '[email protected]'
fill_in 'user_password', :with => '123456'
click_button 'Log in'

fill_in 'user_gauth_token', :with => ROTP::TOTP.new(testuser.get_qr).at(Time.now)
click_button 'Check Token'
assert_equal foo_path, current_path
Capybara.reset_sessions!
end

test 'fail token authentication' do
create_and_signin_gauth_user
fill_in 'user_gauth_token', :with => '1'
Expand All @@ -92,6 +108,20 @@ def teardown
Capybara.reset_sessions!
end

test 'fail token authentication redirects back to custom url' do
Devise::CheckgaController.any_instance.stubs(:redirect_on_error_url).returns('/foo')
create_full_user
visit new_user_session_path
fill_in 'user_email', :with => '[email protected]'
fill_in 'user_password', :with => '123456'
click_button 'Log in'

fill_in 'user_gauth_token', :with => "wrong token"
click_button 'Check Token'
assert_equal foo_path, current_path
Capybara.reset_sessions!
end

test 'successfull token authentication' do
testuser = User.find_by_email("[email protected]")
visit new_user_session_path
Expand Down Expand Up @@ -179,4 +209,4 @@ def teardown

Timecop.return
end
end
end
2 changes: 1 addition & 1 deletion test/integration_tests_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ActionController::IntegrationTest
def warden
request.env['warden']
end

def create_full_user
@@user ||= begin
user = User.create!(
Expand Down
7 changes: 7 additions & 0 deletions test/rails_app/app/controllers/foo_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class FooController < ApplicationController
skip_before_filter :authenticate_user!

def index
render :nothing => true
end
end
1 change: 1 addition & 0 deletions test/rails_app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
devise_for :users

resources :posts
get 'foo' => 'foo#index'
root :to => 'posts#index'
end
3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
require 'capybara/rails'
require 'timecop'

require "mocha/integration/test_unit"
Mocha::Integration::TestUnit.activate

I18n.load_path << File.expand_path("../support/locale/en.yml", __FILE__) if DEVISE_ORM == :mongoid

ActiveSupport::Deprecation.silenced = true
Expand Down