@Before public void setUp() throws Exception { requiredConfig = new BasicContainerConfig(); requiredConfig.newTransaction().addContainer( makeContainer(ContainerConfig.DEFAULT_CONTAINER, LOCKED_DOMAIN_SUFFIX_KEY, "-a.example.com:8080", LOCKED_DOMAIN_REQUIRED_KEY, true)).commit(); enabledConfig = new BasicContainerConfig(); enabledConfig.newTransaction().addContainer( makeContainer(ContainerConfig.DEFAULT_CONTAINER, LOCKED_DOMAIN_SUFFIX_KEY, "-a.example.com:8080")).commit(); wantsLocked = makeGadget(true, false, "http://somehost.com/somegadget.xml"); notLocked = makeGadget(false, false, "not-locked"); wantsSecurityToken = makeGadget(false, true, "http://somehost.com/securitytoken.xml"); wantsBoth = makeGadget(true, true, "http://somehost.com/tokenandlocked.xml"); }
@Test public void testMultiContainer() throws Exception { ContainerConfig inheritsConfig = new BasicContainerConfig(); inheritsConfig .newTransaction() .addContainer( makeContainer(ContainerConfig.DEFAULT_CONTAINER, LOCKED_DOMAIN_SUFFIX_KEY, "-a.example.com:8080", LOCKED_DOMAIN_REQUIRED_KEY, true)) .addContainer(makeContainer("other")) .commit(); lockedDomainService = new HashLockedDomainService(inheritsConfig, true, ldgen); assertFalse(lockedDomainService.isGadgetValidForHost("www.example.com", wantsLocked, "other")); assertFalse(lockedDomainService.isGadgetValidForHost("www.example.com", notLocked, "other")); assertTrue(lockedDomainService.isGadgetValidForHost( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "other")); }
@Before public void setUp() throws Exception { requiredConfig = new BasicContainerConfig(); requiredConfig.newTransaction().addContainer( makeContainer(ContainerConfig.DEFAULT_CONTAINER, LOCKED_DOMAIN_SUFFIX_KEY, "-a.example.com:8080", LOCKED_DOMAIN_REQUIRED_KEY, true)).commit(); enabledConfig = new BasicContainerConfig(); enabledConfig.newTransaction().addContainer( makeContainer(ContainerConfig.DEFAULT_CONTAINER, LOCKED_DOMAIN_SUFFIX_KEY, "-a.example.com:8080")).commit(); wantsLocked = makeGadget(true, false, "http://somehost.com/somegadget.xml"); notLocked = makeGadget(false, false, "not-locked"); wantsSecurityToken = makeGadget(false, true, "http://somehost.com/securitytoken.xml"); wantsBoth = makeGadget(true, true, "http://somehost.com/tokenandlocked.xml"); }
@Test public void testMultiContainer() throws Exception { ContainerConfig inheritsConfig = new BasicContainerConfig(); inheritsConfig .newTransaction() .addContainer( makeContainer(ContainerConfig.DEFAULT_CONTAINER, LOCKED_DOMAIN_SUFFIX_KEY, "-a.example.com:8080", LOCKED_DOMAIN_REQUIRED_KEY, true)) .addContainer(makeContainer("other")) .commit(); lockedDomainService = new HashLockedDomainService(inheritsConfig, true, ldgen); assertFalse(lockedDomainService.isGadgetValidForHost("www.example.com", wantsLocked, "other")); assertFalse(lockedDomainService.isGadgetValidForHost("www.example.com", notLocked, "other")); 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 testMissingConfig() throws Exception { ContainerConfig containerMissingConfig = new BasicContainerConfig(); containerMissingConfig.newTransaction().addContainer(makeContainer(ContainerConfig.DEFAULT_CONTAINER)).commit(); lockedDomainService = new HashLockedDomainService(containerMissingConfig, true, ldgen); assertFalse(lockedDomainService.isGadgetValidForHost("www.example.com", wantsLocked, "default")); assertTrue(lockedDomainService.isGadgetValidForHost("www.example.com", notLocked, "default")); }
@Test public void testMissingConfig() throws Exception { ContainerConfig containerMissingConfig = new BasicContainerConfig(); containerMissingConfig.newTransaction().addContainer(makeContainer(ContainerConfig.DEFAULT_CONTAINER)).commit(); lockedDomainService = new HashLockedDomainService(containerMissingConfig, true, ldgen); assertFalse(lockedDomainService.isGadgetValidForHost("www.example.com", wantsLocked, "default")); assertTrue(lockedDomainService.isGadgetValidForHost("www.example.com", notLocked, "default")); }
@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")); }