public static SecurityToken getSecurityToken(String owner, String viewer, String gadget) throws Exception { return new BasicSecurityToken(owner, viewer, "app", "container.com", gadget, "0", "default", GADGET_MAKE_REQUEST_URL, null); }
public static SecurityToken getSecurityToken(String owner, String viewer, String gadget) throws Exception { return new BasicSecurityToken(owner, viewer, "app", "container.com", gadget, "0", "default", GADGET_MAKE_REQUEST_URL, null); }
public static SecurityToken getSecurityToken(String owner, String viewer, String gadget) throws Exception { return new BasicSecurityToken(owner, viewer, "app", "container.com", gadget, "0", "default", GADGET_MAKE_REQUEST_URL, null); }
return new BasicSecurityToken( Utf8UrlCoder.decode(tokens[OWNER_INDEX]), Utf8UrlCoder.decode(tokens[VIEWER_INDEX]),
return new BasicSecurityToken( Utf8UrlCoder.decode(tokens[OWNER_INDEX]), Utf8UrlCoder.decode(tokens[VIEWER_INDEX]),
@Before public void setup() throws Exception { expectedToken = new BasicSecurityToken( "owner", "viewer", "app", "domain", "appUrl", "0", "container", "activeUrl", 1000L); // Mock token codec codec = new SecurityTokenCodec() { public SecurityToken createToken(Map<String, String> tokenParameters) throws SecurityTokenException { return tokenParameters == null ? null : "1234".equals(tokenParameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME)) ? expectedToken : null; } public String encodeToken(SecurityToken token) throws SecurityTokenException { return null; } public int getTokenTimeToLive() { return 0; // Not used. } public int getTokenTimeToLive(String container) { return 0; // Not used. } }; authHandler = new UrlParameterAuthenticationHandler(codec, true); }
@Before public void setup() throws Exception { expectedToken = new BasicSecurityToken( "owner", "viewer", "app", "domain", "appUrl", "0", "container", "activeUrl", 1000L); // Mock token codec codec = new SecurityTokenCodec() { public SecurityToken createToken(Map<String, String> tokenParameters) throws SecurityTokenException { return tokenParameters == null ? null : "1234".equals(tokenParameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME)) ? expectedToken : null; } public String encodeToken(SecurityToken token) throws SecurityTokenException { return null; } public int getTokenTimeToLive() { return 0; // Not used. } public int getTokenTimeToLive(String container) { return 0; // Not used. } }; authHandler = new UrlParameterAuthenticationHandler(codec, true); }
@Before public void setup() throws Exception { expectedToken = new BasicSecurityToken( "owner", "viewer", "app", "domain", "appUrl", "0", "container", "activeUrl", 1000L); // Mock token codec codec = new SecurityTokenCodec() { public SecurityToken createToken(Map<String, String> tokenParameters) throws SecurityTokenException { return tokenParameters == null ? null : "1234".equals(tokenParameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME)) ? expectedToken : null; } public String encodeToken(SecurityToken token) throws SecurityTokenException { return null; } public int getTokenTimeToLive() { return 0; // Not used. } public int getTokenTimeToLive(String container) { return 0; // Not used. } }; authHandler = new UrlParameterAuthenticationHandler(codec, true); }
@Before public void setUp() throws Exception { control = EasyMock.createNiceControl(); processor = control.createMock(Processor.class); lockedDomainService = control.createMock(LockedDomainService.class); oauthUriManager = control.createMock(OAuthUriManager.class); stateCrypter = new BasicBlobCrypter("1111111111111111111".getBytes()); securityToken = new BasicSecurityToken("viewer", "viewer", "app", "container.com", "gadget", "0", "default", MAKE_REQUEST_URL, null); gadget = control.createMock(Gadget.class); fetcherConfig = new OAuthFetcherConfig(null, null, null, null, false); responseParams = new OAuthResponseParams(null, null, null); }
@Before public void setUp() throws Exception { control = EasyMock.createNiceControl(); processor = control.createMock(Processor.class); lockedDomainService = control.createMock(LockedDomainService.class); oauthUriManager = control.createMock(OAuthUriManager.class); stateCrypter = new BasicBlobCrypter("1111111111111111111".getBytes()); securityToken = new BasicSecurityToken("viewer", "viewer", "app", "container.com", "gadget", "0", "default", MAKE_REQUEST_URL, null); gadget = control.createMock(Gadget.class); fetcherConfig = new OAuthFetcherConfig(null, null, null, null, false); responseParams = new OAuthResponseParams(null, null, null); }
@Before public void setUp() throws Exception { control = EasyMock.createNiceControl(); processor = control.createMock(Processor.class); lockedDomainService = control.createMock(LockedDomainService.class); oauthUriManager = control.createMock(OAuthUriManager.class); stateCrypter = new BasicBlobCrypter("1111111111111111111".getBytes()); securityToken = new BasicSecurityToken("viewer", "viewer", "app", "container.com", "gadget", "0", "default", MAKE_REQUEST_URL, null); gadget = control.createMock(Gadget.class); fetcherConfig = new OAuthFetcherConfig(null, null, null, null, false); responseParams = new OAuthResponseParams(null, null, null); }
@Test public void createKeySignedViewer() throws Exception { RequestAuthenticationInfo authInfo = newMockAuthInfo( false /* isSignOwner */, true /* isSignViewer */, ImmutableMap.of("OAUTH_SERVICE_NAME", SERVICE_NAME, "OAUTH_TOKEN_NAME", TOKEN_NAME)); replay(authInfo); String viewerId = "viewer eye dee"; SecurityToken securityToken = new BasicSecurityToken( "", viewerId, "", "", APP_URI.toString(), MODULE_ID, CONTAINER_NAME, null, null); HttpRequest request = new HttpRequest(DEFAULT_URI) .setAuthType(AuthType.SIGNED) .setOAuthArguments(new OAuthArguments(authInfo)) .setSecurityToken(securityToken); CacheKeyBuilder key = new CacheKeyBuilder() .setLegacyParam(0, DEFAULT_URI) .setLegacyParam(1, AuthType.SIGNED) .setLegacyParam(3, null) // The Viewer ID is in this case defaults to null .setLegacyParam(5, APP_URI) .setLegacyParam(6, MODULE_ID) .setLegacyParam(7, SERVICE_NAME) .setLegacyParam(8, TOKEN_NAME); assertEquals(key.build(), cache.createKey(request)); }
@Test public void createKeySignedViewer() throws Exception { RequestAuthenticationInfo authInfo = newMockAuthInfo( false /* isSignOwner */, true /* isSignViewer */, ImmutableMap.of("OAUTH_SERVICE_NAME", SERVICE_NAME, "OAUTH_TOKEN_NAME", TOKEN_NAME)); replay(authInfo); String viewerId = "viewer eye dee"; SecurityToken securityToken = new BasicSecurityToken( "", viewerId, "", "", APP_URI.toString(), MODULE_ID, CONTAINER_NAME, null, null); HttpRequest request = new HttpRequest(DEFAULT_URI) .setAuthType(AuthType.SIGNED) .setOAuthArguments(new OAuthArguments(authInfo)) .setSecurityToken(securityToken); CacheKeyBuilder key = new CacheKeyBuilder() .setLegacyParam(0, DEFAULT_URI) .setLegacyParam(1, AuthType.SIGNED) .setLegacyParam(3, null) // The Viewer ID is in this case defaults to null .setLegacyParam(5, APP_URI) .setLegacyParam(6, MODULE_ID) .setLegacyParam(7, SERVICE_NAME) .setLegacyParam(8, TOKEN_NAME); assertEquals(key.build(), cache.createKey(request)); }
@Test public void createKeySignedViewer() throws Exception { RequestAuthenticationInfo authInfo = newMockAuthInfo( false /* isSignOwner */, true /* isSignViewer */, ImmutableMap.of("OAUTH_SERVICE_NAME", SERVICE_NAME, "OAUTH_TOKEN_NAME", TOKEN_NAME)); replay(authInfo); String viewerId = "viewer eye dee"; SecurityToken securityToken = new BasicSecurityToken( "", viewerId, "", "", APP_URI.toString(), MODULE_ID, CONTAINER_NAME, null, null); HttpRequest request = new HttpRequest(DEFAULT_URI) .setAuthType(AuthType.SIGNED) .setOAuthArguments(new OAuthArguments(authInfo)) .setSecurityToken(securityToken); CacheKeyBuilder key = new CacheKeyBuilder() .setLegacyParam(0, DEFAULT_URI) .setLegacyParam(1, AuthType.SIGNED) .setLegacyParam(3, null) // The Viewer ID is in this case defaults to null .setLegacyParam(5, APP_URI) .setLegacyParam(6, MODULE_ID) .setLegacyParam(7, SERVICE_NAME) .setLegacyParam(8, TOKEN_NAME); assertEquals(key.build(), cache.createKey(request)); }
@Test public void createKeySignedOwner() throws Exception { // Using a mock instead of a fake object makes the test less brittle if the interface should // change. RequestAuthenticationInfo authInfo = newMockAuthInfo( true /* isSignOwner */, false /* isSignViewer */, ImmutableMap.of("OAUTH_SERVICE_NAME", SERVICE_NAME, "OAUTH_TOKEN_NAME", TOKEN_NAME)); replay(authInfo); String ownerId = "owner eye dee"; SecurityToken securityToken = new BasicSecurityToken(ownerId, "", "", "", APP_URI.toString(), MODULE_ID, CONTAINER_NAME, null, null); HttpRequest request = new HttpRequest(DEFAULT_URI) .setAuthType(AuthType.SIGNED) .setOAuthArguments(new OAuthArguments(authInfo)) .setSecurityToken(securityToken); CacheKeyBuilder key = new CacheKeyBuilder() .setLegacyParam(0, DEFAULT_URI) .setLegacyParam(1, AuthType.SIGNED) .setLegacyParam(2, ownerId) .setLegacyParam(3, "") .setLegacyParam(5, APP_URI) .setLegacyParam(6, MODULE_ID) .setLegacyParam(7, SERVICE_NAME) .setLegacyParam(8, TOKEN_NAME); assertEquals(key.build(), cache.createKey(request)); }
@Test public void createKeySignedOwner() throws Exception { // Using a mock instead of a fake object makes the test less brittle if the interface should // change. RequestAuthenticationInfo authInfo = newMockAuthInfo( true /* isSignOwner */, false /* isSignViewer */, ImmutableMap.of("OAUTH_SERVICE_NAME", SERVICE_NAME, "OAUTH_TOKEN_NAME", TOKEN_NAME)); replay(authInfo); String ownerId = "owner eye dee"; SecurityToken securityToken = new BasicSecurityToken(ownerId, "", "", "", APP_URI.toString(), MODULE_ID, CONTAINER_NAME, null, null); HttpRequest request = new HttpRequest(DEFAULT_URI) .setAuthType(AuthType.SIGNED) .setOAuthArguments(new OAuthArguments(authInfo)) .setSecurityToken(securityToken); CacheKeyBuilder key = new CacheKeyBuilder() .setLegacyParam(0, DEFAULT_URI) .setLegacyParam(1, AuthType.SIGNED) .setLegacyParam(2, ownerId) .setLegacyParam(3, "") .setLegacyParam(5, APP_URI) .setLegacyParam(6, MODULE_ID) .setLegacyParam(7, SERVICE_NAME) .setLegacyParam(8, TOKEN_NAME); assertEquals(key.build(), cache.createKey(request)); }
@Test public void createKeyWithTokenOwner() throws Exception { RequestAuthenticationInfo authInfo = newMockAuthInfo( true /* isSignOwner */, true /* isSignViewer */, ImmutableMap.of("OAUTH_SERVICE_NAME", SERVICE_NAME, "OAUTH_TOKEN_NAME", TOKEN_NAME, "OAUTH_USE_TOKEN", "always")); replay(authInfo); String userId = "user id"; SecurityToken securityToken = new BasicSecurityToken( userId, userId, "", "", APP_URI.toString(), MODULE_ID, CONTAINER_NAME, null, null); HttpRequest request = new HttpRequest(DEFAULT_URI) .setAuthType(AuthType.SIGNED) .setOAuthArguments(new OAuthArguments(authInfo)) .setSecurityToken(securityToken); CacheKeyBuilder key = new CacheKeyBuilder() .setLegacyParam(0, DEFAULT_URI) .setLegacyParam(1, AuthType.SIGNED) .setLegacyParam(2, userId) .setLegacyParam(3, userId) .setLegacyParam(4, userId) .setLegacyParam(5, APP_URI) .setLegacyParam(6, MODULE_ID) .setLegacyParam(7, SERVICE_NAME) .setLegacyParam(8, TOKEN_NAME); assertEquals(key.build(), cache.createKey(request)); }
@Test public void createKeySignedOwner() throws Exception { // Using a mock instead of a fake object makes the test less brittle if the interface should // change. RequestAuthenticationInfo authInfo = newMockAuthInfo( true /* isSignOwner */, false /* isSignViewer */, ImmutableMap.of("OAUTH_SERVICE_NAME", SERVICE_NAME, "OAUTH_TOKEN_NAME", TOKEN_NAME)); replay(authInfo); String ownerId = "owner eye dee"; SecurityToken securityToken = new BasicSecurityToken(ownerId, "", "", "", APP_URI.toString(), MODULE_ID, CONTAINER_NAME, null, null); HttpRequest request = new HttpRequest(DEFAULT_URI) .setAuthType(AuthType.SIGNED) .setOAuthArguments(new OAuthArguments(authInfo)) .setSecurityToken(securityToken); CacheKeyBuilder key = new CacheKeyBuilder() .setLegacyParam(0, DEFAULT_URI) .setLegacyParam(1, AuthType.SIGNED) .setLegacyParam(2, ownerId) .setLegacyParam(3, "") .setLegacyParam(5, APP_URI) .setLegacyParam(6, MODULE_ID) .setLegacyParam(7, SERVICE_NAME) .setLegacyParam(8, TOKEN_NAME); assertEquals(key.build(), cache.createKey(request)); }
@Test public void createKeyWithTokenOwner() throws Exception { RequestAuthenticationInfo authInfo = newMockAuthInfo( true /* isSignOwner */, true /* isSignViewer */, ImmutableMap.of("OAUTH_SERVICE_NAME", SERVICE_NAME, "OAUTH_TOKEN_NAME", TOKEN_NAME, "OAUTH_USE_TOKEN", "always")); replay(authInfo); String userId = "user id"; SecurityToken securityToken = new BasicSecurityToken( userId, userId, "", "", APP_URI.toString(), MODULE_ID, CONTAINER_NAME, null, null); HttpRequest request = new HttpRequest(DEFAULT_URI) .setAuthType(AuthType.SIGNED) .setOAuthArguments(new OAuthArguments(authInfo)) .setSecurityToken(securityToken); CacheKeyBuilder key = new CacheKeyBuilder() .setLegacyParam(0, DEFAULT_URI) .setLegacyParam(1, AuthType.SIGNED) .setLegacyParam(2, userId) .setLegacyParam(3, userId) .setLegacyParam(4, userId) .setLegacyParam(5, APP_URI) .setLegacyParam(6, MODULE_ID) .setLegacyParam(7, SERVICE_NAME) .setLegacyParam(8, TOKEN_NAME); assertEquals(key.build(), cache.createKey(request)); }
@Test public void createKeyWithTokenOwner() throws Exception { RequestAuthenticationInfo authInfo = newMockAuthInfo( true /* isSignOwner */, true /* isSignViewer */, ImmutableMap.of("OAUTH_SERVICE_NAME", SERVICE_NAME, "OAUTH_TOKEN_NAME", TOKEN_NAME, "OAUTH_USE_TOKEN", "always")); replay(authInfo); String userId = "user id"; SecurityToken securityToken = new BasicSecurityToken( userId, userId, "", "", APP_URI.toString(), MODULE_ID, CONTAINER_NAME, null, null); HttpRequest request = new HttpRequest(DEFAULT_URI) .setAuthType(AuthType.SIGNED) .setOAuthArguments(new OAuthArguments(authInfo)) .setSecurityToken(securityToken); CacheKeyBuilder key = new CacheKeyBuilder() .setLegacyParam(0, DEFAULT_URI) .setLegacyParam(1, AuthType.SIGNED) .setLegacyParam(2, userId) .setLegacyParam(3, userId) .setLegacyParam(4, userId) .setLegacyParam(5, APP_URI) .setLegacyParam(6, MODULE_ID) .setLegacyParam(7, SERVICE_NAME) .setLegacyParam(8, TOKEN_NAME); assertEquals(key.build(), cache.createKey(request)); }