@Test public void withWl() { final PrefixSource entrySource = new ArrayListPrefixSource(Arrays.asList("/org/apache", "/org/sonatype")); Mockito.when(wlManager.getPrefixSourceFor(Mockito.any(MavenProxyRepository.class))) .thenReturn(entrySource); // WL will be built, not every request should be allowed final ProxyRequestFilterImpl filter = new ProxyRequestFilterImpl(eventBus, applicationStatusSource, wlManager); // ping (this would happen on event) filter.buildPathMatcherFor(mavenProxyRepository); // +1 doTestAllowed(filter, "/org/apache/maven/foo/1.0/foo-1.0.jar", true); // +1 doTestAllowed(filter, "/org/sonatype/maven/foo/1.0/foo-1.0.jar", true); // -1 com doTestAllowed(filter, "/com/sonatype/maven/foo/1.0/foo-1.0.jar", false); // -1 not in WL doTestAllowed( filter, "/.meta/prefix.txt", false); // this file is handled in AbstractMavenRepository, using // UID attributes to test for IsHidden attribute }
protected void doTestAllowed( final ProxyRequestFilterImpl filter, final String path, final boolean shouldBeAllowed) { final ResourceStoreRequest resourceStoreRequest = new ResourceStoreRequest(path); assertThat( String.format("%s path is expected to return %s", path, shouldBeAllowed), filter.allowed(mavenProxyRepository, resourceStoreRequest), is(shouldBeAllowed)); }