Skip to content

Commit

Permalink
validate integrity of france connect authorization id
Browse files Browse the repository at this point in the history
  • Loading branch information
JeSuisUnCaillou committed Dec 2, 2024
1 parent e80987c commit 0462763
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ module DGFIPExtensions::APIImpotParticulierModalities
add_attributes :france_connect_authorization_id
validates :france_connect_authorization_id,
presence: true,
inclusion: { in: organization.valid_authorizations_of(AuthorizationRequest::FranceConnect).pluck(:id), message: 'coucou' },
inclusion: { in: ->(authorization_request) { authorization_request.organization.valid_authorizations_of(AuthorizationRequest::FranceConnect).pluck(:id) } },
if: -> { modalities == 'with_france_connect' && need_complete_validation?(:modalities) }

validate :france_connect_authorization_
end

def associated_france_connect_authorization
Expand Down
27 changes: 26 additions & 1 deletion spec/models/authorization_request/api_impot_particulier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
volumetrie_appels_par_minute:,
volumetrie_justification:,
safety_certification_begin_date:,
safety_certification_end_date:
safety_certification_end_date:,
organization:
)
end

Expand All @@ -24,6 +25,7 @@
let(:volumetrie_justification) { nil }
let(:safety_certification_begin_date) { nil }
let(:safety_certification_end_date) { nil }
let(:organization) { nil }

describe 'volumetrie validation' do
before { authorization_request.current_build_step = 'volumetrie' }
Expand Down Expand Up @@ -106,6 +108,29 @@

it { is_expected.not_to be_valid }
end

context 'with a france connect authorization id from another organization' do
let(:validated_france_connect_authorization_request) { create(:authorization_request, :france_connect, :validated) }
let(:france_connect_authorization_id) { validated_france_connect_authorization_request.authorizations.first.id }

it { is_expected.not_to be_valid }
end

context 'with a revoked france connect authorization id from the same organization' do
let(:validated_france_connect_authorization_request) { create(:authorization_request, :france_connect, :revoked) }
let(:organization) { validated_france_connect_authorization_request.organization }
let(:france_connect_authorization_id) { validated_france_connect_authorization_request.authorizations.first.id }

it { is_expected.not_to be_valid }
end

context 'with a validated france connect authorization id from the same organization' do
let(:validated_france_connect_authorization_request) { create(:authorization_request, :france_connect, :validated) }
let(:organization) { validated_france_connect_authorization_request.organization }
let(:france_connect_authorization_id) { validated_france_connect_authorization_request.authorizations.first.id }

it { is_expected.to be_valid }
end
end
end

Expand Down

0 comments on commit 0462763

Please sign in to comment.