Skip to content

Commit 7f6973a

Browse files
committed
Fix for microprofile#118. Provide separate deployment to retrieve a key from a URL.
Signed-off-by: Roberto Cortez <[email protected]>
1 parent f8dafe0 commit 7f6973a

File tree

3 files changed

+76
-17
lines changed

3 files changed

+76
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* You may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
package org.eclipse.microprofile.jwt.tck.config;
21+
22+
import org.eclipse.microprofile.auth.LoginConfig;
23+
24+
import javax.ws.rs.ApplicationPath;
25+
import javax.ws.rs.core.Application;
26+
27+
@LoginConfig(authMethod = "MP-JWT", realmName = "TCK-MP-JWT")
28+
@ApplicationPath("/key")
29+
public class KeyApplication extends Application {
30+
}

tck/src/test/java/org/eclipse/microprofile/jwt/tck/config/PublicKeyAsJWKLocationURLTest.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.eclipse.microprofile.jwt.tck.util.MpJwtTestVersion;
4545
import org.eclipse.microprofile.jwt.tck.util.TokenUtils;
4646
import org.jboss.arquillian.container.test.api.Deployment;
47+
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
4748
import org.jboss.arquillian.container.test.api.RunAsClient;
4849
import org.jboss.arquillian.test.api.ArquillianResource;
4950
import org.jboss.arquillian.testng.Arquillian;
@@ -69,14 +70,29 @@ public class PublicKeyAsJWKLocationURLTest extends Arquillian {
6970
@ArquillianResource
7071
private URL baseURL;
7172

73+
@Deployment(name = "keyEndpoint", order = 1)
74+
public static WebArchive createKeyEndpoint() throws Exception {
75+
URL publicKey = PublicKeyAsPEMLocationURLTest.class.getResource("/publicKey4k.pem");
76+
77+
final WebArchive webArchive = ShrinkWrap
78+
.create(WebArchive.class, "KeyEndpoint.war")
79+
.addAsResource(publicKey, "/publicKey4k.pem")
80+
.addAsResource(publicKey, "/publicKey.pem")
81+
.addClass(PublicKeyEndpoint.class)
82+
.addClass(KeyApplication.class)
83+
.addClass(SimpleTokenUtils.class)
84+
.addAsWebInfResource("beans.xml", "beans.xml");
85+
return webArchive;
86+
}
87+
7288
/**
7389
* Create a CDI aware base web application archive that includes a JWKS endpoint that
7490
* is referenced via the mp.jwt.verify.publickey.location as a URL resource property.
7591
* The root url is /jwks
7692
* @return the base base web application archive
7793
* @throws IOException - on resource failure
7894
*/
79-
@Deployment()
95+
@Deployment(name = "testApp", order = 2)
8096
public static WebArchive createLocationURLDeployment() throws IOException {
8197
URL publicKey = PublicKeyAsJWKLocationURLTest.class.getResource("/publicKey4k.pem");
8298
// Setup the microprofile-config.properties content
@@ -85,7 +101,7 @@ public static WebArchive createLocationURLDeployment() throws IOException {
85101
String jwksBaseURL = System.getProperty("mp.jwt.tck.jwks.baseURL", "http://localhost:8080/");
86102
// Location points to the JWKS endpoint of the deployment
87103
System.out.printf("baseURL=%s\n", jwksBaseURL);
88-
URL jwksURL = new URL(new URL(jwksBaseURL), "jwks/endp/publicKey4kAsJWKS?kid=publicKey4k");
104+
URL jwksURL = new URL(new URL(jwksBaseURL), "key/endp/publicKey4kAsJWKS?kid=publicKey4k");
89105
System.out.printf("jwksURL=%s\n", jwksURL);
90106
configProps.setProperty(Names.VERIFIER_PUBLIC_KEY_LOCATION, jwksURL.toExternalForm());
91107
configProps.setProperty(Names.ISSUER, TCKConstants.TEST_ISSUER);
@@ -108,6 +124,7 @@ public static WebArchive createLocationURLDeployment() throws IOException {
108124
}
109125

110126
@RunAsClient()
127+
@OperateOnDeployment("testApp")
111128
@Test(groups = TEST_GROUP_CONFIG,
112129
description = "Validate the http://localhost:8080/jwks/endp/publicKey4kAsJWKS JWKS endpoint")
113130
public void validateLocationUrlContents() throws Exception {
@@ -137,6 +154,7 @@ public void validateLocationUrlContents() throws Exception {
137154
}
138155

139156
@RunAsClient
157+
@OperateOnDeployment("testApp")
140158
@Test(groups = TEST_GROUP_CONFIG, dependsOnMethods = { "validateLocationUrlContents" },
141159
description = "Validate specifying the mp.jwt.verify.publickey.location as remote URL to a JWKS key")
142160
public void testKeyAsLocationUrl() throws Exception {

tck/src/test/java/org/eclipse/microprofile/jwt/tck/config/PublicKeyAsPEMLocationURLTest.java

+26-15
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040

4141
import org.eclipse.microprofile.jwt.config.Names;
4242
import org.eclipse.microprofile.jwt.tck.TCKConstants;
43-
import org.eclipse.microprofile.jwt.tck.util.MpJwtTestVersion;
4443
import org.eclipse.microprofile.jwt.tck.util.TokenUtils;
4544
import org.jboss.arquillian.container.test.api.Deployment;
45+
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
4646
import org.jboss.arquillian.container.test.api.RunAsClient;
4747
import org.jboss.arquillian.test.api.ArquillianResource;
4848
import org.jboss.arquillian.testng.Arquillian;
@@ -68,33 +68,43 @@ public class PublicKeyAsPEMLocationURLTest extends Arquillian {
6868
@ArquillianResource
6969
private URL baseURL;
7070

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+
7186
/**
7287
* Create a CDI aware base web application archive that includes an embedded JWK public key that
7388
* is referenced via the mp.jwt.verify.publickey.location as a URL resource property.
7489
* The root url is /pem
90+
*
7591
* @return the base base web application archive
7692
* @throws IOException - on resource failure
7793
*/
78-
@Deployment()
94+
@Deployment(name = "testApp", order = 2)
7995
public static WebArchive createLocationURLDeployment() throws IOException {
8096
URL publicKey = PublicKeyAsPEMLocationURLTest.class.getResource("/publicKey4k.pem");
8197
// Setup the microprofile-config.properties content
8298
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");
90101
configProps.setProperty(Names.ISSUER, TCKConstants.TEST_ISSUER);
91102
StringWriter configSW = new StringWriter();
92103
configProps.store(configSW, "PublicKeyAsPEMLocationURLTest microprofile-config.properties");
93104
StringAsset configAsset = new StringAsset(configSW.toString());
94105

95106
WebArchive webArchive = ShrinkWrap
96107
.create(WebArchive.class, "PublicKeyAsPEMLocationURLTest.war")
97-
.addAsManifestResource(new StringAsset(MpJwtTestVersion.MPJWT_V_1_1.name()), MpJwtTestVersion.MANIFEST_NAME)
98108
.addAsResource(publicKey, "/publicKey4k.pem")
99109
.addAsResource(publicKey, "/publicKey.pem")
100110
.addClass(PublicKeyEndpoint.class)
@@ -103,13 +113,13 @@ public static WebArchive createLocationURLDeployment() throws IOException {
103113
.addAsWebInfResource("beans.xml", "beans.xml")
104114
.addAsManifestResource(configAsset, "microprofile-config.properties")
105115
;
106-
System.out.printf("WebArchive: %s\n", webArchive.toString(true));
107116
return webArchive;
108117
}
109118

110119
@RunAsClient()
120+
@OperateOnDeployment("testApp")
111121
@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")
113123
public void validateLocationUrlContents() throws Exception {
114124
URL locationURL = new URL(baseURL, "pem/endp/publicKey4k");
115125
Reporter.log("Begin validateLocationUrlContents");
@@ -129,8 +139,9 @@ public void validateLocationUrlContents() throws Exception {
129139
}
130140

131141
@RunAsClient
142+
@OperateOnDeployment("testApp")
132143
@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")
134145
public void testKeyAsLocationUrl() throws Exception {
135146
Reporter.log("testKeyAsLocationUrl, expect HTTP_OK");
136147

@@ -141,9 +152,9 @@ public void testKeyAsLocationUrl() throws Exception {
141152

142153
String uri = baseURL.toExternalForm() + "pem/endp/verifyKeyLocationAsPEMUrl";
143154
WebTarget echoEndpointTarget = ClientBuilder.newClient()
144-
.target(uri)
155+
.target(uri)
145156
;
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();
147158
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
148159
String replyString = response.readEntity(String.class);
149160
JsonReader jsonReader = Json.createReader(new StringReader(replyString));

0 commit comments

Comments
 (0)