Skip to content

Commit

Permalink
integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SidharthBansal committed Jul 2, 2018
2 parents 6402d62 + d870958 commit 10fed6b
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 3 deletions.
57 changes: 55 additions & 2 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,60 @@
}
})



#facebook Provider
OmniAuth.config.mock_auth[:facebook1] = OmniAuth::AuthHash.new({
'provider' => 'facebook',
'uid' => '1357905002',
'info' => {
'name' => 'sidharth bansal',
'email' => 'bansal.sidharth309@gmail.com'
}
})

#Twitter Provider
OmniAuth.config.mock_auth[:twitter1] = OmniAuth::AuthHash.new({
'provider' => 'twitter',
'uid' => '135798079602',
'info' => {
'name' => 'sidharth bansal',
'email' => 'bansal.sidharth309@gmail.com'
}
})

OmniAuth.config.mock_auth[:facebook2] = OmniAuth::AuthHash.new({
'provider' => 'facebook',
'uid' => '1359988009602',
'info' => {
'name' => 'jeffrey',
'email' => 'jeff@pxlshp.com'
}
})

OmniAuth.config.mock_auth[:facebook3] = OmniAuth::AuthHash.new({
'provider' => 'facebook',
'uid' => '13579992302',
'info' => {
'name' => 'emila buffet',
'email' => 'emila.buffet309@gmail.com'
}
})

OmniAuth.config.mock_auth[:twitter2] = OmniAuth::AuthHash.new({
'provider' => 'twitter',
'uid' => '137898009602',
'info' => {
'name' => 'jeffrey',
'email' => 'jeff@pxlshp.com'
}
})

OmniAuth.config.mock_auth[:twitter3] = OmniAuth::AuthHash.new({
'provider' => 'twitter',
'uid' => '135689602',
'info' => {
'name' => 'emila buffet',
'email' => 'emila.buffet309@gmail.com'
}
})

end
2 changes: 2 additions & 0 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
provider :google_oauth2, ENV["OAUTH_GOOGLE_APP_KEY"],ENV["OAUTH_GOOGLE_APP_SECRET"] , skip_jwt: true
#For provider github, app_id is stored in OAUTH_GITHUB_APP_KEY and app_secret in OAUTH_GITHUB_APP_SECRET
provider :github, ENV["OAUTH_GITHUB_APP_KEY"], ENV["OAUTH_GITHUB_APP_SECRET"], { scope: 'user:email' }
#For Facebook provider
provider :facebook, ENV["OAUTH_FACEBOOK_APP_KEY"], ENV["OAUTH_FACEBOOK_APP_SECRET"]
#For provider github, app_id is stored in OAUTH_TWITTER_APP_KEY and app_secret in OAUTH_TWITTER_APP_SECRET
provider :twitter, ENV["OAUTH_TWITTER_APP_KEY"], ENV["OAUTH_TWITTER_APP_SECRET"]
end
2 changes: 2 additions & 0 deletions containers/docker-compose-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ services:
- OAUTH_GITHUB_APP_SECRET=${OAUTH_GITHUB_APP_SECRET}
- OAUTH_TWITTER_APP_KEY=${OAUTH_TWITTER_APP_KEY}
- OAUTH_TWITTER_APP_SECRET=${OAUTH_TWITTER_APP_SECRET}
- OAUTH_FACEBOOK_APP_KEY=${OAUTH_FACEBOOK_APP_KEY}
- OAUTH_FACEBOOK_APP_SECRET=${OAUTH_FACEBOOK_APP_SECRET}
volumes:
- ..:/app
- /etc/passwd:/etc/passwd:ro
Expand Down
2 changes: 2 additions & 0 deletions containers/docker-compose-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ services:
- OAUTH_GITHUB_APP_SECRET=${OAUTH_GITHUB_APP_SECRET}
- OAUTH_TWITTER_APP_KEY=${OAUTH_TWITTER_APP_KEY}
- OAUTH_TWITTER_APP_SECRET=${OAUTH_TWITTER_APP_SECRET}
- OAUTH_FACEBOOK_APP_KEY=${OAUTH_FACEBOOK_APP_KEY}
- OAUTH_FACEBOOK_APP_SECRET=${OAUTH_FACEBOOK_APP_SECRET}
volumes:
- ..:/app
ports:
Expand Down
2 changes: 2 additions & 0 deletions containers/docker-compose-unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ services:
- OAUTH_GITHUB_APP_SECRET=${OAUTH_GITHUB_APP_SECRET}
- OAUTH_TWITTER_APP_KEY=${OAUTH_TWITTER_APP_KEY}
- OAUTH_TWITTER_APP_SECRET=${OAUTH_TWITTER_APP_SECRET}
- OAUTH_FACEBOOK_APP_KEY=${OAUTH_FACEBOOK_APP_KEY}
- OAUTH_FACEBOOK_APP_SECRET=${OAUTH_FACEBOOK_APP_SECRET}
volumes:
- ..:/app
ports:
Expand Down
113 changes: 113 additions & 0 deletions test/functional/user_sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,117 @@ class UserSessionsControllerTest < ActionController::TestCase
post :destroy
assert_equal "Successfully logged out.", flash[:notice]
end


