config .newTransaction() .addContainer(ImmutableMap .<String, Object>builder() .put(ContainerConfig.CONTAINER_KEY, ContainerConfig.DEFAULT_CONTAINER)
config .newTransaction() .addContainer(ImmutableMap .<String, Object>builder() .put(ContainerConfig.CONTAINER_KEY, ContainerConfig.DEFAULT_CONTAINER) .put(DefaultJsUriManager.JS_PATH_PARAM, JS_PATH) .build()) .addContainer(ImmutableMap .<String, Object>builder() .put(ContainerConfig.CONTAINER_KEY, CONTAINER) .put(DefaultJsUriManager.JS_PATH_PARAM, JS_PATH) .build()) .addContainer(ImmutableMap .<String, Object>builder() .put(ContainerConfig.CONTAINER_KEY, altContainer) .put(DefaultJsUriManager.JS_PATH_PARAM, JS_PATH) .build()) .commit(); LockedDomainService ldService = new HashLockedDomainService(config, enabled, prefixGen); return new TestDefaultIframeUriManager(config, ldService);
@Test public void testChangingContainers() throws Exception { String newContainer = "newcontainer"; Map<String, String> values = new HashMap<String, String>(); values.put(Keys.APP_URL.getKey(), "http://www.example.com/gadget.xml"); values.put(Keys.MODULE_ID.getKey(), Long.toString(12345L, 10)); values.put(Keys.OWNER.getKey(), "owner"); values.put(Keys.VIEWER.getKey(), "viewer"); values.put(Keys.TRUSTED_JSON.getKey(), "trusted"); BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(newContainer, null, null, values); String encrypted = t.getContainer() + ":" + getBlobCrypter(getContainerKey(newContainer)).wrap(t.toMap()); // fails when trying to create a token for a non-existing container try { codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted)); fail("Should have thrown a SecurityTokenException"); } catch (SecurityTokenException e) { // pass } // add the container, now it should succeed config.newTransaction().addContainer(makeContainer(newContainer)).commit(); codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted)); // remove the token, now it should fail again config.newTransaction().removeContainer(newContainer).commit(); try { codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted)); fail("Should have thrown a SecurityTokenException"); } catch (SecurityTokenException e) { // pass } }
config .newTransaction() .addContainer(ImmutableMap.<String, Object>builder() .put(ContainerConfig.CONTAINER_KEY, ContainerConfig.DEFAULT_CONTAINER) .put(LOCKED_DOMAIN_SUFFIX_KEY, LD_SUFFIX) .build()) .addContainer(ImmutableMap.<String, Object> builder() .put(ContainerConfig.CONTAINER_KEY, CONTAINER) .put(IFRAME_BASE_PATH_KEY, IFRAME_PATH) .put(DefaultJsUriManager.JS_PATH_PARAM, JS_PATH) .build()) .commit();
config .newTransaction() .addContainer(ImmutableMap.<String, Object>builder() .put(ContainerConfig.CONTAINER_KEY, ContainerConfig.DEFAULT_CONTAINER) .put(LOCKED_DOMAIN_SUFFIX_KEY, LD_SUFFIX) .build()) .addContainer(ImmutableMap.<String, Object> builder() .put(ContainerConfig.CONTAINER_KEY, CONTAINER) .put(IFRAME_BASE_PATH_KEY, IFRAME_PATH)
config .newTransaction() .addContainer(DEFAULT_CONTAINER_CONFIG) .addContainer(MOCK_CONTAINER_CONFIG) .commit(); proxyUriManager = new DefaultProxyUriManager(config, null); rewriterNoOverrideExpires = new CssResponseRewriter(new CajaCssParser(),
config .newTransaction() .addContainer(DEFAULT_CONTAINER_CONFIG) .addContainer(MOCK_CONTAINER_CONFIG) .commit(); proxyUriManager = new DefaultProxyUriManager(config, null); rewriterNoOverrideExpires = new CssResponseRewriter(new CajaCssParser(),
@Test public void testPropertyTypes() throws Exception { String container = "misc"; config.newTransaction().addContainer(makeContainer("misc", "bool", Boolean.valueOf(true), "bool2", "true", "badbool", Integer.valueOf(1234), "badbool2", "notabool", "int", Integer.valueOf(1234), "int2", "1234", "badint", "notanint", "string", "abcd", "list", ImmutableList.of("a"), "badlist", "notalist", "map", ImmutableMap.of("a", "b"), "badmap", "notamap")).commit(); assertEquals(true, config.getBool(container, "bool")); assertEquals(true, config.getBool(container, "bool2")); assertEquals(false, config.getBool(container, "badbool")); assertEquals(false, config.getBool(container, "badbool2")); assertEquals(1234, config.getInt(container, "int")); assertEquals(1234, config.getInt(container, "int2")); assertEquals(0, config.getInt(container, "badint")); assertEquals("abcd", config.getString(container, "string")); assertEquals(ImmutableList.of("a"), config.getList(container, "list")); assertTrue(config.getList(container, "badlist").isEmpty()); assertEquals(ImmutableMap.of("a", "b"), config.getMap(container, "map")); assertTrue(config.getMap(container, "badmap").isEmpty()); }
@Test public void testConfigurationChanged() throws Exception { ContainerConfig config = new BasicContainerConfig(); config .newTransaction() .addContainer(makeContainer(ContainerConfig.DEFAULT_CONTAINER)) .addContainer( makeContainer("container", LOCKED_DOMAIN_REQUIRED_KEY, true, LOCKED_DOMAIN_SUFFIX_KEY, "-a.example.com:8080")) .commit(); lockedDomainService = new HashLockedDomainService(config, true, ldgen); assertTrue(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "container")); assertFalse(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "other")); config.newTransaction().addContainer(makeContainer( "other", LOCKED_DOMAIN_REQUIRED_KEY, true, LOCKED_DOMAIN_SUFFIX_KEY, "-a.example.com:8080")) .commit(); lockedDomainService.getConfigObserver().containersChanged( config, ImmutableSet.of("other"), ImmutableSet.<String>of()); assertTrue(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "container")); assertTrue(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "other")); config.newTransaction().removeContainer("container").commit(); assertFalse(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "container")); assertTrue(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "other")); }
@Test public void testPropertyTypes() throws Exception { String container = "misc"; config.newTransaction().addContainer(makeContainer("misc", "bool", Boolean.valueOf(true), "bool2", "true", "badbool", Integer.valueOf(1234), "badbool2", "notabool", "int", Integer.valueOf(1234), "int2", "1234", "badint", "notanint", "string", "abcd", "list", ImmutableList.of("a"), "badlist", "notalist", "map", ImmutableMap.of("a", "b"), "badmap", "notamap")).commit(); assertEquals(true, config.getBool(container, "bool")); assertEquals(true, config.getBool(container, "bool2")); assertEquals(false, config.getBool(container, "badbool")); assertEquals(false, config.getBool(container, "badbool2")); assertEquals(1234, config.getInt(container, "int")); assertEquals(1234, config.getInt(container, "int2")); assertEquals(0, config.getInt(container, "badint")); assertEquals("abcd", config.getString(container, "string")); assertEquals(ImmutableList.of("a"), config.getList(container, "list")); assertTrue(config.getList(container, "badlist").isEmpty()); assertEquals(ImmutableMap.of("a", "b"), config.getMap(container, "map")); assertTrue(config.getMap(container, "badmap").isEmpty()); }
@Test public void testChangingContainers() throws Exception { String newContainer = "newcontainer"; Map<String, String> values = new HashMap<String, String>(); values.put(Keys.APP_URL.getKey(), "http://www.example.com/gadget.xml"); values.put(Keys.MODULE_ID.getKey(), Long.toString(12345L, 10)); values.put(Keys.OWNER.getKey(), "owner"); values.put(Keys.VIEWER.getKey(), "viewer"); values.put(Keys.TRUSTED_JSON.getKey(), "trusted"); BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(newContainer, null, null, values); String encrypted = t.getContainer() + ":" + getBlobCrypter(getContainerKey(newContainer)).wrap(t.toMap()); // fails when trying to create a token for a non-existing container try { codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted)); fail("Should have thrown a SecurityTokenException"); } catch (SecurityTokenException e) { // pass } // add the container, now it should succeed config.newTransaction().addContainer(makeContainer(newContainer)).commit(); codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted)); // remove the token, now it should fail again config.newTransaction().removeContainer(newContainer).commit(); try { codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted)); fail("Should have thrown a SecurityTokenException"); } catch (SecurityTokenException e) { // pass } }
@Test public void testConfigurationChanged() throws Exception { ContainerConfig config = new BasicContainerConfig(); config .newTransaction() .addContainer(makeContainer(ContainerConfig.DEFAULT_CONTAINER)) .addContainer( makeContainer("container", LOCKED_DOMAIN_REQUIRED_KEY, true, LOCKED_DOMAIN_SUFFIX_KEY, "-a.example.com:8080")) .commit(); lockedDomainService = new HashLockedDomainService(config, true, ldgen); assertTrue(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "container")); assertFalse(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "other")); config.newTransaction().addContainer(makeContainer( "other", LOCKED_DOMAIN_REQUIRED_KEY, true, LOCKED_DOMAIN_SUFFIX_KEY, "-a.example.com:8080")) .commit(); lockedDomainService.getConfigObserver().containersChanged( config, ImmutableSet.of("other"), ImmutableSet.<String>of()); assertTrue(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "container")); assertTrue(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "other")); config.newTransaction().removeContainer("container").commit(); assertFalse(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "container")); assertTrue(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "other")); }
@Test public void testChangingContainers() throws Exception { String newContainer = "newcontainer"; Map<String, String> values = new HashMap<String, String>(); values.put(Keys.APP_URL.getKey(), "http://www.example.com/gadget.xml"); values.put(Keys.MODULE_ID.getKey(), Long.toString(12345L, 10)); values.put(Keys.OWNER.getKey(), "owner"); values.put(Keys.VIEWER.getKey(), "viewer"); values.put(Keys.TRUSTED_JSON.getKey(), "trusted"); BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(newContainer, null, null, values); String encrypted = t.getContainer() + ":" + getBlobCrypter(getContainerKey(newContainer)).wrap(t.toMap()); // fails when trying to create a token for a non-existing container try { codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted)); fail("Should have thrown a SecurityTokenException"); } catch (SecurityTokenException e) { // pass } // add the container, now it should succeed config.newTransaction().addContainer(makeContainer(newContainer)).commit(); codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted)); // remove the token, now it should fail again config.newTransaction().removeContainer(newContainer).commit(); try { codec.createToken(ImmutableMap.of(SecurityTokenCodec.SECURITY_TOKEN_NAME, encrypted)); fail("Should have thrown a SecurityTokenException"); } catch (SecurityTokenException e) { // pass } }
@Test public void testPropertyTypes() throws Exception { String container = "misc"; config.newTransaction().addContainer(makeContainer("misc", "bool", Boolean.valueOf(true), "bool2", "true", "badbool", Integer.valueOf(1234), "badbool2", "notabool", "int", Integer.valueOf(1234), "int2", "1234", "badint", "notanint", "string", "abcd", "list", ImmutableList.of("a"), "badlist", "notalist", "map", ImmutableMap.of("a", "b"), "badmap", "notamap")).commit(); assertEquals(true, config.getBool(container, "bool")); assertEquals(true, config.getBool(container, "bool2")); assertEquals(false, config.getBool(container, "badbool")); assertEquals(false, config.getBool(container, "badbool2")); assertEquals(1234, config.getInt(container, "int")); assertEquals(1234, config.getInt(container, "int2")); assertEquals(0, config.getInt(container, "badint")); assertEquals("abcd", config.getString(container, "string")); assertEquals(ImmutableList.of("a"), config.getList(container, "list")); assertTrue(config.getList(container, "badlist").isEmpty()); assertEquals(ImmutableMap.of("a", "b"), config.getMap(container, "map")); assertTrue(config.getMap(container, "badmap").isEmpty()); }
@Test public void testClearContainerConfig() throws Exception { ConfigObserver observer = EasyMock.createMock(ContainerConfig.ConfigObserver.class); observer.containersChanged(EasyMock.isA(ContainerConfig.class), EasyMock.eq(ImmutableSet.of("additional")), EasyMock.eq(ImmutableSet.of("extra"))); EasyMock.replay(observer); config = new BasicContainerConfig(); config .newTransaction() .clearContainers() .addContainer(DEFAULT_CONTAINER) .addContainer(EXTRA_CONTAINER) .commit(); config.addConfigObserver(observer, false); config .newTransaction() .clearContainers() .addContainer(DEFAULT_CONTAINER) .addContainer(makeContainer("additional")) .commit(); assertFalse(config.getContainers().contains("extra")); assertTrue(config.getContainers().contains("additional")); EasyMock.verify(observer); }
@Test public void testContainersAreMergedRecursively() throws Exception { // Data taken from the documentation for BasicContainerConfig#mergeParents Map<String, Object> defaultContainer = makeContainer("default", "base", "/gadgets/foo", "user", "peter", "map", ImmutableMap.of("latitude", 42, "longitude", -8), "data", ImmutableList.of("foo", "bar")); Map<String, Object> newContainer = makeContainer("new", "user", "anne", "colour", "green", "map", ImmutableMap.of("longitude", 130), "data", null); Map<String, Object> expectedContainer = makeContainer("new", "base", "/gadgets/foo", "user", "anne", "colour", "green", "map", ImmutableMap.of("latitude", 42, "longitude", 130), "data", null); config.newTransaction().addContainer(defaultContainer).addContainer(newContainer).commit(); assertEquals(expectedContainer, config.getProperties("new")); }
@Test public void testContainersChange() throws Exception { String beforeUrl = "//apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.example.org%2Findex.html" + "&debug=0&nocache=0&refresh=0&rooe=1&url=http%3A%2F%2Fwww.example.org%2Findex.html"; String afterUrl = "//apache.org/random/url?container=accel" + "&gadget=http%3A%2F%2Fwww.example.org%2Findex.html" + "&debug=0&nocache=0&refresh=0&rooe=1&url=http%3A%2F%2Fwww.example.org%2Findex.html"; Uri uri = Uri.parse("http://www.example.org/index.html"); HttpRequest req = new HttpRequest(uri); req.setContainer("accel"); assertEquals(Uri.parse(beforeUrl), uriManager.parseAndNormalize(req)); assertTrue(uriManager.looksLikeAccelUri(Uri.parse(beforeUrl))); assertFalse(uriManager.looksLikeAccelUri(Uri.parse(afterUrl))); config.newTransaction().addContainer(makeConfig("accel", "/random/url")).commit(); uri = Uri.parse("http://www.example.org/index.html"); req = new HttpRequest(uri); req.setContainer("accel"); assertEquals(Uri.parse(afterUrl), uriManager.parseAndNormalize(req)); assertFalse(uriManager.looksLikeAccelUri(Uri.parse(beforeUrl))); assertTrue(uriManager.looksLikeAccelUri(Uri.parse(afterUrl))); } }
@Test public void containerConfigurationChanges() throws Exception { ContainerConfig config = new BasicContainerConfig(); config .newTransaction() .addContainer(ImmutableMap .<String, Object>builder() .put(ContainerConfig.CONTAINER_KEY, ContainerConfig.DEFAULT_CONTAINER) .put(LOCKED_DOMAIN_SUFFIX_KEY, LD_SUFFIX) .put(IFRAME_BASE_PATH_KEY, IFRAME_PATH) .put(LOCKED_DOMAIN_REQUIRED_KEY, true) .build()) .commit(); LockedDomainService ldService = new HashLockedDomainService(config, true, prefixGen); TestDefaultIframeUriManager manager = new TestDefaultIframeUriManager(config, ldService); Uri testUri = Uri.parse("http://foobar" + LD_SUFFIX + "/?url=http://example.com"); config.newTransaction().addContainer(ImmutableMap .<String, Object>builder() .put(ContainerConfig.CONTAINER_KEY, ContainerConfig.DEFAULT_CONTAINER) .put(LOCKED_DOMAIN_SUFFIX_KEY, LD_SUFFIX_ALT) .build()).commit(); assertEquals(UriStatus.VALID_UNVERSIONED, manager.validateRenderingUri(testUri)); }
@Test public void testClearContainerConfig() throws Exception { ConfigObserver observer = EasyMock.createMock(ContainerConfig.ConfigObserver.class); observer.containersChanged(EasyMock.isA(ContainerConfig.class), EasyMock.eq(ImmutableSet.of("additional")), EasyMock.eq(ImmutableSet.of("extra"))); EasyMock.replay(observer); config = new BasicContainerConfig(); config .newTransaction() .clearContainers() .addContainer(DEFAULT_CONTAINER) .addContainer(EXTRA_CONTAINER) .commit(); config.addConfigObserver(observer, false); config .newTransaction() .clearContainers() .addContainer(DEFAULT_CONTAINER) .addContainer(makeContainer("additional")) .commit(); assertFalse(config.getContainers().contains("extra")); assertTrue(config.getContainers().contains("additional")); EasyMock.verify(observer); }
@Test public void containerConfigurationChanges() throws Exception { ContainerConfig config = new BasicContainerConfig(); config .newTransaction() .addContainer(ImmutableMap .<String, Object>builder() .put(ContainerConfig.CONTAINER_KEY, ContainerConfig.DEFAULT_CONTAINER) .put(LOCKED_DOMAIN_SUFFIX_KEY, LD_SUFFIX) .put(IFRAME_BASE_PATH_KEY, IFRAME_PATH) .put(LOCKED_DOMAIN_REQUIRED_KEY, true) .build()) .commit(); LockedDomainService ldService = new HashLockedDomainService(config, true, prefixGen); TestDefaultIframeUriManager manager = new TestDefaultIframeUriManager(config, ldService); Uri testUri = Uri.parse("http://foobar" + LD_SUFFIX + "/?url=http://example.com"); config.newTransaction().addContainer(ImmutableMap .<String, Object>builder() .put(ContainerConfig.CONTAINER_KEY, ContainerConfig.DEFAULT_CONTAINER) .put(LOCKED_DOMAIN_SUFFIX_KEY, LD_SUFFIX_ALT) .build()).commit(); assertEquals(UriStatus.VALID_UNVERSIONED, manager.validateRenderingUri(testUri)); }