package com.scalepoint.jwt_assertion_client;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

/**
 * Validate that assertion token is generated according to the specification
 */
@SuppressWarnings("unused")
public class JwtAssertionFactoryTest {

    private final static String TOKEN_ENDPOINT_URI = "https://foobar";
    private final static String CLIENT_ID = "clientid";
    private Jws<Claims> token;
    private String thumbprint;

    @BeforeClass
    public void init() {
        RSACertificateWithPrivateKey keyPair = TestCertificateHelper.load();
        thumbprint = CertificateUtil.getThumbprint(keyPair.getCertificate());
        JwtAssertionFactory factory = new JwtAssertionFactory(TOKEN_ENDPOINT_URI, CLIENT_ID, keyPair);
        String tokenString = factory.CreateAssertionToken();
        token = Jwts.parser().setSigningKey(keyPair.getPrivateKey()).parseClaimsJws(tokenString);
    }

    @Test
    public void shouldBeJwt() {
        Assert.assertEquals(token.getHeader().getType(), "JWT");
    }

    @Test
    public void shouldUseRS256() {
        Assert.assertEquals(token.getHeader().getAlgorithm(), "RS256");
    }

    @Test
    public void shouldContainX5t() {
        Assert.assertEquals(token.getHeader().get("x5t"), thumbprint);
    }

    @Test
    public void shouldContainValidIssuer() {
        Assert.assertEquals(token.getBody().getIssuer(), CLIENT_ID);
    }

    @Test
    public void shouldContainValidSubject() {
        Assert.assertEquals(token.getBody().getSubject(), CLIENT_ID);
    }

    @Test
    public void shouldContainValidAudience() {
        Assert.assertEquals(token.getBody().getAudience(), TOKEN_ENDPOINT_URI);
    }

    @Test
    public void shouldContainJwtId() {
        Assert.assertNotNull(token.getBody().getId());
    }

    @Test
    public void shouldContainExpiration() {
        Assert.assertNotNull(token.getBody().getExpiration());
    }

    @Test
    public void shouldContainIssuedAt() {
        Assert.assertNotNull(token.getBody().getIssuedAt());
    }
}

@@ -1072,16 +1072,14 @@
 oid 
-shouldBe
+testIs
 Jwt(
@@ -1184,17 +1184,16 @@
 oid 
-should
+test
 Use
+s
 RS25
@@ -1303,29 +1303,28 @@
 ic void 
-should
+test
 Contain
+s
 X5t() %7B%0A
@@ -1423,37 +1423,36 @@
 public void 
-should
+test
 Contain
+s
 ValidIssuer(
@@ -1553,37 +1553,36 @@
 public void 
-should
+test
 Contain
+s
 ValidSubject
@@ -1689,29 +1689,28 @@
 ic void 
-should
+test
 Contain
+s
 ValidAud
@@ -1832,29 +1832,28 @@
 ic void 
-should
+test
 Contain
+s
 JwtId() 
@@ -1942,29 +1942,28 @@
 ic void 
-should
+test
 Contain
+s
 Expirati
@@ -2069,21 +2069,20 @@
 oid 
-should
+test
 Contain
+s
 Issu

Rename test methods