Skip to content
Merged
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
4 changes: 1 addition & 3 deletions app/services/service_provider_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class ServiceProviderUpdater
SP_PROTECTED_ATTRIBUTES = %i[
created_at
id
native
updated_at
].to_set.freeze

Expand Down Expand Up @@ -34,13 +33,12 @@ def update_cache(service_provider)
if service_provider['active'] == true
create_or_update_service_provider(issuer, service_provider)
else
ServiceProvider.where(issuer: issuer, native: false).destroy_all
ServiceProvider.where(issuer: issuer).destroy_all
end
end

def create_or_update_service_provider(issuer, service_provider)
sp = ServiceProvider.find_by(issuer: issuer)
return if sp&.native?
sync_model(sp, cleaned_service_provider(service_provider))
end

Expand Down
27 changes: 5 additions & 22 deletions spec/services/service_provider_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
block_encryption: 'aes256-cbc',
certs: [saml_test_sp_cert],
active: true,
native: false,
approved: true,
help_text: {
sign_in: { en: '<b>A new different sign-in help text</b>' },
Expand Down Expand Up @@ -105,7 +104,6 @@
expect(sp.id).to_not eq 0
expect(sp.updated_at).to_not eq friendly_sp[:updated_at]
expect(sp.created_at).to_not eq friendly_sp[:created_at]
expect(sp.native).to eq false
expect(sp.approved).to eq true
expect(sp.help_text['sign_in']).to eq friendly_sp[:help_text][:sign_in].
stringify_keys
Expand All @@ -129,7 +127,6 @@
expect(sp.id).to eq old_id
expect(sp.updated_at).to_not eq friendly_sp[:updated_at]
expect(sp.created_at).to_not eq friendly_sp[:created_at]
expect(sp.native).to eq false
expect(sp.approved).to eq true
expect(sp.help_text['sign_in']).to eq friendly_sp[:help_text][:sign_in].
stringify_keys
Expand Down Expand Up @@ -184,7 +181,7 @@
end
end

context 'a non-native service provider is invalid' do
context 'a service provider is invalid' do
let(:dashboard_service_providers) do
[
{
Expand All @@ -200,7 +197,6 @@
block_encryption: 'aes256-cbc',
certs: [saml_test_sp_cert],
active: true,
native: false,
approved: true,
redirect_uris: [''],
},
Expand Down Expand Up @@ -294,25 +290,12 @@
let(:sp) { create(:service_provider, issuer: attributes[:issuer]) }
before { attributes[:active] = false }

context 'it is not a native service provider' do
it 'destroys the service_provider' do
subject.run(attributes)

destroyed_sp = ServiceProvider.find_by(issuer: attributes[:issuer])

expect(destroyed_sp).to be nil
end
end

context 'it is a native service provider' do
before { sp.update!(native: true) }
it 'is not destroyed' do
subject.run(attributes)
it 'destroys the service_provider' do
subject.run(attributes)

destroyed_sp = ServiceProvider.find_by(issuer: attributes[:issuer])
destroyed_sp = ServiceProvider.find_by(issuer: attributes[:issuer])

expect(destroyed_sp).to eq sp
end
expect(destroyed_sp).to be nil
end
end
end
Expand Down