-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14232 from sberyozkin/smallrye-jwt-sign-encrypt
Add JWT innerSign/encrypt test
- Loading branch information
Showing
12 changed files
with
101 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ye-jwt/deployment/src/test/java/io/quarkus/jwt/test/DefaultGroupsSignEncryptUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.quarkus.jwt.test; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
import io.smallrye.jwt.algorithm.KeyEncryptionAlgorithm; | ||
import io.smallrye.jwt.build.Jwt; | ||
|
||
public class DefaultGroupsSignEncryptUnitTest { | ||
private static Class<?>[] testClasses = { | ||
DefaultGroupsEndpoint.class, | ||
TokenUtils.class | ||
}; | ||
/** | ||
* The test generated JWT token string | ||
*/ | ||
private String token; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(testClasses) | ||
.addAsResource("publicKey.pem") | ||
.addAsResource("privateKey.pem") | ||
.addAsResource("applicationDefaultGroupsSignEncrypt.properties", "application.properties")); | ||
|
||
@BeforeEach | ||
public void generateToken() throws Exception { | ||
token = Jwt.issuer("https://server.example.com").innerSign() | ||
.keyAlgorithm(KeyEncryptionAlgorithm.RSA_OAEP) | ||
.encrypt(); | ||
} | ||
|
||
/** | ||
* Validate a request with MP-JWT without a 'groups' claim is successful | ||
* due to the default value being provided in the configuration | ||
* | ||
*/ | ||
@Test | ||
public void echoGroups() { | ||
RestAssured.given().auth() | ||
.oauth2(token) | ||
.get("/endp/echo") | ||
.then().assertThat().statusCode(200) | ||
.body(equalTo("User")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...smallrye-jwt/deployment/src/test/resources/applicationDefaultGroupsSignEncrypt.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
mp.jwt.verify.publickey.location=/publicKey.pem | ||
smallrye.jwt.decrypt.key.location=/privateKey.pem | ||
|
||
smallrye.jwt.sign.key-location=/privateKey.pem | ||
smallrye.jwt.encrypt.key-location=/publicKey.pem | ||
|
||
mp.jwt.verify.issuer=https://server.example.com | ||
smallrye.jwt.claims.groups=User | ||
|
||
quarkus.log.category."io.quarkus.smallrye.jwt.runtime.auth.MpJwtValidator".min-level=TRACE | ||
quarkus.log.category."io.quarkus.smallrye.jwt.runtime.auth.MpJwtValidator".level=TRACE |