コード例 #1
0
ファイル: MacSignerTest.java プロジェクト: RootServices/jwt
  /**
   * Test scenario taken from, https://tools.ietf.org/html/rfc7515#appendix-A.1
   *
   * <p>There is a modification in which the sign input does not contain \r\n Which is why the
   * signature is different than the rfc.
   */
  @Test
  public void shouldSignBytesCorrectly() {
    String input =
        "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9."
            + "eyJpc3MiOiJqb2UiLCJleHAiOjEzMDA4MTkzODAsImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ";

    String actual = subject.run(input.getBytes());

    assertThat(actual, is("lliDzOlRAdGUCfCHCPx_uisb6ZfZ1LRQa0OJLeYTTpY"));
  }
コード例 #2
0
ファイル: MacSignerTest.java プロジェクト: RootServices/jwt
  /**
   * Test scenario taken from, https://tools.ietf.org/html/rfc7515#appendix-A.1
   *
   * <p>There is a modification in which the sign input does not contain \r\n Which is why the
   * signature is different than the rfc.
   */
  @Test
  public void shouldSignJwtCorrectly() throws JwtToJsonException {

    // header
    Header header = new Header();
    header.setAlgorithm(Algorithm.HS256);
    header.setType(Optional.of(TokenType.JWT));

    // claim of the jwt.
    Claim claim = new Claim();
    Optional<String> issuer = Optional.of("joe");
    Optional<Long> expirationTime = Optional.of(1300819380L);
    claim.setUriIsRoot(true);
    claim.setIssuer(issuer);
    claim.setExpirationTime(expirationTime);

    JsonWebToken jwt = new JsonWebToken(header, claim);

    String actual = subject.run(jwt);
    assertThat(actual, is("lliDzOlRAdGUCfCHCPx_uisb6ZfZ1LRQa0OJLeYTTpY"));
  }