|
|
@ -16,12 +16,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.cloudfoundry;
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.cloudfoundry;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Base64;
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException.Reason;
|
|
|
|
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException.Reason;
|
|
|
|
import org.springframework.util.Base64Utils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
@ -44,8 +44,8 @@ class TokenTests {
|
|
|
|
String header = "{\"alg\": \"RS256\", \"kid\": \"key-id\", \"typ\": \"JWT\"}";
|
|
|
|
String header = "{\"alg\": \"RS256\", \"kid\": \"key-id\", \"typ\": \"JWT\"}";
|
|
|
|
String claims = "invalid-claims";
|
|
|
|
String claims = "invalid-claims";
|
|
|
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
|
|
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
|
|
|
.isThrownBy(() -> new Token(Base64Utils.encodeToString(header.getBytes()) + "."
|
|
|
|
.isThrownBy(() -> new Token(Base64.getEncoder().encodeToString(header.getBytes()) + "."
|
|
|
|
+ Base64Utils.encodeToString(claims.getBytes())))
|
|
|
|
+ Base64.getEncoder().encodeToString(claims.getBytes())))
|
|
|
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
|
|
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -54,8 +54,8 @@ class TokenTests {
|
|
|
|
String header = "invalid-header";
|
|
|
|
String header = "invalid-header";
|
|
|
|
String claims = "{\"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\"}";
|
|
|
|
String claims = "{\"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\"}";
|
|
|
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
|
|
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
|
|
|
.isThrownBy(() -> new Token(Base64Utils.encodeToString(header.getBytes()) + "."
|
|
|
|
.isThrownBy(() -> new Token(Base64.getEncoder().encodeToString(header.getBytes()) + "."
|
|
|
|
+ Base64Utils.encodeToString(claims.getBytes())))
|
|
|
|
+ Base64.getEncoder().encodeToString(claims.getBytes())))
|
|
|
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
|
|
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -71,16 +71,16 @@ class TokenTests {
|
|
|
|
void validJwt() {
|
|
|
|
void validJwt() {
|
|
|
|
String header = "{\"alg\": \"RS256\", \"kid\": \"key-id\", \"typ\": \"JWT\"}";
|
|
|
|
String header = "{\"alg\": \"RS256\", \"kid\": \"key-id\", \"typ\": \"JWT\"}";
|
|
|
|
String claims = "{\"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\"}";
|
|
|
|
String claims = "{\"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\"}";
|
|
|
|
String content = Base64Utils.encodeToString(header.getBytes()) + "."
|
|
|
|
String content = Base64.getEncoder().encodeToString(header.getBytes()) + "."
|
|
|
|
+ Base64Utils.encodeToString(claims.getBytes());
|
|
|
|
+ Base64.getEncoder().encodeToString(claims.getBytes());
|
|
|
|
String signature = Base64Utils.encodeToString("signature".getBytes());
|
|
|
|
String signature = Base64.getEncoder().encodeToString("signature".getBytes());
|
|
|
|
Token token = new Token(content + "." + signature);
|
|
|
|
Token token = new Token(content + "." + signature);
|
|
|
|
assertThat(token.getExpiry()).isEqualTo(2147483647);
|
|
|
|
assertThat(token.getExpiry()).isEqualTo(2147483647);
|
|
|
|
assertThat(token.getIssuer()).isEqualTo("http://localhost:8080/uaa/oauth/token");
|
|
|
|
assertThat(token.getIssuer()).isEqualTo("http://localhost:8080/uaa/oauth/token");
|
|
|
|
assertThat(token.getSignatureAlgorithm()).isEqualTo("RS256");
|
|
|
|
assertThat(token.getSignatureAlgorithm()).isEqualTo("RS256");
|
|
|
|
assertThat(token.getKeyId()).isEqualTo("key-id");
|
|
|
|
assertThat(token.getKeyId()).isEqualTo("key-id");
|
|
|
|
assertThat(token.getContent()).isEqualTo(content.getBytes());
|
|
|
|
assertThat(token.getContent()).isEqualTo(content.getBytes());
|
|
|
|
assertThat(token.getSignature()).isEqualTo(Base64Utils.decodeFromString(signature));
|
|
|
|
assertThat(token.getSignature()).isEqualTo(Base64.getDecoder().decode(signature));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -120,9 +120,9 @@ class TokenTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Token createToken(String header, String claims) {
|
|
|
|
private Token createToken(String header, String claims) {
|
|
|
|
Token token = new Token(
|
|
|
|
Token token = new Token(Base64.getEncoder().encodeToString(header.getBytes()) + "."
|
|
|
|
Base64Utils.encodeToString(header.getBytes()) + "." + Base64Utils.encodeToString(claims.getBytes())
|
|
|
|
+ Base64.getEncoder().encodeToString(claims.getBytes()) + "."
|
|
|
|
+ "." + Base64Utils.encodeToString("signature".getBytes()));
|
|
|
|
+ Base64.getEncoder().encodeToString("signature".getBytes()));
|
|
|
|
return token;
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|