Added test
This commit is contained in:
parent
4766ad2f80
commit
3ec9670319
|
@ -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<String> roles = auth.getRoles();
|
||||
logger.debug("{} All roles are {}", context, roles);
|
||||
Assert.assertTrue(roles.contains(SystemEnvironment.IS_MANAGER));
|
||||
Collection<String> contextRoles = auth.getContextRoles();
|
||||
logger.debug("{} Context roles are {}", context, contextRoles);
|
||||
Collection<String> 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));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue