Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mocklab references and replace with wiremock #1

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public Object apply(Object context, Options options) {
JWTCreator.Builder tokenBuilder = JWT.create()
.withExpiresAt(expiryDate)
.withIssuedAt(new Date())
.withIssuer(getOptionOrDefault(options, "iss", "mocklab"))
.withAudience(getOptionOrDefault(options, "aud", "mocklab.io"))
.withIssuer(getOptionOrDefault(options, "iss", "wiremock"))
.withAudience(getOptionOrDefault(options, "aud", "wiremock.io"))
.withSubject(getOptionOrDefault(options, "sub", "user-123"));

if (options.hash.containsKey("nbf")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ void init() {
void produces_default_jwt_with_100_year_lifetime_when_no_parameters_specified() {
DecodedJWT decodedJwt = verifyHs256AndDecodeForTemplate("{{jwt}}");

assertThat(decodedJwt.getIssuer(), is("mocklab"));
assertThat(decodedJwt.getAudience().get(0), is("mocklab.io"));
assertThat(decodedJwt.getIssuer(), is("wiremock"));
assertThat(decodedJwt.getAudience().get(0), is("wiremock.io"));
inLastFewSeconds(decodedJwt.getIssuedAt());
inTheFutureFrom(decodedJwt.getExpiresAt(), decodedJwt.getIssuedAt(), 36500, DAYS);
}
Expand Down Expand Up @@ -128,9 +128,9 @@ void produces_a_JWT_with_the_supplied_not_before_date() {
@Test
void produces_a_JWT_with_the_supplied_issuer() {
DecodedJWT decodedJwt =
verifyHs256AndDecodeForTemplate("{{jwt iss='https://jwt-example.mocklab.io/'}}");
verifyHs256AndDecodeForTemplate("{{jwt iss='https://jwt-example.wiremock.io/'}}");

assertThat(decodedJwt.getIssuer(), is("https://jwt-example.mocklab.io/"));
assertThat(decodedJwt.getIssuer(), is("https://jwt-example.wiremock.io/"));
}

@Test
Expand All @@ -143,24 +143,24 @@ void produces_a_JWT_with_the_supplied_subject() {
@Test
void produces_a_JWT_with_the_supplied_single_audience() {
DecodedJWT decodedJwt =
verifyHs256AndDecodeForTemplate("{{jwt aud='https://jwt-target.mocklab.io/'}}");
verifyHs256AndDecodeForTemplate("{{jwt aud='https://jwt-target.wiremock.io/'}}");

assertThat(decodedJwt.getAudience().get(0), is("https://jwt-target.mocklab.io/"));
assertThat(decodedJwt.getAudience().get(0), is("https://jwt-target.wiremock.io/"));
}

@Test
void produces_a_JWT_with_custom_claims() {
DecodedJWT decodedJwt =
verifyHs256AndDecodeForTemplate(
"{{jwt sub='superuser' isAdmin=true quota=23 score=0.96 email='superuser@example.mocklab.io' signupDate=(parseDate '2017-01-02T03:04:05Z')}}");
"{{jwt sub='superuser' isAdmin=true quota=23 score=0.96 email='superuser@example.wiremock.io' signupDate=(parseDate '2017-01-02T03:04:05Z')}}");

assertThat(decodedJwt.getSubject(), is("superuser"));
Map<String, Claim> claims = decodedJwt.getClaims();

assertThat(claims.get("isAdmin").asBoolean(), is(true));
assertThat(claims.get("quota").asInt(), is(23));
assertThat(claims.get("score").asDouble(), is(0.96));
assertThat(claims.get("email").asString(), is("superuser@example.mocklab.io"));
assertThat(claims.get("email").asString(), is("superuser@example.wiremock.io"));
assertThat(claims.get("signupDate").asDate(), is(Dates.parse("2017-01-02T03:04:05Z")));
}

Expand Down
Loading