### Question:
DefaultIframeUriManager implements IframeUriManager { public UriStatus validateRenderingUri(Uri inUri) { UriBuilder uri = new UriBuilder(inUri); String gadgetStr = uri.getQueryParameter(Param.URL.getKey()); Uri gadgetUri; try { gadgetUri = Uri.parse(gadgetStr); } catch (Exception e) { return UriStatus.BAD_URI; } String container = uri.getQueryParameter(Param.CONTAINER.getKey()); if (container == null) { container = ContainerConfig.DEFAULT_CONTAINER; } String version = uri.getQueryParameter(Param.VERSION.getKey()); if (versioner == null || version == null) { return UriStatus.VALID_UNVERSIONED; } return versioner.validate(gadgetUri, container, version); } @Inject  DefaultIframeUriManager(ContainerConfig config,
                                 LockedDomainService ldService,
                                 SecurityTokenCodec securityTokenCodec); @Inject(optional = true) void setVersioner(Versioner versioner); @Inject(optional = true) void setTemplatingSignal(TemplatingSignal tplSignal); @Inject(optional = true) void setAuthority(Authority authority); Uri makeRenderingUri(Gadget gadget); UriStatus validateRenderingUri(Uri inUri); static String tplKey(String key); Map<String, Uri> makeAllRenderingUris(Gadget gadget); static final String LOCKED_DOMAIN_SUFFIX_KEY; static final String UNLOCKED_DOMAIN_KEY; static final String SECURITY_TOKEN_ALWAYS_KEY; static final String LOCKED_DOMAIN_FEATURE_NAME; static final String SECURITY_TOKEN_FEATURE_NAME; }### Answer:
@Test public void badUriValidatingUri() throws Exception { Uri uri = new UriBuilder().addQueryParameter(Param.URL.getKey(), "^': bad:").toUri(); TestDefaultIframeUriManager manager = makeManager(false, false); UriStatus status = manager.validateRenderingUri(uri); assertEquals(UriStatus.BAD_URI, status); }
@Test public void validUnversionedNoVersioner() throws Exception { Uri uri = makeValidationTestUri(LD_PREFIX + LD_SUFFIX, "version"); DefaultIframeUriManager manager = makeManager(false, false); assertEquals(UriStatus.VALID_UNVERSIONED, manager.validateRenderingUri(uri)); }
@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: 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)); }