|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
* Copyright 2012-2021 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -91,7 +91,7 @@ class TokenValidatorTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void validateTokenWhenKidValidationFailsTwiceShouldThrowException() throws Exception {
|
|
|
|
void validateTokenWhenKidValidationFailsTwiceShouldThrowException() {
|
|
|
|
ReflectionTestUtils.setField(this.tokenValidator, "tokenKeys", INVALID_KEYS);
|
|
|
|
ReflectionTestUtils.setField(this.tokenValidator, "tokenKeys", INVALID_KEYS);
|
|
|
|
given(this.securityService.fetchTokenKeys()).willReturn(INVALID_KEYS);
|
|
|
|
given(this.securityService.fetchTokenKeys()).willReturn(INVALID_KEYS);
|
|
|
|
String header = "{\"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
|
|
|
|
String header = "{\"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
|
|
|
@ -133,7 +133,7 @@ class TokenValidatorTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void validateTokenWhenSignatureInvalidShouldThrowException() throws Exception {
|
|
|
|
void validateTokenWhenSignatureInvalidShouldThrowException() {
|
|
|
|
ReflectionTestUtils.setField(this.tokenValidator, "tokenKeys",
|
|
|
|
ReflectionTestUtils.setField(this.tokenValidator, "tokenKeys",
|
|
|
|
Collections.singletonMap("valid-key", INVALID_KEY));
|
|
|
|
Collections.singletonMap("valid-key", INVALID_KEY));
|
|
|
|
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
|
|
|
|
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
|
|
|
@ -144,7 +144,7 @@ class TokenValidatorTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void validateTokenWhenTokenAlgorithmIsNotRS256ShouldThrowException() throws Exception {
|
|
|
|
void validateTokenWhenTokenAlgorithmIsNotRS256ShouldThrowException() {
|
|
|
|
String header = "{ \"alg\": \"HS256\", \"typ\": \"JWT\"}";
|
|
|
|
String header = "{ \"alg\": \"HS256\", \"typ\": \"JWT\"}";
|
|
|
|
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
|
|
|
|
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
|
|
|
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class).isThrownBy(
|
|
|
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class).isThrownBy(
|
|
|
@ -153,7 +153,7 @@ class TokenValidatorTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void validateTokenWhenExpiredShouldThrowException() throws Exception {
|
|
|
|
void validateTokenWhenExpiredShouldThrowException() {
|
|
|
|
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
|
|
|
|
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
|
|
|
|
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
|
|
|
|
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
|
|
|
|
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\", \"typ\": \"JWT\"}";
|
|
|
|
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\", \"typ\": \"JWT\"}";
|
|
|
@ -164,7 +164,7 @@ class TokenValidatorTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void validateTokenWhenIssuerIsNotValidShouldThrowException() throws Exception {
|
|
|
|
void validateTokenWhenIssuerIsNotValidShouldThrowException() {
|
|
|
|
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
|
|
|
|
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
|
|
|
|
given(this.securityService.getUaaUrl()).willReturn("https://other-uaa.com");
|
|
|
|
given(this.securityService.getUaaUrl()).willReturn("https://other-uaa.com");
|
|
|
|
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\", \"typ\": \"JWT\", \"scope\": [\"actuator.read\"]}";
|
|
|
|
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\", \"typ\": \"JWT\", \"scope\": [\"actuator.read\"]}";
|
|
|
@ -175,7 +175,7 @@ class TokenValidatorTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void validateTokenWhenAudienceIsNotValidShouldThrowException() throws Exception {
|
|
|
|
void validateTokenWhenAudienceIsNotValidShouldThrowException() {
|
|
|
|
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
|
|
|
|
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
|
|
|
|
given(this.securityService.getUaaUrl()).willReturn("http://localhost:8080/uaa");
|
|
|
|
given(this.securityService.getUaaUrl()).willReturn("http://localhost:8080/uaa");
|
|
|
|
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\", \"typ\": \"JWT\"}";
|
|
|
|
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\", \"typ\": \"JWT\"}";
|
|
|
|