40
40
41
41
import org .eclipse .microprofile .jwt .config .Names ;
42
42
import org .eclipse .microprofile .jwt .tck .TCKConstants ;
43
- import org .eclipse .microprofile .jwt .tck .util .MpJwtTestVersion ;
44
43
import org .eclipse .microprofile .jwt .tck .util .TokenUtils ;
45
44
import org .jboss .arquillian .container .test .api .Deployment ;
45
+ import org .jboss .arquillian .container .test .api .OperateOnDeployment ;
46
46
import org .jboss .arquillian .container .test .api .RunAsClient ;
47
47
import org .jboss .arquillian .test .api .ArquillianResource ;
48
48
import org .jboss .arquillian .testng .Arquillian ;
@@ -68,33 +68,43 @@ public class PublicKeyAsPEMLocationURLTest extends Arquillian {
68
68
@ ArquillianResource
69
69
private URL baseURL ;
70
70
71
+ @ Deployment (name = "keyEndpoint" , order = 1 )
72
+ public static WebArchive createKeyEndpoint () throws Exception {
73
+ URL publicKey = PublicKeyAsPEMLocationURLTest .class .getResource ("/publicKey4k.pem" );
74
+
75
+ final WebArchive webArchive = ShrinkWrap
76
+ .create (WebArchive .class , "KeyEndpoint.war" )
77
+ .addAsResource (publicKey , "/publicKey4k.pem" )
78
+ .addAsResource (publicKey , "/publicKey.pem" )
79
+ .addClass (PublicKeyEndpoint .class )
80
+ .addClass (KeyApplication .class )
81
+ .addClass (SimpleTokenUtils .class )
82
+ .addAsWebInfResource ("beans.xml" , "beans.xml" );
83
+ return webArchive ;
84
+ }
85
+
71
86
/**
72
87
* Create a CDI aware base web application archive that includes an embedded JWK public key that
73
88
* is referenced via the mp.jwt.verify.publickey.location as a URL resource property.
74
89
* The root url is /pem
90
+ *
75
91
* @return the base base web application archive
76
92
* @throws IOException - on resource failure
77
93
*/
78
- @ Deployment ()
94
+ @ Deployment (name = "testApp" , order = 2 )
79
95
public static WebArchive createLocationURLDeployment () throws IOException {
80
96
URL publicKey = PublicKeyAsPEMLocationURLTest .class .getResource ("/publicKey4k.pem" );
81
97
// Setup the microprofile-config.properties content
82
98
Properties configProps = new Properties ();
83
- // Read in the base URL of deployment since it cannot be injected for use by this method
84
- String jwksBaseURL = System .getProperty ("mp.jwt.tck.jwks.baseURL" , "http://localhost:8080/" );
85
- // Location points to the PEM endpoint of the deployment
86
- System .out .printf ("baseURL=%s\n " , jwksBaseURL );
87
- URL pemURL = new URL (new URL (jwksBaseURL ), "pem/endp/publicKey4k" );
88
- System .out .printf ("pemURL=%s\n " , pemURL );
89
- configProps .setProperty (Names .VERIFIER_PUBLIC_KEY_LOCATION , pemURL .toExternalForm ());
99
+ // Location points to an endpoint that returns a PEM key
100
+ configProps .setProperty (Names .VERIFIER_PUBLIC_KEY_LOCATION , "http://localhost:8080/key/endp/publicKey4k" );
90
101
configProps .setProperty (Names .ISSUER , TCKConstants .TEST_ISSUER );
91
102
StringWriter configSW = new StringWriter ();
92
103
configProps .store (configSW , "PublicKeyAsPEMLocationURLTest microprofile-config.properties" );
93
104
StringAsset configAsset = new StringAsset (configSW .toString ());
94
105
95
106
WebArchive webArchive = ShrinkWrap
96
107
.create (WebArchive .class , "PublicKeyAsPEMLocationURLTest.war" )
97
- .addAsManifestResource (new StringAsset (MpJwtTestVersion .MPJWT_V_1_1 .name ()), MpJwtTestVersion .MANIFEST_NAME )
98
108
.addAsResource (publicKey , "/publicKey4k.pem" )
99
109
.addAsResource (publicKey , "/publicKey.pem" )
100
110
.addClass (PublicKeyEndpoint .class )
@@ -103,13 +113,13 @@ public static WebArchive createLocationURLDeployment() throws IOException {
103
113
.addAsWebInfResource ("beans.xml" , "beans.xml" )
104
114
.addAsManifestResource (configAsset , "microprofile-config.properties" )
105
115
;
106
- System .out .printf ("WebArchive: %s\n " , webArchive .toString (true ));
107
116
return webArchive ;
108
117
}
109
118
110
119
@ RunAsClient ()
120
+ @ OperateOnDeployment ("testApp" )
111
121
@ Test (groups = TEST_GROUP_CONFIG ,
112
- description = "Validate the http://localhost:8080/pem/endp/publicKey4k PEM endpoint" )
122
+ description = "Validate the http://localhost:8080/pem/endp/publicKey4k PEM endpoint" )
113
123
public void validateLocationUrlContents () throws Exception {
114
124
URL locationURL = new URL (baseURL , "pem/endp/publicKey4k" );
115
125
Reporter .log ("Begin validateLocationUrlContents" );
@@ -129,8 +139,9 @@ public void validateLocationUrlContents() throws Exception {
129
139
}
130
140
131
141
@ RunAsClient
142
+ @ OperateOnDeployment ("testApp" )
132
143
@ Test (groups = TEST_GROUP_CONFIG , dependsOnMethods = { "validateLocationUrlContents" },
133
- description = "Validate specifying the mp.jwt.verify.publickey.location as remote URL to a PEM key" )
144
+ description = "Validate specifying the mp.jwt.verify.publickey.location as remote URL to a PEM key" )
134
145
public void testKeyAsLocationUrl () throws Exception {
135
146
Reporter .log ("testKeyAsLocationUrl, expect HTTP_OK" );
136
147
@@ -141,9 +152,9 @@ public void testKeyAsLocationUrl() throws Exception {
141
152
142
153
String uri = baseURL .toExternalForm () + "pem/endp/verifyKeyLocationAsPEMUrl" ;
143
154
WebTarget echoEndpointTarget = ClientBuilder .newClient ()
144
- .target (uri )
155
+ .target (uri )
145
156
;
146
- Response response = echoEndpointTarget .request (APPLICATION_JSON ).header (HttpHeaders .AUTHORIZATION , "Bearer " + token ).get ();
157
+ Response response = echoEndpointTarget .request (APPLICATION_JSON ).header (HttpHeaders .AUTHORIZATION , "Bearer " + token ).get ();
147
158
Assert .assertEquals (response .getStatus (), HttpURLConnection .HTTP_OK );
148
159
String replyString = response .readEntity (String .class );
149
160
JsonReader jsonReader = Json .createReader (new StringReader (replyString ));
0 commit comments