use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.Token in project spring-boot by spring-projects.
the class ReactiveTokenValidatorTests method validateTokenWhenCacheIsEmptyShouldFetchTokenKeys.
@Test
void validateTokenWhenCacheIsEmptyShouldFetchTokenKeys() throws Exception {
PublisherProbe<Map<String, String>> fetchTokenKeys = PublisherProbe.of(Mono.just(VALID_KEYS));
given(this.securityService.fetchTokenKeys()).willReturn(fetchTokenKeys.mono());
given(this.securityService.getUaaUrl()).willReturn(Mono.just("http://localhost:8080/uaa"));
String header = "{\"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
String claims = "{\"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
StepVerifier.create(this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes())))).verifyComplete();
assertThat(this.tokenValidator).hasFieldOrPropertyWithValue("cachedTokenKeys", VALID_KEYS);
fetchTokenKeys.assertWasSubscribed();
}
use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.Token in project spring-boot by spring-projects.
the class TokenValidatorTests method validateTokenWhenIssuerIsNotValidShouldThrowException.
@Test
void validateTokenWhenIssuerIsNotValidShouldThrowException() {
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
given(this.securityService.getUaaUrl()).willReturn("https://other-uaa.com");
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\", \"typ\": \"JWT\", \"scope\": [\"actuator.read\"]}";
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\"}";
assertThatExceptionOfType(CloudFoundryAuthorizationException.class).isThrownBy(() -> this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes())))).satisfies(reasonRequirement(Reason.INVALID_ISSUER));
}
use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.Token in project spring-boot by spring-projects.
the class TokenValidatorTests method validateTokenWhenTokenAlgorithmIsNotRS256ShouldThrowException.
@Test
void validateTokenWhenTokenAlgorithmIsNotRS256ShouldThrowException() {
String header = "{ \"alg\": \"HS256\", \"typ\": \"JWT\"}";
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
assertThatExceptionOfType(CloudFoundryAuthorizationException.class).isThrownBy(() -> this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes())))).satisfies(reasonRequirement(Reason.UNSUPPORTED_TOKEN_SIGNING_ALGORITHM));
}
use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.Token in project spring-boot by spring-projects.
the class TokenValidatorTests method validateTokenWhenSignatureInvalidShouldThrowException.
@Test
void validateTokenWhenSignatureInvalidShouldThrowException() {
ReflectionTestUtils.setField(this.tokenValidator, "tokenKeys", Collections.singletonMap("valid-key", INVALID_KEY));
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
assertThatExceptionOfType(CloudFoundryAuthorizationException.class).isThrownBy(() -> this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes())))).satisfies(reasonRequirement(Reason.INVALID_SIGNATURE));
}
use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.Token in project spring-boot by spring-projects.
the class TokenValidatorTests method validateTokenWhenAudienceIsNotValidShouldThrowException.
@Test
void validateTokenWhenAudienceIsNotValidShouldThrowException() {
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
given(this.securityService.getUaaUrl()).willReturn("http://localhost:8080/uaa");
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\", \"typ\": \"JWT\"}";
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"foo.bar\"]}";
assertThatExceptionOfType(CloudFoundryAuthorizationException.class).isThrownBy(() -> this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes())))).satisfies(reasonRequirement(Reason.INVALID_AUDIENCE));
}
Aggregations