From 13da938658e0f799a7c89faadcfbbfee95a220d8 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Thu, 11 May 2023 12:34:27 +0200 Subject: feat(spring): add authorisation configuration for multi-modul projects --- .../springboot/test/utils/BasicAuthUserTest.java | 41 ----------------- .../test/utils/BasicSecurityConfigTest.java | 52 ++++++++++++++++++++++ 2 files changed, 52 insertions(+), 41 deletions(-) delete mode 100644 eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicAuthUserTest.java create mode 100644 eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicSecurityConfigTest.java (limited to 'eaaf-springboot-utils/src/test/java/at/gv/egiz') diff --git a/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicAuthUserTest.java b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicAuthUserTest.java deleted file mode 100644 index 95bd5dcb..00000000 --- a/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicAuthUserTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package at.gv.egiz.eaaf.utils.springboot.test.utils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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.utils.springboot.security.BasicAuthUser; - -@RunWith(BlockJUnit4ClassRunner.class) -public class BasicAuthUserTest { - - @Test - public void simpleTest() { - assertFalse("username", - BasicAuthUser.builder().password(rand()).role(rand()).build().isValid()); - assertFalse("password", - BasicAuthUser.builder().username(rand()).role(rand()).build().isValid()); - assertFalse("role", - BasicAuthUser.builder().password(rand()).username(rand()).build().isValid()); - - assertTrue("valid", - BasicAuthUser.builder().username(rand()).password(rand()).role(rand()).build().isValid()); - - assertEquals("role size", 2, - BasicAuthUser.builder().username(rand()).password(rand()) - .role(rand()).role(rand()).build() - .getRolesArray().length); - - } - - private String rand() { - return RandomStringUtils.randomAlphanumeric(5); - - } - -} diff --git a/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicSecurityConfigTest.java b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicSecurityConfigTest.java new file mode 100644 index 00000000..83117253 --- /dev/null +++ b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicSecurityConfigTest.java @@ -0,0 +1,52 @@ +package at.gv.egiz.eaaf.utils.springboot.test.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +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.utils.springboot.security.AuthorizationConfiguration; +import at.gv.egiz.eaaf.utils.springboot.security.BasicAuthUser; + +@RunWith(BlockJUnit4ClassRunner.class) +public class BasicSecurityConfigTest { + + @Test + public void userConfig() { + assertFalse("username", + BasicAuthUser.builder().password(rand()).role(rand()).build().isValid()); + assertFalse("password", + BasicAuthUser.builder().username(rand()).role(rand()).build().isValid()); + assertFalse("role", + BasicAuthUser.builder().password(rand()).username(rand()).build().isValid()); + + assertTrue("valid", + BasicAuthUser.builder().username(rand()).password(rand()).role(rand()).build().isValid()); + + assertEquals("role size", 2, + BasicAuthUser.builder().username(rand()).password(rand()) + .role(rand()).role(rand()).build() + .getRolesArray().length); + + } + + @Test + public void authoriseConfig() { + + assertEquals("endpoint size", 2, + AuthorizationConfiguration.builder().role(rand()) + .endpoint(rand()).endpoint(rand()).build() + .getEndPointsArray().length); + + } + + private String rand() { + return RandomStringUtils.randomAlphanumeric(5); + + } + +} -- cgit v1.2.3