Skip to content

Commit 3609623

Browse files
committed
add DPoPProofProvider test
1 parent 212b040 commit 3609623

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/test/java/org/example/action/HeaderValuesAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ public String get() {
4545
headers.putAll(httpRequest.getHeaders());
4646
return "success";
4747
}
48+
49+
public String post() {
50+
headers.putAll(httpRequest.getHeaders());
51+
return "success";
52+
}
4853
}

src/test/java/org/primeframework/mvc/GlobalTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.primeframework.mvc;
1717

18+
import javax.annotation.Nullable;
1819
import java.io.ByteArrayInputStream;
1920
import java.io.File;
2021
import java.io.IOException;
@@ -49,6 +50,7 @@
4950
import com.google.inject.Key;
5051
import com.google.inject.TypeLiteral;
5152
import freemarker.template.Configuration;
53+
import io.fusionauth.http.HTTPMethod;
5254
import io.fusionauth.http.HTTPValues.Headers;
5355
import io.fusionauth.http.HTTPValues.Methods;
5456
import org.example.action.JwtAuthorizedAction;
@@ -72,6 +74,7 @@
7274
import org.primeframework.mvc.security.CBCCipherProvider;
7375
import org.primeframework.mvc.security.DefaultEncryptor;
7476
import org.primeframework.mvc.security.Encryptor;
77+
import org.primeframework.mvc.test.DPoPProofProvider;
7578
import org.primeframework.mvc.util.URIBuilder;
7679
import org.testng.annotations.BeforeClass;
7780
import org.testng.annotations.DataProvider;
@@ -1554,6 +1557,26 @@ public void headers() throws IOException {
15541557
.assertJSONValuesAt("/foo", List.of("bar", "baz"));
15551558
}
15561559

1560+
@Test
1561+
public void dpopHeader() throws IOException {
1562+
// Make sure DPoPProofProvider gets invoked with proper values
1563+
// (a real DPoPProofProvider would generate a signed JWT)
1564+
DPoPProofProvider provider = (httpMethod, htu, accessToken) -> httpMethod.toString() + ":" + htu + ":" + accessToken;
1565+
1566+
simulator.test("/header-values")
1567+
.withDPoPProofProvider(provider)
1568+
.get()
1569+
.assertStatusCode(200)
1570+
.assertJSONValuesAt("/dpop", List.of("GET:http://localhost:9080/header-values:null"));
1571+
1572+
simulator.test("/header-values")
1573+
.withDPoPProofProvider(provider)
1574+
.withAuthorizationBearerToken("fake.token")
1575+
.post()
1576+
.assertStatusCode(200)
1577+
.assertJSONValuesAt("/dpop", List.of("POST:http://localhost:9080/header-values:fake.token"));
1578+
}
1579+
15571580
@Test
15581581
public void head() {
15591582
simulator.test("/head")

src/test/java/org/primeframework/mvc/test/DPoPProofProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
import io.fusionauth.http.HTTPMethod;
2121

22+
/**
23+
* Interface for generating DPoP Proofs. Allows one to plug in their
24+
* own DPoP Proof generation to HTTP requests in a test framework.
25+
*/
2226
public interface DPoPProofProvider {
2327
String generateDPoPProof(HTTPMethod httpMethod, String htu, @Nullable String accessToken);
2428
}

src/test/java/org/primeframework/mvc/test/RequestBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public RequestBuilder withCookie(String name, String value) throws Exception {
503503
return withCookie(name, value, false, false);
504504
}
505505

506-
public RequestBuilder withDPoPProofProvider(DPoPProofProvider dPoPProofProvider) throws Exception {
506+
public RequestBuilder withDPoPProofProvider(DPoPProofProvider dPoPProofProvider) {
507507
this.dPoPProofProvider = dPoPProofProvider;
508508
return this;
509509
}

0 commit comments

Comments
 (0)