Search in sources :

Example 66 with Claim

use of com.auth0.jwt.Claim in project java-jwt by auth0.

the class JsonNodeClaimTest method shouldGetAsMapValue.

@SuppressWarnings({ "unchecked", "RedundantCast" })
@Test
public void shouldGetAsMapValue() {
    JsonNode value = mapper.valueToTree(Collections.singletonMap("key", new UserPojo("john", 123)));
    Claim claim = claimFromNode(value);
    assertThat(claim, is(notNullValue()));
    Map map = claim.as(Map.class);
    assertThat(((Map<String, Object>) map.get("key")), hasEntry("name", (Object) "john"));
    assertThat(((Map<String, Object>) map.get("key")), hasEntry("id", (Object) 123));
}
Also used : UserPojo(com.auth0.jwt.UserPojo) JsonNode(com.fasterxml.jackson.databind.JsonNode) Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 67 with Claim

use of com.auth0.jwt.Claim in project java-jwt by auth0.

the class JsonNodeClaimTest method shouldGetNullArrayIfNonArrayValue.

@Test
public void shouldGetNullArrayIfNonArrayValue() {
    JsonNode value = mapper.valueToTree(1);
    Claim claim = claimFromNode(value);
    assertThat(claim.asArray(String.class), is(nullValue()));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 68 with Claim

use of com.auth0.jwt.Claim in project java-jwt by auth0.

the class JsonNodeClaimTest method shouldConvertToString.

@Test
public void shouldConvertToString() {
    JsonNode value = mapper.valueToTree(new UserPojo("john", 123));
    JsonNode nullValue = mapper.valueToTree(null);
    JsonNode missingValue = MissingNode.getInstance();
    Claim claim = claimFromNode(value);
    Claim nullClaim = claimFromNode(nullValue);
    Claim missingClaim = claimFromNode(missingValue);
    assertThat(claim.toString(), is("{\"name\":\"john\",\"id\":123}"));
    assertThat(nullClaim.isNull(), is(true));
    assertThat(nullClaim.toString(), is("Null claim"));
    assertThat(missingClaim.isMissing(), is(true));
    assertThat(missingClaim.toString(), is("Missing claim"));
}
Also used : UserPojo(com.auth0.jwt.UserPojo) JsonNode(com.fasterxml.jackson.databind.JsonNode) Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 69 with Claim

use of com.auth0.jwt.Claim in project java-jwt by auth0.

the class JsonNodeClaimTest method shouldGetNullArrayIfNullValue.

@Test
public void shouldGetNullArrayIfNullValue() {
    JsonNode value = mapper.valueToTree(null);
    Claim claim = claimFromNode(value);
    assertThat(claim.asArray(String.class), is(nullValue()));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 70 with Claim

use of com.auth0.jwt.Claim in project java-jwt by auth0.

the class JsonNodeClaimTest method shouldReturnNonNullClaimWhenParsingBooleanValue.

@Test
public void shouldReturnNonNullClaimWhenParsingBooleanValue() {
    JsonNode value = mapper.valueToTree(Boolean.TRUE);
    Claim claim = claimFromNode(value);
    assertThat(claim, is(notNullValue()));
    assertThat(claim, is(instanceOf(JsonNodeClaim.class)));
    assertThat(claim.isNull(), is(false));
    assertThat(claim.isMissing(), is(false));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Aggregations

Claim (com.auth0.jwt.interfaces.Claim)110 Test (org.junit.Test)67 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)62 JsonNode (com.fasterxml.jackson.databind.JsonNode)42 Algorithm (com.auth0.jwt.algorithms.Algorithm)24 Date (java.util.Date)24 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)21 RSAPublicKey (java.security.interfaces.RSAPublicKey)21 Test (org.junit.jupiter.api.Test)18 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)17 JWTVerifier (com.auth0.jwt.JWTVerifier)15 JwksTestKeySource (org.sdase.commons.server.auth.service.testsources.JwksTestKeySource)14 JsonObject (com.google.gson.JsonObject)10 HashMap (java.util.HashMap)9 UserPojo (com.auth0.jwt.UserPojo)8 IOException (java.io.IOException)8 Map (java.util.Map)8 TestingProcessManager (io.supertokens.test.TestingProcessManager)7 NullClaim (com.auth0.jwt.impl.NullClaim)5 JWT (com.auth0.jwt.JWT)4