spec/omniauth/strategies/auth0_spec.rb in omniauth-auth0-2.4.2 vs spec/omniauth/strategies/auth0_spec.rb in omniauth-auth0-2.5.0
- old
+ new
@@ -24,11 +24,16 @@
domain_url
)
end
describe 'client_options' do
- let(:subject) { auth0.client }
+ let(:subject) { OmniAuth::Strategies::Auth0.new(
+ application,
+ client_id,
+ client_secret,
+ domain_url
+ ).client }
context 'domain with https' do
let(:domain_url) { 'https://samples.auth0.com' }
it_behaves_like 'site has valid domain url', 'https://samples.auth0.com'
end
@@ -159,16 +164,21 @@
let(:id_token) do
payload = {}
payload['sub'] = user_id
payload['iss'] = "#{domain_url}/"
payload['aud'] = client_id
+ payload['name'] = name
+ payload['nickname'] = nickname
+ payload['picture'] = picture
+ payload['email'] = email
+ payload['email_verified'] = email_verified
+
JWT.encode payload, client_secret, 'HS256'
end
let(:oauth_response) do
{
- id_token: id_token,
access_token: access_token,
expires_in: expires_in,
token_type: token_type
}
end
@@ -180,21 +190,11 @@
expires_in: expires_in,
token_type: token_type
}
end
- let(:basic_user_info) { { sub: user_id } }
- let(:oidc_user_info) do
- {
- sub: user_id,
- name: name,
- nickname: nickname,
- email: email,
- picture: picture,
- email_verified: email_verified
- }
- end
+ let(:basic_user_info) { { "sub" => user_id, "name" => name } }
def stub_auth(body)
stub_request(:post, 'https://samples.auth0.com/oauth/token')
.with(headers: { 'Auth0-Client' => telemetry_value })
.to_return(
@@ -218,11 +218,13 @@
before(:each) do
WebMock.reset!
end
- let(:subject) { MultiJson.decode(last_response.body) }
+ let(:subject) do
+ MultiJson.decode(last_response.body)
+ end
context 'basic oauth' do
before do
stub_auth(oauth_response)
stub_userinfo(basic_user_info)
@@ -237,15 +239,19 @@
expect(subject['credentials']['token']).to eq(access_token)
expect(subject['credentials']['expires']).to be true
expect(subject['credentials']['expires_at']).to_not be_nil
end
- it 'has basic values' do
+ it 'has basic values' do
expect(subject['provider']).to eq('auth0')
expect(subject['uid']).to eq(user_id)
- expect(subject['info']['name']).to eq(user_id)
+ expect(subject['info']['name']).to eq(name)
end
+
+ it 'should use the user info endpoint' do
+ expect(subject['extra']['raw_info']).to eq(basic_user_info)
+ end
end
context 'basic oauth w/refresh token' do
before do
stub_auth(oauth_response.merge(refresh_token: refresh_token))
@@ -266,10 +272,9 @@
end
context 'oidc' do
before do
stub_auth(oidc_response)
- stub_userinfo(oidc_user_info)
trigger_callback
end
it 'to succeed' do
expect(last_response.status).to eq(200)