Closed andreasgerner closed 7 months ago
@andreasgerner can you share your project or a reproducer? What you are doing seems pretty close to what is done at several places in this repo (and others that I author), so it should work (this can be due to your security config or whatever)...
I setup a sample containing everything that should be needed to reproduce.
@andreasgerner I found a few things to fix in your reproducer:
src/main/resources/application.yaml
should be resolved (use environment variables to override this values when you start the program, not inside the yaml)
oidc:
issuer-url: https://some-issuer.com/auth/realms/master
client-id: client-id
com.c4-soft.*
are lost => rename src/test/resources/application.yaml
to src/test/resources/application-test.yaml
@WithMckMvc
or @SpringBootTest
, so decorate the test with what is relevant)Migrating from pure unit tests to @SpringBootTest
integration tests resolved my issue, thank you!
@andreasgerner you're welcome. thank you for taking time to provide with reproducer. Please note that @SpringBootTest
should be used with care as it can slow down tests execution by loading more of the application context than what is actually needed. Use @WebMvcTest
when testing a controller and specify the minimum configuration classes to load when using @SpringBootTest
.
Describe the bug When using
@WithJwt
, the roles of my JWT-JSON-File are not picked up according to the configured JSON-Path in my configuration. Further debugging showed me, thatConfigurableClaimSetAuthoritiesConverter::convert
doesn't get called.Code sample Test Class:
student.json:
application.yml (in test resources):
Expected behavior
Authentication
set in test has authority 'some-role'. Instead, authorities only include scopes.