Skip to content

CloudFoundry endpoint integration tests are order dependent #38363

@SaaiVenkat

Description

@SaaiVenkat

Issue

  • The following tests in org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive.CloudFoundryWebFluxEndpointIntegrationTests will fail when run at any time after running the test linksToOtherEndpointsForbidden()
    • 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(), the ReactiveTokenValidator tokenValidator mock is set to throw CloudFoundryAuthorizationException when tokenValidator.validate(any()) is called. However, this is not reset after the unit test is run.
    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 using given(tokenValidator.validate(any())).willReturn(Mono.empty());
  • So, when the above mentioned tests are called after linksToOtherEndpointsForbidden() without resetting the tokenValidator mock, the mock throws CloudFoundryAuthorizationException 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 the tokenValidator state is reset using Mockito.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

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions