Skip to content

Commit

Permalink
Add Introspection Claims Test (#2404)
Browse files Browse the repository at this point in the history
* Add Introspection Claims Test

* add more example settings

* Revert "add more example settings"

This reverts commit 21a5b88.

* add constant
  • Loading branch information
strehle authored Jul 14, 2023
1 parent 0ed726b commit f7cef28
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public class Claims {
private Long previousLogonTime;
@JsonProperty(ClaimConstants.AMR)
private String[] amr;
@JsonProperty(ClaimConstants.CLIENT_AUTH_METHOD)
private String clientAuth;

public String getUserId() {
return userId;
Expand Down Expand Up @@ -353,4 +355,12 @@ public List<String> getGrantedScopes() {
public void setGrantedScopes(List<String> grantedScopes) {
this.grantedScopes = grantedScopes;
}

public String getClientAuth() {
return this.clientAuth;
}

public void setClientAuth(final String clientAuth) {
this.clientAuth = clientAuth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ static public List<String> getStringValues() {
public static final String GRANT_TYPE_AUTHORIZATION_CODE = "authorization_code";
public static final String GRANT_TYPE_IMPLICIT = "implicit";

public static final String CLIENT_AUTH_NONE = "none";

public static final String ID_TOKEN_HINT_PROMPT = "prompt";
public static final String ID_TOKEN_HINT_PROMPT_NONE = "none";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.cloudfoundry.identity.uaa.oauth.token;

import com.nimbusds.jose.util.Base64URL;
import org.cloudfoundry.identity.uaa.util.JsonUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.text.ParseException;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class IntrospectionClaimsTest {

private final static String TOKEN_PAYLOAD = "eyJqdGkiOiJiODc5MzNkYmQ3MDM0ZTZjODE1MDZmOTljODUwYWUwYSIsImNsaWVudF9hdXRoX21ldGhvZCI6Im5vbmUiLCJzdWIiOiJiZjNkOTJhNC1jNGVjLTQxMDQtOGJmNS0yZTMwMTFmZDQxODUiLCJzY29wZSI6WyJvcGVuaWQiXSwiY2xpZW50X2lkIjoibG9naW4iLCJjaWQiOiJsb2dpbiIsImF6cCI6ImxvZ2luIiwicmV2b2NhYmxlIjp0cnVlLCJncmFudF90eXBlIjoiYXV0aG9yaXphdGlvbl9jb2RlIiwidXNlcl9pZCI6ImJmM2Q5MmE0LWM0ZWMtNDEwNC04YmY1LTJlMzAxMWZkNDE4NSIsIm9yaWdpbiI6Imlhcy5wcm94eSIsInVzZXJfbmFtZSI6IkZpcnN0Lk5hbWVAZW1haWwub3JnIiwiZW1haWwiOiJGaXJzdC5OYW1lQGVtYWlsLm9yZyIsImF1dGhfdGltZSI6MTY4OTE3ODg2MiwicmV2X3NpZyI6IjIzYmRhYmZkIiwiaWF0IjoxNjg5MTc4ODYzLCJleHAiOjE2ODkyMjIwNjMsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MC91YWEvb2F1dGgvdG9rZW4iLCJ6aWQiOiJ1YWEiLCJhdWQiOlsib3BlbmlkIiwibG9naW4iXX0";
private IntrospectionClaims INTROSPECTION_PAYLOAD;

@BeforeEach
void setup() throws ParseException {
String json = new Base64URL(TOKEN_PAYLOAD).decodeToString();
INTROSPECTION_PAYLOAD = JsonUtils.readValue(json, IntrospectionClaims.class);
INTROSPECTION_PAYLOAD.setActive(false);
}

@Test
void setActive() {
INTROSPECTION_PAYLOAD.setActive(true);
assertTrue(INTROSPECTION_PAYLOAD.isActive());
}

@Test
void isActive() {
assertFalse(INTROSPECTION_PAYLOAD.isActive());
}

@Test
void testSerialize() {
assertTrue(JsonUtils.writeValueAsString(INTROSPECTION_PAYLOAD).contains(TokenConstants.CLIENT_AUTH_NONE));
}
}

0 comments on commit f7cef28

Please sign in to comment.