@Test public void testRemoveContainer() throws Exception { config.newTransaction().addContainer(EXTRA_CONTAINER).commit(); config.newTransaction().addContainer(EXTRA_CONTAINER).commit(); ConfigObserver observer = EasyMock.createMock(ContainerConfig.ConfigObserver.class); observer.containersChanged(EasyMock.isA(ContainerConfig.class), EasyMock.eq(ImmutableSet.<String>of()), EasyMock.eq(ImmutableSet.of("extra"))); EasyMock.replay(observer); config.addConfigObserver(observer, false); config.newTransaction().removeContainer("extra").commit(); assertFalse(config.getContainers().contains("extra")); EasyMock.verify(observer); }
@Test public void testRemoveContainer() throws Exception { config.newTransaction().addContainer(EXTRA_CONTAINER).commit(); config.newTransaction().addContainer(EXTRA_CONTAINER).commit(); ConfigObserver observer = EasyMock.createMock(ContainerConfig.ConfigObserver.class); observer.containersChanged(EasyMock.isA(ContainerConfig.class), EasyMock.eq(ImmutableSet.<String>of()), EasyMock.eq(ImmutableSet.of("extra"))); EasyMock.replay(observer); config.addConfigObserver(observer, false); config.newTransaction().removeContainer("extra").commit(); assertFalse(config.getContainers().contains("extra")); EasyMock.verify(observer); }
@Test public void testRemoveContainer() throws Exception { config.newTransaction().addContainer(EXTRA_CONTAINER).commit(); config.newTransaction().addContainer(EXTRA_CONTAINER).commit(); ConfigObserver observer = EasyMock.createMock(ContainerConfig.ConfigObserver.class); observer.containersChanged(EasyMock.isA(ContainerConfig.class), EasyMock.eq(ImmutableSet.<String>of()), EasyMock.eq(ImmutableSet.of("extra"))); EasyMock.replay(observer); config.addConfigObserver(observer, false); config.newTransaction().removeContainer("extra").commit(); assertFalse(config.getContainers().contains("extra")); EasyMock.verify(observer); }
@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 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 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 } }