Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def form_data

private

def api_call
track_missing_credentials! if credentials_missing?

super
end

def token
context.params[:token]
end
Expand All @@ -60,4 +66,17 @@ def france_connect_check_token_url
def api_name
context.params[:api_name]
end

def credentials_missing?
client_id == "france_connect_v2_#{api_name}_client_id" ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

je ne comprends pas comment cela peut fonctionner y'a un souci quelque part

@Samuelfaure Samuelfaure Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En staging / dev, Siade.credentials[:france_connect_v2_allocation_rentree_scolaire_client_id] renvoie "france_connect_v2_allocation_rentree_scolaire_client_id" si cette clef n'existe pas

if Rails.env.local? || Rails.env.staging?
  credentials.default_proc = proc do |hash, key|
    is_url_or_domain = key.to_s.include?('_url') || key.to_s.end_with?('_domain')

    hash[key] = is_url_or_domain ? "https://#{key}.gouv.fr" : key.to_s
  end
else
  credentials.default_proc = proc do |_, key|
    raise KeyError, "key '#{key}' not found"
  end
end

En vrai je réalise qu'il faudrait juste virer le .staging? ici à la place, vu que ça raise en prod

@Samuelfaure Samuelfaure Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoique d'un autre coté on a mis le .staging? ici pour une bonne raison 🙄 on fait pas d'appels en staging donc osef des credentials... à l'exception de l'env d'intégration FC avec vrai token d'intégration.... mmmmhhh tu en penses quoi?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne comprends pas ce que tu veux résoudre comme problème 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en staging j'ai passé un moment à debug l'absence des credentials FranceConnect 😅 je me dit que ça vaut la peine de log ça dans Sentry pour pas re-débug le meme problème

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Siade.credentials[:"france_connect_v2_#{api_name}_client_id"].presence || (raise error)

un truc du genre

client_secret == "france_connect_v2_#{api_name}_client_secret"
end

def track_missing_credentials!
MonitoringService.instance.track(
'error',
"FranceConnect client credentials missing for api_name=#{api_name}",
fingerprint: ['france-connect-missing-credentials', api_name]
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,44 @@
end
end
end

context 'when FranceConnect client credentials are missing for this api_name' do
before do
allow(Rails).to receive(:env).and_return('production'.inquiry)
allow(Siade.credentials).to receive(:[]).and_call_original
allow(Siade.credentials).to receive(:[]).with(:france_connect_v2_quotient_familial_client_id)
.and_return('france_connect_v2_quotient_familial_client_id')
allow(Siade.credentials).to receive(:[]).with(:france_connect_v2_quotient_familial_client_secret)
.and_return('france_connect_v2_quotient_familial_client_secret')
allow(MonitoringService.instance).to receive(:track)
end

it 'tracks a distinct, alertable error to Sentry' do
make_call

expect(MonitoringService.instance).to have_received(:track).with(
'error',
a_string_including('quotient_familial'),
fingerprint: %w[france-connect-missing-credentials quotient_familial]
)
end
end

context 'when FranceConnect client credentials are configured for this api_name' do
before do
allow(Rails).to receive(:env).and_return('production'.inquiry)
allow(Siade.credentials).to receive(:[]).and_call_original
allow(Siade.credentials).to receive(:[]).with(:france_connect_v2_quotient_familial_client_id)
.and_return('a_real_looking_client_id')
allow(Siade.credentials).to receive(:[]).with(:france_connect_v2_quotient_familial_client_secret)
.and_return('a_real_looking_client_secret')
allow(MonitoringService.instance).to receive(:track)
end

it 'does not track anything' do
make_call

expect(MonitoringService.instance).not_to have_received(:track)
end
end
end
Loading