From d55ada21c2042658d79f3648d082f4aaccc69015 Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Wed, 14 Apr 2021 13:45:02 -0300 Subject: [PATCH] Removed classes that already exist in quarkus-security-test-utils --- .../io/quarkus/security/test/AuthData.java | 18 ---- .../quarkus/security/test/IdentityMock.java | 92 ------------------- .../security/test/SecurityTestUtils.java | 32 ------- .../test/cdi/CDIAccessDefaultTest.java | 16 ++-- .../SecurityAnnotationOnFinalMethodTest.java | 16 ++-- ...inalMethodWithDisableFinalRemovalTest.java | 6 +- 6 files changed, 19 insertions(+), 161 deletions(-) delete mode 100644 extensions/security/deployment/src/test/java/io/quarkus/security/test/AuthData.java delete mode 100644 extensions/security/deployment/src/test/java/io/quarkus/security/test/IdentityMock.java delete mode 100644 extensions/security/deployment/src/test/java/io/quarkus/security/test/SecurityTestUtils.java diff --git a/extensions/security/deployment/src/test/java/io/quarkus/security/test/AuthData.java b/extensions/security/deployment/src/test/java/io/quarkus/security/test/AuthData.java deleted file mode 100644 index 80c897c725a1c..0000000000000 --- a/extensions/security/deployment/src/test/java/io/quarkus/security/test/AuthData.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.quarkus.security.test; - -import java.util.Set; - -/** - * @author Michal Szynkiewicz, michal.l.szynkiewicz@gmail.com - */ -public class AuthData { - public final Set roles; - public final boolean anonymous; - public final String name; - - public AuthData(Set roles, boolean anonymous, String name) { - this.roles = roles; - this.anonymous = anonymous; - this.name = name; - } -} diff --git a/extensions/security/deployment/src/test/java/io/quarkus/security/test/IdentityMock.java b/extensions/security/deployment/src/test/java/io/quarkus/security/test/IdentityMock.java deleted file mode 100644 index 5a7ab362685f3..0000000000000 --- a/extensions/security/deployment/src/test/java/io/quarkus/security/test/IdentityMock.java +++ /dev/null @@ -1,92 +0,0 @@ -package io.quarkus.security.test; - -import java.security.Permission; -import java.security.Principal; -import java.util.Collections; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Priority; -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.inject.Alternative; - -import io.quarkus.security.credential.Credential; -import io.quarkus.security.identity.SecurityIdentity; -import io.smallrye.mutiny.Uni; - -/** - * @author Michal Szynkiewicz, michal.l.szynkiewicz@gmail.com - */ -@Alternative -@ApplicationScoped -@Priority(1) -public class IdentityMock implements SecurityIdentity { - - public static final AuthData ANONYMOUS = new AuthData(null, true, null); - public static final AuthData USER = new AuthData(Collections.singleton("user"), false, "user"); - public static final AuthData ADMIN = new AuthData(Collections.singleton("admin"), false, "admin"); - - private static volatile boolean anonymous; - private static volatile Set roles; - private static volatile String name; - - public static void setUpAuth(AuthData auth) { - IdentityMock.anonymous = auth.anonymous; - IdentityMock.roles = auth.roles; - IdentityMock.name = auth.name; - } - - @Override - public Principal getPrincipal() { - return new Principal() { - @Override - public String getName() { - return name; - } - }; - } - - @Override - public boolean hasRole(String role) { - if (roles == null) { - return false; - } - return getRoles().contains(role); - } - - @Override - public boolean isAnonymous() { - return anonymous; - } - - @Override - public Set getRoles() { - return roles; - } - - @Override - public T getCredential(Class aClass) { - return null; - } - - @Override - public Set getCredentials() { - return null; - } - - @Override - public T getAttribute(String s) { - return null; - } - - @Override - public Map getAttributes() { - return null; - } - - @Override - public Uni checkPermission(Permission permission) { - return null; - } - -} diff --git a/extensions/security/deployment/src/test/java/io/quarkus/security/test/SecurityTestUtils.java b/extensions/security/deployment/src/test/java/io/quarkus/security/test/SecurityTestUtils.java deleted file mode 100644 index cfbd683f702de..0000000000000 --- a/extensions/security/deployment/src/test/java/io/quarkus/security/test/SecurityTestUtils.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.quarkus.security.test; - -import static io.quarkus.security.test.IdentityMock.setUpAuth; - -import java.util.function.Supplier; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.function.Executable; - -/** - * @author Michal Szynkiewicz, michal.l.szynkiewicz@gmail.com - */ -public class SecurityTestUtils { - public static void assertSuccess(Supplier action, T expectedResult, AuthData... auth) { - for (AuthData authData : auth) { - setUpAuth(authData); - Assertions.assertEquals(action.get(), expectedResult); - } - - } - - public static void assertFailureFor(Executable action, Class expectedException, - AuthData... auth) { - for (AuthData authData : auth) { - setUpAuth(authData); - Assertions.assertThrows(expectedException, action); - } - } - - private SecurityTestUtils() { - } -} diff --git a/extensions/security/deployment/src/test/java/io/quarkus/security/test/cdi/CDIAccessDefaultTest.java b/extensions/security/deployment/src/test/java/io/quarkus/security/test/cdi/CDIAccessDefaultTest.java index 4d222bb1efa78..60e9a2eb51612 100644 --- a/extensions/security/deployment/src/test/java/io/quarkus/security/test/cdi/CDIAccessDefaultTest.java +++ b/extensions/security/deployment/src/test/java/io/quarkus/security/test/cdi/CDIAccessDefaultTest.java @@ -1,10 +1,10 @@ package io.quarkus.security.test.cdi; -import static io.quarkus.security.test.IdentityMock.ADMIN; -import static io.quarkus.security.test.IdentityMock.ANONYMOUS; -import static io.quarkus.security.test.IdentityMock.USER; -import static io.quarkus.security.test.SecurityTestUtils.assertFailureFor; -import static io.quarkus.security.test.SecurityTestUtils.assertSuccess; +import static io.quarkus.security.test.utils.IdentityMock.ADMIN; +import static io.quarkus.security.test.utils.IdentityMock.ANONYMOUS; +import static io.quarkus.security.test.utils.IdentityMock.USER; +import static io.quarkus.security.test.utils.SecurityTestUtils.assertFailureFor; +import static io.quarkus.security.test.utils.SecurityTestUtils.assertSuccess; import javax.inject.Inject; import javax.inject.Named; @@ -16,13 +16,13 @@ import io.quarkus.security.ForbiddenException; import io.quarkus.security.UnauthorizedException; -import io.quarkus.security.test.AuthData; -import io.quarkus.security.test.IdentityMock; -import io.quarkus.security.test.SecurityTestUtils; import io.quarkus.security.test.cdi.app.BeanWithSecuredMethods; import io.quarkus.security.test.cdi.app.SubclassWithDenyAll; import io.quarkus.security.test.cdi.app.SubclassWithPermitAll; import io.quarkus.security.test.cdi.app.SubclassWithoutAnnotations; +import io.quarkus.security.test.utils.AuthData; +import io.quarkus.security.test.utils.IdentityMock; +import io.quarkus.security.test.utils.SecurityTestUtils; import io.quarkus.test.QuarkusUnitTest; /** diff --git a/extensions/security/deployment/src/test/java/io/quarkus/security/test/cdi/SecurityAnnotationOnFinalMethodTest.java b/extensions/security/deployment/src/test/java/io/quarkus/security/test/cdi/SecurityAnnotationOnFinalMethodTest.java index d4fe7bbad4c2c..b6fd0fb794fa2 100644 --- a/extensions/security/deployment/src/test/java/io/quarkus/security/test/cdi/SecurityAnnotationOnFinalMethodTest.java +++ b/extensions/security/deployment/src/test/java/io/quarkus/security/test/cdi/SecurityAnnotationOnFinalMethodTest.java @@ -1,10 +1,10 @@ package io.quarkus.security.test.cdi; -import static io.quarkus.security.test.IdentityMock.ADMIN; -import static io.quarkus.security.test.IdentityMock.ANONYMOUS; -import static io.quarkus.security.test.IdentityMock.USER; -import static io.quarkus.security.test.SecurityTestUtils.assertFailureFor; -import static io.quarkus.security.test.SecurityTestUtils.assertSuccess; +import static io.quarkus.security.test.utils.IdentityMock.ADMIN; +import static io.quarkus.security.test.utils.IdentityMock.ANONYMOUS; +import static io.quarkus.security.test.utils.IdentityMock.USER; +import static io.quarkus.security.test.utils.SecurityTestUtils.assertFailureFor; +import static io.quarkus.security.test.utils.SecurityTestUtils.assertSuccess; import javax.inject.Inject; @@ -15,9 +15,9 @@ import io.quarkus.security.ForbiddenException; import io.quarkus.security.UnauthorizedException; -import io.quarkus.security.test.AuthData; -import io.quarkus.security.test.IdentityMock; -import io.quarkus.security.test.SecurityTestUtils; +import io.quarkus.security.test.utils.AuthData; +import io.quarkus.security.test.utils.IdentityMock; +import io.quarkus.security.test.utils.SecurityTestUtils; import io.quarkus.test.QuarkusUnitTest; public class SecurityAnnotationOnFinalMethodTest { diff --git a/extensions/security/deployment/src/test/java/io/quarkus/security/test/cdi/SecurityAnnotationOnFinalMethodWithDisableFinalRemovalTest.java b/extensions/security/deployment/src/test/java/io/quarkus/security/test/cdi/SecurityAnnotationOnFinalMethodWithDisableFinalRemovalTest.java index 8d1fbd4d2110b..20261cf62c265 100644 --- a/extensions/security/deployment/src/test/java/io/quarkus/security/test/cdi/SecurityAnnotationOnFinalMethodWithDisableFinalRemovalTest.java +++ b/extensions/security/deployment/src/test/java/io/quarkus/security/test/cdi/SecurityAnnotationOnFinalMethodWithDisableFinalRemovalTest.java @@ -11,9 +11,9 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import io.quarkus.security.test.AuthData; -import io.quarkus.security.test.IdentityMock; -import io.quarkus.security.test.SecurityTestUtils; +import io.quarkus.security.test.utils.AuthData; +import io.quarkus.security.test.utils.IdentityMock; +import io.quarkus.security.test.utils.SecurityTestUtils; import io.quarkus.test.QuarkusUnitTest; public class SecurityAnnotationOnFinalMethodWithDisableFinalRemovalTest {