mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-17 13:44:09 +00:00
Add tests for openid signup with every provider
The spec for omniauth doesn't test signup for every provider, and it doesn't test if it has tests for all available providers Also, we no longer use secrets * Add model test to check if the omniauth providers have changed * Test signup using every provider * Replace secretswith environment variables
This commit is contained in:
parent
9341edd9cb
commit
95b88be061
3 changed files with 107 additions and 4 deletions
|
|
@ -118,9 +118,35 @@ feature Openid do
|
|||
end
|
||||
end
|
||||
|
||||
shared_examples 'sign up with openid' do |provider|
|
||||
scenario "has option to sign in with #{provider}" do
|
||||
visit '/accounts/sign_up'
|
||||
expect(page.has_content?('or sign in using')).to eq true
|
||||
expect(page.has_link?("omniauth-#{provider}")).to eq true
|
||||
end
|
||||
|
||||
scenario "sign up with #{provider}" do
|
||||
expected_count_openid = Openid.count + 1
|
||||
expected_count_user = User.count + 1
|
||||
visit '/accounts/sign_up'
|
||||
|
||||
mock_auth_accounts
|
||||
within('#openidlinks') do
|
||||
click_link "omniauth-#{provider}"
|
||||
end
|
||||
expect(flash).to eq("user-#{provider}@example.com signed in successfully with #{provider}")
|
||||
expect(Openid.count).to eq(expected_count_openid)
|
||||
expect(User.count).to eq(expected_count_user)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'omniauth' do
|
||||
if User.omniauth_providers.present?
|
||||
it_behaves_like 'sign in with openid'
|
||||
|
||||
User.omniauth_providers.each do |provider|
|
||||
it_behaves_like 'sign up with openid', provider
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -426,4 +426,10 @@ describe User do
|
|||
expect(user.events_registrations).to eq [@events_registration1, @events_registration2]
|
||||
end
|
||||
end
|
||||
|
||||
describe '.omniauth_providers' do
|
||||
it 'contains providers' do
|
||||
expect(User.omniauth_providers).to eq [:suse, :google, :facebook, :github]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,10 +2,14 @@ module OmniauthMacros
|
|||
# The mock_auth configuration allows you to set per-provider (or default)
|
||||
# authentication hashes to return during integration testing.
|
||||
|
||||
Rails.application.secrets.google_key = 'test key google'
|
||||
Rails.application.secrets.google_secret = 'test secret google'
|
||||
Rails.application.secrets.facebook_key = 'test key facebook'
|
||||
Rails.application.secrets.facebook_secret = 'test secret facebook'
|
||||
ENV['OSEM_GOOGLE_KEY'] = 'test key google'
|
||||
ENV['OSEM_GOOGLE_SECRET'] = 'test secret google'
|
||||
ENV['OSEM_FACEBOOK_KEY'] = 'test key facebook'
|
||||
ENV['OSEM_FACEBOOK_SECRET'] = 'test secret facebook'
|
||||
ENV['OSEM_SUSE_KEY'] = 'test key suse'
|
||||
ENV['OSEM_SUSE_SECRET'] = 'test secret suse'
|
||||
ENV['OSEM_GITHUB_KEY'] = 'test key github'
|
||||
ENV['OSEM_GITHUB_SECRET'] = 'test secret github'
|
||||
|
||||
def mock_auth_new_user
|
||||
OmniAuth.config.mock_auth[:google] =
|
||||
|
|
@ -74,4 +78,71 @@ module OmniauthMacros
|
|||
}
|
||||
)
|
||||
end
|
||||
|
||||
# We use these mock accounts to ensure that the ones which are available in
|
||||
# development are valid, to test omniauth actions and verify that a mock
|
||||
# account is available for every supported omniauth provider.
|
||||
# These must be identical to the ones in /config/environments/development.rb
|
||||
# Remember to keep them in sync with development.rb
|
||||
def mock_auth_accounts
|
||||
OmniAuth.config.mock_auth[:facebook] =
|
||||
OmniAuth::AuthHash.new(
|
||||
provider: 'facebook',
|
||||
uid: 'facebook-test-uid-1',
|
||||
info: {
|
||||
name: 'facebook user',
|
||||
email: 'user-facebook@example.com',
|
||||
username: 'user_facebook'
|
||||
},
|
||||
credentials: {
|
||||
token: 'fb_mock_token',
|
||||
secret: 'fb_mock_secret'
|
||||
}
|
||||
)
|
||||
|
||||
OmniAuth.config.mock_auth[:google] =
|
||||
OmniAuth::AuthHash.new(
|
||||
provider: 'google',
|
||||
uid: 'google-test-uid-1',
|
||||
info: {
|
||||
name: 'google user',
|
||||
email: 'user-google@example.com',
|
||||
username: 'user_google'
|
||||
},
|
||||
credentials: {
|
||||
token: 'google_mock_token',
|
||||
secret: 'google_mock_secret'
|
||||
}
|
||||
)
|
||||
|
||||
OmniAuth.config.mock_auth[:suse] =
|
||||
OmniAuth::AuthHash.new(
|
||||
provider: 'suse',
|
||||
uid: 'suse-test-uid-1',
|
||||
info: {
|
||||
name: 'suse user',
|
||||
email: 'user-suse@example.com',
|
||||
username: 'user_suse'
|
||||
},
|
||||
credentials: {
|
||||
token: 'suse_mock_token',
|
||||
secret: 'suse_mock_secret'
|
||||
}
|
||||
)
|
||||
|
||||
OmniAuth.config.mock_auth[:github] =
|
||||
OmniAuth::AuthHash.new(
|
||||
provider: 'github',
|
||||
uid: 'github-test-uid-1',
|
||||
info: {
|
||||
name: 'github user',
|
||||
email: 'user-github@example.com',
|
||||
username: 'user_github'
|
||||
},
|
||||
credentials: {
|
||||
token: 'github_mock_token',
|
||||
secret: 'github_mock_secret'
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue