@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
  }
  @Override
  protected YumRepository doRun() throws Exception {
    String repositoryId = getRepositoryId();

    if (!StringUtils.isEmpty(repositoryId)) {
      checkState(
          yumRegistry.isRegistered(repositoryId),
          "Metadata regeneration can only be run on repositories that have an enabled 'Yum: Generate Metadata' capability");
      Yum yum = yumRegistry.get(repositoryId);
      checkState(
          yum.getNexusRepository().getRepositoryKind().isFacetAvailable(HostedRepository.class),
          "Metadata generation can only be run on hosted repositories");
    }

    setDefaults();

    LOG.debug("Generating Yum-Repository for '{}' ...", getRpmDir());
    try {
      getRepoDir().mkdirs();

      File rpmListFile = createRpmListFile();
      commandLineExecutor.exec(buildCreateRepositoryCommand(rpmListFile));

      if (isUseAbsoluteUrls() && StringUtils.isNotBlank(getRpmUrl())) {
        replaceUrlInRepomdXml();
      }

    } catch (IOException e) {
      LOG.warn("Yum metadata generation failed", e);
      throw new IOException("Yum metadata generation failed", e);
    }
    // TODO dubious
    Thread.sleep(100);

    final Repository repository = findRepository();
    if (repository != null) {
      final MavenRepository mavenRepository = repository.adaptToFacet(MavenRepository.class);
      if (mavenRepository != null) {
        try {
          routingManager.forceUpdatePrefixFile(mavenRepository);
        } catch (Exception e) {
          logger.warn("Could not update Whitelist for repository '{}'", mavenRepository, e);
        }
      }
    }

    regenerateMetadataForGroups();
    return new YumRepositoryImpl(getRepoDir(), repositoryId, getVersion());
  }
 protected void buildPathMatcherFor(final MavenProxyRepository mavenProxyRepository) {
   try {
     final PrefixSource prefixSource = manager.getPrefixSourceFor(mavenProxyRepository);
     if (prefixSource.supported()) {
       final PathMatcher pathMatcher =
           new PathMatcher(prefixSource.readEntries(), Integer.MAX_VALUE);
       pathMatchers.put(mavenProxyRepository.getId(), pathMatcher);
     } else {
       dropPathMatcherFor(mavenProxyRepository);
     }
   } catch (IOException e) {
     getLogger().warn("Could not build PathMatcher for {}!", mavenProxyRepository, e);
     dropPathMatcherFor(mavenProxyRepository);
   }
 }
예제 #4
0
  @Test
  public void flippingProxyModeUpdatesWL() throws Exception {
    // at this point, NexusStartedEvent was fired, and hence, WL's should be inited
    final Manager wm = lookup(Manager.class);
    final MavenProxyRepository proxy1 =
        getRepositoryRegistry().getRepositoryWithFacet(PROXY1_REPO_ID, MavenProxyRepository.class);

    assertThat(proxy1.getProxyMode(), equalTo(ProxyMode.BLOCKED_MANUAL));
    waitForRoutingBackgroundUpdates();

    // let's check states
    {
      // proxy1
      final RoutingStatus proxy1status = wm.getStatusFor(proxy1);
      // this repo is Blocked
      assertThat(proxy1status.getPublishingStatus().getStatus(), equalTo(PStatus.NOT_PUBLISHED));
      assertThat(
          proxy1status.getDiscoveryStatus().getStatus(), equalTo(DStatus.ENABLED_NOT_POSSIBLE));
      assertThat(proxy1status.getDiscoveryStatus().getLastDiscoveryStrategy(), is("none"));
      // Remark: the combination of those three above simply means "discovery never tried against
      // it"
      // yet.
    }
    {
      // group
      final RoutingStatus groupStatus =
          wm.getStatusFor(
              getRepositoryRegistry()
                  .getRepositoryWithFacet(GROUP_REPO_ID, MavenGroupRepository.class));
      // not all members have WL, unpublished
      assertThat(groupStatus.getPublishingStatus().getStatus(), equalTo(PStatus.NOT_PUBLISHED));
      // message should refer to proxy1 as reason of not publishing group WL
      assertThat(
          groupStatus.getPublishingStatus().getLastPublishedMessage(),
          containsString(proxy1.getName()));
      assertThat(groupStatus.getDiscoveryStatus().getStatus(), equalTo(DStatus.NOT_A_PROXY));
    }

    {
      // let's flip proxy1 now
      proxy1.setProxyMode(ProxyMode.ALLOW);
      getApplicationConfiguration().saveConfiguration();
      Thread.yield();
      wairForAsyncEventsToCalmDown();
      waitForRoutingBackgroundUpdates();
    }

    // let's check states again, now with enabled proxy1

    {
      // proxy1
      final RoutingStatus proxy1status =
          wm.getStatusFor(
              getRepositoryRegistry()
                  .getRepositoryWithFacet(PROXY1_REPO_ID, MavenProxyRepository.class));
      // this repo is Out of Service
      assertThat(proxy1status.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED));
      assertThat(proxy1status.getDiscoveryStatus().getStatus(), equalTo(DStatus.SUCCESSFUL));
      assertThat(
          proxy1status.getDiscoveryStatus().getLastDiscoveryStrategy(),
          is(RemotePrefixFileStrategy.ID));
    }
    {
      // group
      final RoutingStatus groupStatus =
          wm.getStatusFor(
              getRepositoryRegistry()
                  .getRepositoryWithFacet(GROUP_REPO_ID, MavenGroupRepository.class));
      assertThat(groupStatus.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED));
      assertThat(groupStatus.getDiscoveryStatus().getStatus(), equalTo(DStatus.NOT_A_PROXY));
    }

    {
      // let's flip proxy1 now back
      proxy1.setProxyMode(ProxyMode.BLOCKED_MANUAL);
      getApplicationConfiguration().saveConfiguration();
      Thread.yield();
      wairForAsyncEventsToCalmDown();
      waitForRoutingBackgroundUpdates();
    }

    // let's check states again, now with enabled proxy1

    {
      // proxy1
      final RoutingStatus proxy1status =
          wm.getStatusFor(
              getRepositoryRegistry()
                  .getRepositoryWithFacet(PROXY1_REPO_ID, MavenProxyRepository.class));
      // this repo is blocked
      assertThat(proxy1status.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED));
      assertThat(
          proxy1status.getDiscoveryStatus().getStatus(), equalTo(DStatus.ENABLED_NOT_POSSIBLE));
      assertThat(proxy1status.getDiscoveryStatus().getLastDiscoveryStrategy(), is("none"));
    }
    {
      // group
      final RoutingStatus groupStatus =
          wm.getStatusFor(
              getRepositoryRegistry()
                  .getRepositoryWithFacet(GROUP_REPO_ID, MavenGroupRepository.class));
      assertThat(groupStatus.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED));
      assertThat(groupStatus.getDiscoveryStatus().getStatus(), equalTo(DStatus.NOT_A_PROXY));
    }
  }
예제 #5
0
  @Test
  public void manuallyBlockedRepositoryDoesNotAffectWLInitialization() throws Exception {
    // at this point, NexusStartedEvent was fired, and hence, WL's should be inited
    final Manager wm = lookup(Manager.class);
    final MavenProxyRepository proxy1 =
        getRepositoryRegistry().getRepositoryWithFacet(PROXY1_REPO_ID, MavenProxyRepository.class);

    assertThat(proxy1.getProxyMode(), equalTo(ProxyMode.BLOCKED_MANUAL));
    waitForRoutingBackgroundUpdates();

    // let's check states

    {
      // proxy1
      final RoutingStatus proxy1status = wm.getStatusFor(proxy1);
      // this repo is Out of Service
      assertThat(proxy1status.getPublishingStatus().getStatus(), equalTo(PStatus.NOT_PUBLISHED));
      assertThat(
          proxy1status.getDiscoveryStatus().getStatus(), equalTo(DStatus.ENABLED_NOT_POSSIBLE));
      assertThat(proxy1status.getDiscoveryStatus().getLastDiscoveryStrategy(), is("none"));
      // Remark: the combination of those three above simply means "discovery never tried against
      // it"
      // yet.
    }

    {
      // proxy2
      final RoutingStatus proxy2status =
          wm.getStatusFor(
              getRepositoryRegistry()
                  .getRepositoryWithFacet(PROXY2_REPO_ID, MavenProxyRepository.class));
      // this repo should be good
      assertThat(proxy2status.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED));
      assertThat(proxy2status.getDiscoveryStatus().getStatus(), equalTo(DStatus.SUCCESSFUL));
    }

    {
      // hosted
      final RoutingStatus hostedStatus =
          wm.getStatusFor(
              getRepositoryRegistry()
                  .getRepositoryWithFacet(HOSTED_REPO_ID, MavenHostedRepository.class));
      // this repo should be good
      assertThat(hostedStatus.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED));
      assertThat(hostedStatus.getDiscoveryStatus().getStatus(), equalTo(DStatus.NOT_A_PROXY));
    }

    {
      // group
      final RoutingStatus groupStatus =
          wm.getStatusFor(
              getRepositoryRegistry()
                  .getRepositoryWithFacet(GROUP_REPO_ID, MavenGroupRepository.class));
      // not all members have WL, unpublished
      assertThat(groupStatus.getPublishingStatus().getStatus(), equalTo(PStatus.NOT_PUBLISHED));
      // message should refer to proxy1 as reason of not publishing group WL
      assertThat(
          groupStatus.getPublishingStatus().getLastPublishedMessage(),
          containsString(proxy1.getName()));
      assertThat(groupStatus.getDiscoveryStatus().getStatus(), equalTo(DStatus.NOT_A_PROXY));
    }
  }