summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src/test
diff options
context:
space:
mode:
authorThomas <>2024-08-29 09:52:25 +0200
committerThomas <>2024-08-29 09:52:25 +0200
commit61c0fbc5eb9d24267d4ca24cdebe4566e959bd02 (patch)
tree5eb5f8da91042bf1361f7527093b25b2352d4256 /eaaf_core_utils/src/test
parenta6b70202f08ca2d612bd8b33ad1f51ee0fc26333 (diff)
downloadEAAF-Components-61c0fbc5eb9d24267d4ca24cdebe4566e959bd02.tar.gz
EAAF-Components-61c0fbc5eb9d24267d4ca24cdebe4566e959bd02.tar.bz2
EAAF-Components-61c0fbc5eb9d24267d4ca24cdebe4566e959bd02.zip
feat(utils): add RFC7636 (Outh2 PKCE) implementation
Diffstat (limited to 'eaaf_core_utils/src/test')
-rw-r--r--eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/utils/Rfc7636UtilsTest.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/utils/Rfc7636UtilsTest.java b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/utils/Rfc7636UtilsTest.java
new file mode 100644
index 00000000..3bedf3d0
--- /dev/null
+++ b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/utils/Rfc7636UtilsTest.java
@@ -0,0 +1,68 @@
+package at.gv.egiz.eaaf.core.test.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.BlockJUnit4ClassRunner;
+
+import at.gv.egiz.eaaf.core.impl.utils.Rfc7636Utils;
+import at.gv.egiz.eaaf.core.impl.utils.Rfc7636Utils.Method;
+import at.gv.egiz.eaaf.core.impl.utils.Rfc7636Utils.PkceInfo;
+import lombok.SneakyThrows;
+
+@RunWith(BlockJUnit4ClassRunner.class)
+public class Rfc7636UtilsTest {
+
+ @Test
+ @SneakyThrows
+ public void generateS256() {
+ PkceInfo infos = Rfc7636Utils.getInstance().generate();
+ assertNotNull(infos);
+ assertEquals("S256", infos.getMethod());
+ assertEquals(Method.S256, infos.getCodeMethod());
+ assertNotNull(infos.getCodeChallenge());
+ assertNotNull(infos.getCodeVerifier());
+ assertTrue(Rfc7636Utils.getInstance().verify(infos));
+ }
+
+ @Test
+ @SneakyThrows
+ public void generatePlain() {
+ PkceInfo infos = Rfc7636Utils.getInstance().generate(Method.PLAIN);
+ assertNotNull(infos);
+ assertEquals("PLAIN", infos.getMethod());
+ assertEquals(Method.PLAIN, infos.getCodeMethod());
+ assertTrue(Rfc7636Utils.getInstance().verify(infos));
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void verifyInvalid() {
+ PkceInfo infos = PkceInfo.builder()
+ .codeMethod(Method.S256)
+ .codeVerifier(RandomStringUtils.randomAlphabetic(10))
+ .codeChallenge(RandomStringUtils.randomAlphabetic(10))
+ .build();
+ assertFalse(Rfc7636Utils.getInstance().verify(infos));
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void verifyRfc7636TestVector() {
+ PkceInfo infos = PkceInfo.builder()
+ .codeMethod(Method.S256)
+ .codeVerifier("dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk")
+ .codeChallenge("E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM")
+ .build();
+ assertTrue(Rfc7636Utils.getInstance().verify(infos));
+
+ }
+
+}