|
|
|
package com.railinc.sso.zuul.legacy; |
|
|
|
// imports removed |
|
|
|
@RunWith(PowerMockRunner.class) |
|
@SuppressStaticInitializationFor("com.netegrity.policyserver.smapi.ActiveExpressionContext") |
|
public class GetAccessCookieActiveExpressionTest { |
|
|
|
public ActiveExpressionContext build_nice_ae_context(UserContext uc, APIContext ac) { |
|
ActiveExpressionContext c = createNiceMock(ActiveExpressionContext.class); |
|
expect(c.getUserContext()).andReturn(uc); |
|
expect(c.getAPIContext()).andReturn(ac); |
|
return c; |
|
} |
|
|
|
public APIContext build_quiet_api_context() { |
|
return createNiceMock(APIContext.class); |
|
} |
|
|
|
public UserContext build_happy_user_context_fixture() { |
|
UserContext c = createNiceMock(UserContext.class); |
|
return c; |
|
} |
|
|
|
@Test |
|
public void test_happy() throws Exception { |
|
// create fixtures |
|
UserContext userContext = build_happy_user_context_fixture(); |
|
APIContext apiContext = build_quiet_api_context(); |
|
ActiveExpressionContext context = build_nice_ae_context(userContext, apiContext); |
|
|
|
expect(userContext.getProp("givenName")).andReturn("yyy"); |
|
expect(userContext.getProp("sn")).andReturn("zzz"); |
|
expect(userContext.getProp("uid")).andReturn("XXXXXX"); |
|
expect(userContext.getProp("mail")).andReturn("[email protected]"); |
|
|
|
// replay and run test |
|
replay(userContext, apiContext, context); |
|
GetAccessCookieActiveExpression e = new GetAccessCookieActiveExpression(); |
|
e.init(apiContext); |
|
String value = e.invoke(context, null); |
|
value = new String(Base64.decodeBase64(value.getBytes())); |
|
e.release(apiContext); |
|
|
|
assertNotNull(value); |
|
assertTrue("Should have my user id in the token", value.contains("XXXXXX")); |
|
assertTrue("Should have my firstname in the token", value.contains("yyy")); |
|
assertTrue("Should have my last name in the token", value.contains("zzz")); |
|
assertTrue("Should have my escaped email in the token", value.contains("xxx@xxx\\.com")); |
|
} |