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

Fix access rules order and add integration tests #16

Merged
merged 2 commits into from
Apr 25, 2022

Conversation

groldan
Copy link
Member

@groldan groldan commented Apr 25, 2022

Access rules were being applied in the wrong order,
global rules first and service rules after, leading
to the global /** rule matching service URLs that
it shouldn't.

Adds integration tests using WireMock.

Access rules were being applied in the wrong order,
global rules first and service rules after, leading
to the global /** rule matching service URLs that
it shouldn't.

Adds integration tests using WireMock.
@groldan groldan merged commit 4450068 into main Apr 25, 2022
@groldan groldan deleted the fix_global_acces_rules branch April 25, 2022 22:35
@pmauduit
Copy link
Member

Adds integration tests using WireMock.

interesting lib, I did not know about it

@groldan
Copy link
Member Author

groldan commented Apr 26, 2022

I've read about it, first time I used it though. Really nice.

Comment on lines +290 to +301
public @Test void testService_requires_specific_roles_redirects_unauthenticated_to_login() {
mockService.stubFor(get(urlMatching("/analytics(/.*)?")).willReturn(ok()));

testClient.get().uri("/analytics")//
.exchange()//
.expectStatus().isFound()//
.expectHeader().location("/login");

testClient.get().uri("/analytics/any/thing")//
.exchange()//
.expectStatus().isFound()//
.expectHeader().location("/login");
Copy link
Member

Choose a reason for hiding this comment

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

I don't get the test's intent: if "willReturn(ok())", then why are we expecting a redirect to "/login" ?

Copy link
Member Author

Choose a reason for hiding this comment

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

because we're not expecting a 200, or the backend service to be hit at all. If it returns 200 means the backend service was hit and the access rule wasn't applied.

Copy link
Member Author

Choose a reason for hiding this comment

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

which mimics what would happen in real life. If you hit /analytics/anything in the actual analytics app, it'd return OK. But we want to assert the request doesn't even get there because the access rule requires a given role, and there's no authenticated user, so it gets redirected to the login page?

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.

None yet

2 participants