-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Closed
Description
Issue
- The following tests in
org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive.CloudFoundryWebFluxEndpointIntegrationTests
will fail when run at any time after running the testlinksToOtherEndpointsForbidden()
operationWithSecurityInterceptorForbidden()
operationWithSecurityInterceptorSuccess()
linksToOtherEndpointsWithFullAccess()
linksToOtherEndpointsWithRestrictedAccess()
- When the above mentioned tests are run after the test
linksToOtherEndpointsForbidden()
, we get the following error
invalid-token
org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException: invalid-token
at app//org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive.ReactiveTokenValidator.validate(ReactiveTokenValidator.java:53)
at app//org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive.CloudFoundryWebFluxEndpointIntegrationTests.operationWithSecurityInterceptorForbidden(CloudFoundryWebFluxEndpointIntegrationTests.java:97)
- This makes the above mentioned tests to be order dependent
Reason
- In the test
CloudFoundryWebFluxEndpointIntegrationTests.linksToOtherEndpointsForbidden()
, theReactiveTokenValidator tokenValidator
mock is set to throwCloudFoundryAuthorizationException
whentokenValidator.validate(any())
is called. However, this is not reset after the unit test is run.
Lines 170 to 172 in da67ce4
CloudFoundryAuthorizationException exception = new CloudFoundryAuthorizationException(Reason.INVALID_TOKEN, "invalid-token"); willThrow(exception).given(tokenValidator).validate(any()); - All the above mentioned tests mock the same
validate(any())
method usinggiven(tokenValidator.validate(any())).willReturn(Mono.empty());
- So, when the above mentioned tests are called after
linksToOtherEndpointsForbidden()
without resetting thetokenValidator
mock, the mock throwsCloudFoundryAuthorizationException
causing the tests to be order dependent
Steps to Reproduce
- Run the above mentioned tests after running
CloudFoundryWebFluxEndpointIntegrationTests.linksToOtherEndpointsForbidden()
Proposed Fix
- Since using the same polluted state of the
tokenValidator
mock causes this issue, resetting the mock's state after each test run will resolve this issue. - Adding a
tearDown()
method with@AfterEach
where thetokenValidator
state is reset usingMockito.reset()
will solve this issue. - I am happy to discuss further about this issue, and I can create a PR with the proposed fix
Version
- Spring Version:
3.1.5
Metadata
Metadata
Assignees
Labels
type: taskA general taskA general task