Skip to content

Conversation

@azmeuk
Copy link
Member

@azmeuk azmeuk commented Dec 4, 2025

Actually that was already available, but this adds a default value and a unit test.

Copilot AI review requested due to automatic review settings December 4, 2025 11:08
Copilot finished reviewing on behalf of azmeuk December 4, 2025 11:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes the algorithm parameter optional in the pick_random_key method by adding a default value of None. When no algorithm is specified, the method falls back to selecting randomly from all keys in the set.

  • Added default value None to the algorithm parameter in pick_random_key method signature
  • Added a unit test to verify the method works correctly when called without arguments

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/joserfc/_keys.py Updated pick_random_key method signature to make algorithm parameter optional with default value None
tests/jwk/test_jwk_set.py Added test case to verify pick_random_key() can be called without arguments and returns a key

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (bc13ead) to head (ee046b2).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #83   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           47        47           
  Lines         2850      2850           
  Branches       320       320           
=========================================
  Hits          2850      2850           
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lepture
Copy link
Member

lepture commented Dec 6, 2025

The method is used in jwk.guess_key, and jwe._guess_sender_key

return_key = resolved_key.pick_random_key(headers["alg"], parameters)
skey = key.pick_random_key(headers["alg"])

When this method is used, the algorithm name is always known.

@azmeuk
Copy link
Member Author

azmeuk commented Dec 6, 2025

I was thinking of other use cases. For example, in an OIDC server, if a client has not been set a favorite alg for signing, one might want to just use a random key among the keys available, and call pick_random_key without argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants