コード例 #1
0
  /**
   * Verify that a remote answering with '403 Forbidden' will not be auto-blocked with and without a
   * local artifact cached.
   */
  @Test
  public void testNoAutoblockOn403() throws Exception {
    stopProxy();

    server = Server.withPort(proxyPort).start();

    server.serve("/").withBehaviours(content("ok"));
    server.serve("/remote/release-proxy-repo-1/nexus4593/*").withBehaviours(get(getTestFile("/")));

    downloadArtifact(GavUtil.newGav("nexus4593", "artifact", "1.0.0"), "target");

    assertThat(ProxyMode.valueOf(getStatus().getProxyMode()), is(ProxyMode.ALLOW));

    server.serve("/*").withBehaviours(error(403));

    // download will not fail because we have a local copy cached, but the remote will be hit b/c
    // maxAge is set to 0
    downloadArtifact(GavUtil.newGav("nexus4593", "artifact", "1.0.0"), "target");

    assertThat(ProxyMode.valueOf(getStatus().getProxyMode()), is(ProxyMode.ALLOW));

    try {
      downloadArtifact(GavUtil.newGav("g", "a", "403"), "target");
      assertThat("should fail b/c of 403", false);
    } catch (IOException e) {
      // expected, remote will answer with 403
    }

    assertThat(ProxyMode.valueOf(getStatus().getProxyMode()), is(ProxyMode.ALLOW));
  }
コード例 #2
0
  /** Verify that un-autoblocking a repo works when 'HEAD /' is giving 403. */
  @Test(dependsOnMethods = "testAutoblockOn401")
  public void testUnAutoblockFor403() throws Exception {
    startErrorServer(403);
    assertThat(ProxyMode.valueOf(getStatus().getProxyMode()), is(ProxyMode.BLOCKED_AUTO));

    for (int i = 0; i < 10; i++) {
      if (!ProxyMode.valueOf(getStatus().getProxyMode()).equals(ProxyMode.BLOCKED_AUTO)) {
        break;
      }
      Thread.sleep(1000);
    }

    assertThat(
        "No UnAutoblock in 10s",
        ProxyMode.valueOf(getStatus().getProxyMode()),
        is(ProxyMode.ALLOW));
  }
コード例 #3
0
  /**
   * Verify that a remote answering with '401' will still be auto-blocked.
   *
   * <p>This test will change repo status to auto blocked.
   */
  @Test(dependsOnMethods = "testNoAutoblockOn403")
  public void testAutoblockOn401() throws Exception {
    startErrorServer(401);

    try {
      downloadArtifact(GavUtil.newGav("g", "a", "401"), "target");
    } catch (IOException e) {
      // expected, remote will answer with 401
    }

    RepositoryStatusResource status = getStatus();

    assertThat(ProxyMode.valueOf(status.getProxyMode()), is(ProxyMode.BLOCKED_AUTO));
  }