From 121ab60782e2728543ca2f455c656040cbd340a1 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Wed, 10 May 2023 16:39:14 +0200 Subject: feat(spring): add BasicAuth user object and new Interface to load users in multi-module projects --- .../springboot/test/utils/BasicAuthUserTest.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicAuthUserTest.java (limited to 'eaaf-springboot-utils/src/test/java') 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 new file mode 100644 index 00000000..95bd5dcb --- /dev/null +++ b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicAuthUserTest.java @@ -0,0 +1,41 @@ +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); + + } + +} -- cgit v1.2.3