Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module for generating JWTs #2948

Merged
merged 6 commits into from
Sep 24, 2024
Merged

Conversation

stveit
Copy link
Contributor

@stveit stveit commented Aug 8, 2024

#2481

partial replacement for #2569

Adds functions for generating access and refresh Tokens of the Jason Web variety.

The expiry values should probably be configurable, but I'd rather do that in a separate PR since it would require
deciding the granularity of expiry (seconds, minutes, hours), updating docs etc etc ..

@stveit stveit marked this pull request as ready for review August 8, 2024 14:22
@stveit stveit self-assigned this Aug 8, 2024
Copy link

codecov bot commented Aug 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.48%. Comparing base (2dda1eb) to head (cd9e8fb).
Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2948      +/-   ##
==========================================
+ Coverage   60.47%   60.48%   +0.01%     
==========================================
  Files         603      604       +1     
  Lines       43771    43792      +21     
  Branches       48       48              
==========================================
+ Hits        26469    26489      +20     
- Misses      17290    17291       +1     
  Partials       12       12              

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

@stveit stveit force-pushed the add-jwt-token-creation branch 2 times, most recently from 524896f to 49ee048 Compare September 18, 2024 07:30
Copy link
Contributor

@hmpf hmpf left a comment

Choose a reason for hiding this comment

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

Looks fine to me. Why is 'name' and 'aud' identical?

@stveit
Copy link
Contributor Author

stveit commented Sep 23, 2024

Looks fine to me. Why is 'name' and 'aud' identical?

name is the name of the local nav server, and these local tokens are made to be used for the local nav server, hence the audience (aud) is the same as the name for the server. iss is also the same as name and aud, since the server issues them itself

Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

Looks a-ok, but I have questions I want clarified before I give the green light :)

python/nav/web/jwtgen.py Outdated Show resolved Hide resolved
tests/unittests/web/jwtgen_test.py Show resolved Hide resolved
tests/unittests/web/jwtgen_test.py Show resolved Hide resolved
yield "nav"


@pytest.fixture(scope="module")
Copy link
Member

Choose a reason for hiding this comment

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

Just curious why you picked "module" scope for this fixture?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If i remember correctly, fixtures with "module" scope can only use other fixtures that are also "module" scope or higher, so since jwtconf_mock(which is "module" scope) uses this, this also has to be "module" scope

Copy link
Member

Choose a reason for hiding this comment

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

The reason I ask is that I can't recall ever seeing any particular use-case for module scoped fixtures.

I.e. test scoped fixtures are run on every test. module scoped fixtures are only run once per test module. session-scoped fixtures are run once per full test session.

If a test fixture is only ever defined and used within a single module, then I don't see that there is a principal difference between assigning module or session scope to it, so I was curious why you picked module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see what you mean. I think my rationality here was to use the lowest level scope that still fulfilled the needs. I looked at the options and module seemed to fit the best in this case.

python/nav/jwtconf.py Show resolved Hide resolved
yield "nav"


@pytest.fixture(scope="module")
Copy link
Member

Choose a reason for hiding this comment

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

The reason I ask is that I can't recall ever seeing any particular use-case for module scoped fixtures.

I.e. test scoped fixtures are run on every test. module scoped fixtures are only run once per test module. session-scoped fixtures are run once per full test session.

If a test fixture is only ever defined and used within a single module, then I don't see that there is a principal difference between assigning module or session scope to it, so I was curious why you picked module.

@stveit stveit merged commit a9040ca into Uninett:master Sep 24, 2024
10 checks passed
@stveit stveit deleted the add-jwt-token-creation branch September 24, 2024 13:53
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.

3 participants