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

editoast: add configurable authorization to TestAppBuilder #10197

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

hamz2a
Copy link
Contributor

@hamz2a hamz2a commented Dec 26, 2024

Update TestAppBuilder to support configurable authorization settings

  • Modified TestAppBuilder to allow enabling/disabling authorization via the enable_authorization field.
  • Added a test to verify that project creation fails with a FORBIDDEN status when authorization is enabled.

@hamz2a hamz2a requested a review from a team as a code owner December 26, 2024 10:25
@github-actions github-actions bot added the area:editoast Work on Editoast Service label Dec 26, 2024
@hamz2a hamz2a self-assigned this Dec 26, 2024
@hamz2a hamz2a requested a review from leovalais December 26, 2024 10:26
@hamz2a hamz2a force-pushed the hai/editoast-configurable-authorization-in-testapp branch from fe89a25 to 1bf9525 Compare December 26, 2024 10:27
@codecov-commenter
Copy link

codecov-commenter commented Dec 26, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.46%. Comparing base (8ac5276) to head (8713f84).
Report is 67 commits behind head on dev.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev   #10197   +/-   ##
=======================================
  Coverage   81.46%   81.46%           
=======================================
  Files        1058     1058           
  Lines      104318   104320    +2     
  Branches      724      722    -2     
=======================================
+ Hits        84981    84985    +4     
+ Misses      19295    19294    -1     
+ Partials       42       41    -1     
Flag Coverage Δ
editoast 73.68% <100.00%> (+0.05%) ⬆️
front 89.18% <ø> (-0.02%) ⬇️
gateway 2.18% <ø> (ø)
osrdyne 3.28% <ø> (ø)
railjson_generator 87.50% <ø> (ø)
tests 87.05% <ø> (+0.04%) ⬆️

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.

Copy link
Contributor

@leovalais leovalais left a comment

Choose a reason for hiding this comment

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

This PR revealed a bug. When no authentication header is sent to editoast, we respond with a 403 instead of a 401. Its fix belongs to another PR, but I don't believe we should be testing a faulty behavior. Here's my proposition:

  1. Add a function TestApp::def_user(&self, UserInfo, impl IntoIterator<Item = BuiltinRole>) that persists a user configuration for a test.
  2. Add a convenience function TestAppBuilder::user(self, UserInfo, impl IntoIterator<Item = BuiltinRole>)
  3. Add a function like app.post("...").from_user(UserInfo { ... }).json(... to add the headers to the request.
  4. Change the test behavior to "make a request with a real authenticated user which doesn't have the required role", where responding 403 is a valid response.

Wdyt?

editoast/src/views/projects.rs Show resolved Hide resolved
editoast/src/views/test_app.rs Outdated Show resolved Hide resolved
editoast/src/views/test_app.rs Outdated Show resolved Hide resolved
@hamz2a hamz2a force-pushed the hai/editoast-configurable-authorization-in-testapp branch from 1bf9525 to d708641 Compare December 27, 2024 15:54
@hamz2a hamz2a requested a review from leovalais December 27, 2024 15:55
Copy link
Contributor

@leovalais leovalais left a comment

Choose a reason for hiding this comment

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

Thanks for the modifications! It looks much better, a few comments about API readability and convenience.

editoast/src/views/projects.rs Show resolved Hide resolved
editoast/src/views/test_app.rs Outdated Show resolved Hide resolved
editoast/src/views/test_app.rs Outdated Show resolved Hide resolved
editoast/src/views/test_app.rs Outdated Show resolved Hide resolved
@hamz2a hamz2a force-pushed the hai/editoast-configurable-authorization-in-testapp branch 2 times, most recently from 1314060 to 67d9838 Compare December 30, 2024 15:27
@hamz2a hamz2a requested a review from leovalais December 30, 2024 15:34
Copy link
Contributor

@leovalais leovalais left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Signed-off-by: hamz2a <atrari.hamza@gmail.com>
@hamz2a hamz2a force-pushed the hai/editoast-configurable-authorization-in-testapp branch from 67d9838 to 8713f84 Compare January 7, 2025 09:55
@hamz2a hamz2a enabled auto-merge January 7, 2025 10:03
@hamz2a hamz2a added this pull request to the merge queue Jan 7, 2025
Merged via the queue into dev with commit db906a9 Jan 7, 2025
27 checks passed
@hamz2a hamz2a deleted the hai/editoast-configurable-authorization-in-testapp branch January 7, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:editoast Work on Editoast Service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants