RoleToken extends Token { public List<String> getRoles() { return roles; } private  RoleToken(Builder builder);  RoleToken(String signedToken); String getPrincipal(); List<String> getRoles(); String getProxyUser(); boolean getDomainCompleteRoleSet();  }
@Test public void testRoleTokenInvalidParamsAtEnd() throws CryptoException { List<String> roles = new ArrayList<>(); roles.add("reader"); roles.add("writer"); String testKeyVersionK1 = "1"; RoleToken rollTokenToSign = new RoleToken.Builder(rolVersion, svcDomain, roles) .salt(salt).expirationWindow(expirationTime).keyId(testKeyVersionK1).build(); rollTokenToSign.sign(ztsPrivateKeyStringK1); String signedToken = rollTokenToSign.getSignedToken() + ";d=newdomain;r=newroles"; RoleToken rollTokenToValidate = new RoleToken(signedToken); assertNotNull(rollTokenToValidate.getSignedToken()); assertEquals(rollTokenToValidate.getDomain(), svcDomain); List<String> rolesToValidate = rollTokenToValidate.getRoles(); assertEquals(rolesToValidate.size(), roles.size()); assertEquals(rolesToValidate, roles); assertEquals(rollTokenToValidate.getKeyId(), testKeyVersionK1); assertFalse(rollTokenToValidate.validate(ztsPublicKeyStringK1, 300, false)); }
@Test public void testTokenWithoutSignature() { RoleToken token = new RoleToken("v=S1;d=coretech;r=role1,role2"); assertEquals(token.getDomain(), "coretech"); assertNotNull(token.getRoles()); assertEquals(token.getVersion(), "S1"); assertNull(token.getUnsignedToken()); }
@Test public void testTokenWithExtraArgsAfterSignature() { RoleToken token = new RoleToken("v=Z1;d=coretech;r=role1,role2;s=signature;d=sports;r=api"); assertEquals(token.getDomain(), "coretech"); assertNotNull(token.getRoles()); assertEquals(token.getRoles().size(), 2); assertTrue(token.getRoles().contains("role1")); assertTrue(token.getRoles().contains("role2")); assertEquals(token.getVersion(), "Z1"); assertEquals(token.getSignature(), "signature;d=sports;r=api"); assertEquals(token.getUnsignedToken(), "v=Z1;d=coretech;r=role1,role2"); }
@Test public void testBuilderDefaultOptionalValues() { List<String> roles = new ArrayList<>(); roles.add("storage.tenant.weather.updater"); RoleToken token = new RoleToken.Builder(rolVersion, svcDomain, roles).build(); assertEquals(token.getVersion(), rolVersion); assertEquals(token.getDomain(), svcDomain); assertEquals(token.getRoles(), roles); assertNull(token.getHost()); assertNotNull(token.getSalt()); assertEquals(token.getKeyId(), "0"); assertNull(token.getIP()); long timestamp = token.getTimestamp(); assertTrue(timestamp != 0); assertEquals(token.getExpiryTime(), timestamp + 3600); }