test 'sign up and login via provider basic flow for twitter' do
assert_not_nil OmniAuth.config.mock_auth[:twitter1]
#Omniauth hash is present
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter1]
assert_not_nil request.env['omniauth.auth']
#Sign Up for a new user
post :create
assert_equal "You have successfully signed in. Please change your password via a link sent to you via a mail", flash[:notice]
#Log Out
post :destroy
assert_equal "Successfully logged out.", flash[:notice]
#auth hash is present so login via a provider
post :create
assert_equal "Signed in!", flash[:notice]
end

test 'sign up and login via provider alternative flow for twitter' do
assert_not_nil OmniAuth.config.mock_auth[:twitter2]
#Omniauth hash is present
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter2]
assert_not_nil request.env['omniauth.auth']
#Sign Up for an existing user as email exists in the db
post :create
assert_equal "Successfully linked to your account!", flash[:notice]
#Log Out
post :destroy
assert_equal "Successfully logged out.", flash[:notice]
#auth hash is present so login via a provider
post :create
assert_equal "Signed in!", flash[:notice]
end

test 'login user with an email and then contwitter provider' do
post :create,
params: {
user_session: {
username: users(:jeff).email,
password: 'secretive'
}
}
assert_redirected_to '/dashboard'
assert_not_nil OmniAuth.config.mock_auth[:twitter2]
#Omniauth hash is present
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter2]
assert_not_nil request.env['omniauth.auth']
#Link a twitter account to an existing user
post :create
assert_equal "Successfully linked to your account!", flash[:notice]
#Link same twitter account to an existing user again
post :create
assert_equal "Already linked to your account!", flash[:notice]
#Log Out
post :destroy
assert_equal "Successfully logged out.", flash[:notice]
end

test 'sign up and login via provider basic flow for facebook' do
assert_not_nil OmniAuth.config.mock_auth[:facebook1]
#Omniauth hash is present
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:facebook1]
assert_not_nil request.env['omniauth.auth']
#Sign Up for a new user
post :create
assert_equal "You have successfully signed in. Please change your password via a link sent to you via a mail", flash[:notice]
#Log Out
post :destroy
assert_equal "Successfully logged out.", flash[:notice]
#auth hash is present so login via a provider
post :create
assert_equal "Signed in!", flash[:notice]
end

test 'sign up and login via provider alternative flow for facebook' do
assert_not_nil OmniAuth.config.mock_auth[:facebook2]
#Omniauth hash is present
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:facebook2]
assert_not_nil request.env['omniauth.auth']
#Sign Up for an existing user as email exists in the db
post :create
assert_equal "Successfully linked to your account!", flash[:notice]
#Log Out
post :destroy
assert_equal "Successfully logged out.", flash[:notice]
#auth hash is present so login via a provider
post :create
assert_equal "Signed in!", flash[:notice]
end

test 'login user with an email and then connect facebook provider' do
post :create,
params: {
user_session: {
username: users(:jeff).email,
password: 'secretive'
}
}
assert_redirected_to '/dashboard'
assert_not_nil OmniAuth.config.mock_auth[:facebook2]
#Omniauth hash is present
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:facebook2]
assert_not_nil request.env['omniauth.auth']
#Link a facebook account to an existing user
post :create
assert_equal "Successfully linked to your account!", flash[:notice]
#Link same facebook account to an existing user again
post :create
assert_equal "Already linked to your account!", flash[:notice]
#Log Out
post :destroy
assert_equal "Successfully logged out.", flash[:notice]
end
end
17 changes: 16 additions & 1 deletion test/integration/login_flow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,22 @@ class LoginFlowTest < ActionDispatch::IntegrationTest
assert_not_nil OmniAuth.config.mock_auth[:twitter2]
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter2]
assert_not_nil request.env['omniauth.auth']
end
end

test 'facebook login routing' do
assert_routing '/auth/facebook/callback', {controller: 'user_sessions', action: 'create',provider: 'facebook'}
end

test 'facebook login post' do
assert_routing({path: '/auth/facebook/callback', method: 'post'},{controller: 'user_sessions', action: 'create' ,provider: 'facebook'})
end

test 'should get oauth hash from /auth/facebook' do
get '/auth/facebook'
assert_redirected_to '/auth/facebook/callback'
assert_not_nil OmniAuth.config.mock_auth[:facebook2]
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:facebook2]
assert_not_nil request.env['omniauth.auth']
end

end

0 comments on commit 10fed6b

Please sign in to comment.