From 9d1af8708396ee2f48224dcf16f605f0f7247691 Mon Sep 17 00:00:00 2001
From: leeturner <lee@leeturner.me>
Date: Mon, 8 Apr 2024 15:25:05 +0100
Subject: [PATCH 1/2] Remove the mocklab references and replace with wiremock

---
 .../extension/jwt/JwtHandlebarsHelper.java      | 17 +++++++++--------
 .../extension/jwt/JwtHelperAcceptanceTest.java  | 16 ++++++++--------
 2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/wiremock/extension/jwt/JwtHandlebarsHelper.java b/src/main/java/org/wiremock/extension/jwt/JwtHandlebarsHelper.java
index 124a8fc..ddb251f 100644
--- a/src/main/java/org/wiremock/extension/jwt/JwtHandlebarsHelper.java
+++ b/src/main/java/org/wiremock/extension/jwt/JwtHandlebarsHelper.java
@@ -1,11 +1,5 @@
 package org.wiremock.extension.jwt;
 
-import com.auth0.jwt.JWT;
-import com.auth0.jwt.JWTCreator;
-import com.github.jknack.handlebars.Options;
-import com.github.tomakehurst.wiremock.extension.responsetemplating.helpers.HandlebarsHelper;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableSet;
 import java.time.Duration;
 import java.time.Instant;
 import java.time.temporal.ChronoUnit;
@@ -14,6 +8,13 @@
 import java.util.Optional;
 import java.util.Set;
 
+import com.auth0.jwt.JWT;
+import com.auth0.jwt.JWTCreator;
+import com.github.jknack.handlebars.Options;
+import com.github.tomakehurst.wiremock.extension.responsetemplating.helpers.HandlebarsHelper;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+
 public class JwtHandlebarsHelper extends HandlebarsHelper<Object> {
 
     private static final Set<String> RESERVED_PARAMETERS = ImmutableSet.of(
@@ -54,8 +55,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")) {
diff --git a/src/test/java/org/wiremock/extension/jwt/JwtHelperAcceptanceTest.java b/src/test/java/org/wiremock/extension/jwt/JwtHelperAcceptanceTest.java
index a476899..69e2fd2 100644
--- a/src/test/java/org/wiremock/extension/jwt/JwtHelperAcceptanceTest.java
+++ b/src/test/java/org/wiremock/extension/jwt/JwtHelperAcceptanceTest.java
@@ -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);
   }
@@ -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
@@ -143,16 +143,16 @@ 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();
@@ -160,7 +160,7 @@ void produces_a_JWT_with_custom_claims() {
     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")));
   }
 

From 1f73e08816bd64cb64a4437693494d170148b0fc Mon Sep 17 00:00:00 2001
From: leeturner <lee@leeturner.me>
Date: Mon, 8 Apr 2024 15:25:05 +0100
Subject: [PATCH 2/2] Remove the mocklab references and replace with wiremock

---
 .../extension/jwt/JwtHandlebarsHelper.java       |  4 ++--
 .../extension/jwt/JwtHelperAcceptanceTest.java   | 16 ++++++++--------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/wiremock/extension/jwt/JwtHandlebarsHelper.java b/src/main/java/org/wiremock/extension/jwt/JwtHandlebarsHelper.java
index 124a8fc..591855e 100644
--- a/src/main/java/org/wiremock/extension/jwt/JwtHandlebarsHelper.java
+++ b/src/main/java/org/wiremock/extension/jwt/JwtHandlebarsHelper.java
@@ -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")) {
diff --git a/src/test/java/org/wiremock/extension/jwt/JwtHelperAcceptanceTest.java b/src/test/java/org/wiremock/extension/jwt/JwtHelperAcceptanceTest.java
index a476899..69e2fd2 100644
--- a/src/test/java/org/wiremock/extension/jwt/JwtHelperAcceptanceTest.java
+++ b/src/test/java/org/wiremock/extension/jwt/JwtHelperAcceptanceTest.java
@@ -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);
   }
@@ -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
@@ -143,16 +143,16 @@ 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();
@@ -160,7 +160,7 @@ void produces_a_JWT_with_custom_claims() {
     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")));
   }