From 3ec9670319e4f2bdc155a1a8f109194db9578d80 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 28 Oct 2024 15:46:00 +0100 Subject: [PATCH] Added test --- .../resourceregistry/TestTokenRoles.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/test/java/org/gcube/informationsystem/resourceregistry/TestTokenRoles.java diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/TestTokenRoles.java b/src/test/java/org/gcube/informationsystem/resourceregistry/TestTokenRoles.java new file mode 100644 index 0000000..74b637d --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/TestTokenRoles.java @@ -0,0 +1,40 @@ +package org.gcube.informationsystem.resourceregistry; + +import java.util.Collection; + +import org.gcube.common.iam.OIDCBearerAuth; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +public class TestTokenRoles extends ContextTest { + + private static final Logger logger = LoggerFactory.getLogger(ContextTest.class); + + @Ignore + @Test + public void testRoles() throws Exception { + String[] contexts = new String[] {GCUBE, DEVSEC, DEVVRE, DEVNEXT, NEXTNEXT}; + for(String context : contexts){ + String accessToken = getJWTAccessToken(context); + OIDCBearerAuth auth = OIDCBearerAuth.fromAccessTokenString(accessToken); + Collection roles = auth.getRoles(); + logger.debug("{} All roles are {}", context, roles); + Assert.assertTrue(roles.contains(SystemEnvironment.IS_MANAGER)); + Collection contextRoles = auth.getContextRoles(); + logger.debug("{} Context roles are {}", context, contextRoles); + Collection globalRoles = auth.getGlobalRoles(); + logger.debug("{} Global roles are {}", context, globalRoles); + Assert.assertTrue(globalRoles.contains(SystemEnvironment.IS_MANAGER)); + Assert.assertTrue(roles.size()==(contextRoles.size() + globalRoles.size())); + Assert.assertTrue(roles.containsAll(contextRoles)); + Assert.assertTrue(roles.containsAll(globalRoles)); + } + } +}