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