spec/routes/auth_spec.rb in osso-0.0.5.pre.eta vs spec/routes/auth_spec.rb in osso-0.0.5.pre.gamma
- old
+ new
@@ -1,13 +1,10 @@
# frozen_string_literal: true
require 'spec_helper'
describe Osso::Auth do
- before do
- described_class.set(:views, spec_views)
- end
describe 'get /auth/saml/:uuid' do
describe 'for an Okta SAML provider' do
let(:enterprise) { create(:enterprise_with_okta) }
let(:okta_provider) { enterprise.identity_providers.first }
it 'uses omniauth saml' do
@@ -44,10 +41,11 @@
post(
"/auth/saml/#{okta_provider.id}/callback",
nil,
{
'omniauth.auth' => OmniAuth.config.mock_auth[:saml],
+ 'identity_provider' => okta_provider,
},
)
end.to change { Osso::Models::User.count }.by(1)
end
@@ -58,10 +56,11 @@
post(
"/auth/saml/#{okta_provider.id}/callback",
nil,
{
'omniauth.auth' => OmniAuth.config.mock_auth[:saml],
+ 'identity_provider' => okta_provider,
},
)
end.to change { Osso::Models::AuthorizationCode.count }.by(1)
end
@@ -72,10 +71,11 @@
post(
"/auth/saml/#{okta_provider.id}/callback",
nil,
{
'omniauth.auth' => OmniAuth.config.mock_auth[:saml],
+ 'identity_provider' => okta_provider,
},
)
expect(last_response).to be_redirect
follow_redirect!
expect(last_request.url).to match(/.*state=IDP_INITIATED$/)
@@ -97,23 +97,25 @@
post(
"/auth/saml/#{okta_provider.id}/callback",
nil,
{
'omniauth.auth' => OmniAuth.config.mock_auth[:saml],
+ 'identity_provider' => okta_provider,
},
)
end.to_not(change { Osso::Models::User.count })
end
it 'marks the provider as ACTIVE' do
post(
"/auth/saml/#{okta_provider.id}/callback",
nil,
{
'omniauth.auth' => OmniAuth.config.mock_auth[:saml],
+ 'identity_provider' => okta_provider,
},
)
- expect(okta_provider.reload.status).to eq('active')
+ expect(okta_provider.reload.status).to eq('ACTIVE')
end
end
end
describe 'for an (Azure) ADFS SAML provider' do
@@ -128,10 +130,11 @@
post(
"/auth/saml/#{azure_provider.id}/callback",
nil,
{
'omniauth.auth' => OmniAuth.config.mock_auth[:saml],
+ 'identity_provider' => azure_provider,
},
)
end.to change { Osso::Models::User.count }.by(1)
end
@@ -141,14 +144,15 @@
post(
"/auth/saml/#{azure_provider.id}/callback",
nil,
{
'omniauth.auth' => OmniAuth.config.mock_auth[:saml],
+ 'identity_provider' => azure_provider,
},
)
- expect(azure_provider.reload.status).to eq('active')
+ expect(azure_provider.reload.status).to eq('ACTIVE')
end
end
describe 'on subsequent authentications' do
let!(:enterprise) { create(:enterprise_with_azure) }
@@ -164,49 +168,14 @@
post(
"/auth/saml/#{azure_provider.id}/callback",
nil,
{
'omniauth.auth' => OmniAuth.config.mock_auth[:saml],
+ 'identity_provider' => azure_provider,
},
)
end.to_not(change { Osso::Models::User.count })
end
- end
- end
- end
-
- context 'with an invalid SAML response' do
- describe 'post /auth/saml/:uuid/callback' do
- let!(:enterprise) { create(:enterprise_with_azure) }
- let!(:azure_provider) { enterprise.provider }
-
- it 'raises an error when email is missing' do
- mock_saml_omniauth(email: nil, id: SecureRandom.uuid)
-
-
- response = post(
- "/auth/saml/#{azure_provider.id}/callback",
- nil,
- {
- 'omniauth.auth' => OmniAuth.config.mock_auth[:saml],
- },
- )
-
- expect(response.body).to eq('Osso::Error::MissingSamlEmailAttributeError')
- end
-
- it 'raises an error when id is missing' do
- mock_saml_omniauth(email: Faker::Internet.email, id: nil)
-
- response = post(
- "/auth/saml/#{azure_provider.id}/callback",
- nil,
- {
- 'omniauth.auth' => OmniAuth.config.mock_auth[:saml],
- },
- )
-
- expect(response.body).to eq('Osso::Error::MissingSamlIdAttributeError')
end
end
end
end