Search in sources :

Example 1 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class DeleteGroupMemberTest method run.

@Test
public void run() throws Exception {
    final String named = "test";
    expectRepoAutoCreation(named);
    final RemoteRepository r = client.stores().load(StoreType.remote, named, RemoteRepository.class);
    assertThat(r, notNullValue());
    Group group = new Group("group", r.getKey());
    group = client.stores().create(group, "Adding test group", Group.class);
    client.stores().delete(StoreType.remote, named, "Removing test repo");
    System.out.println("Waiting for server events to clear...");
    synchronized (this) {
        wait(3000);
    }
    final StoreListingDTO<RemoteRepository> remotes = client.stores().listRemoteRepositories();
    boolean found = false;
    for (final RemoteRepository remote : remotes) {
        if (remote.getName().equals(named)) {
            found = true;
            break;
        }
    }
    assertThat(found, equalTo(false));
    group = client.stores().load(StoreType.group, group.getName(), Group.class);
    assertThat(group.getConstituents().isEmpty(), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

Example 2 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class DeleteRemoteRepoWithCachedContentTest method deleteRepoWithContent_RepoNotReCreatedWhenContentIsDeleted.

@Test
@Category(EventDependent.class)
public void deleteRepoWithContent_RepoNotReCreatedWhenContentIsDeleted() throws Exception {
    final String named = "test";
    final String path = "path/to/foo.txt";
    final String content = "This is a test";
    expectRepoAutoCreation(named);
    http.expect(http.formatUrl(named, path), 200, content);
    final InputStream stream = client.content().get(StoreType.remote, named, path);
    final String retrieved = IOUtils.toString(stream);
    stream.close();
    assertThat(retrieved, equalTo(content));
    System.out.println("Waiting for server events to clear...");
    waitForEventPropagation();
    client.stores().delete(StoreType.remote, named, "Removing test repo");
    System.out.println("Waiting for server events to clear...");
    waitForEventPropagation();
    final StoreListingDTO<RemoteRepository> remotes = client.stores().listRemoteRepositories();
    boolean found = false;
    for (final RemoteRepository remote : remotes) {
        if (remote.getName().equals(named)) {
            found = true;
            break;
        }
    }
    assertThat(found, equalTo(false));
}
Also used : InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 3 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class ProxyResponseWriter method handleEvent.

@Override
public void handleEvent(final ConduitStreamSinkChannel channel) {
    HttpConduitWrapper http = new HttpConduitWrapper(channel, httpRequest, contentController, cacheProvider);
    if (httpRequest == null) {
        if (error != null) {
            logger.debug("handling error from request reader: " + error.getMessage(), error);
            handleError(error, http);
        } else {
            logger.debug("invalid state (no error or request) from request reader. Sending 400.");
            try {
                http.writeStatus(ApplicationStatus.BAD_REQUEST);
            } catch (final IOException e) {
                logger.error("Failed to write BAD REQUEST for missing HTTP first-line to response channel.", e);
            }
        }
        return;
    }
    // TODO: Can we handle this?
    final String oldThreadName = Thread.currentThread().getName();
    Thread.currentThread().setName("PROXY-" + httpRequest.getRequestLine().toString());
    channel.getCloseSetter().set((sinkChannel) -> {
        logger.debug("sink channel closing.");
        Thread.currentThread().setName(oldThreadName);
    });
    logger.info("\n\n\n>>>>>>> Handle write\n\n\n\n\n");
    if (error == null) {
        try {
            final UserPass proxyUserPass = UserPass.parse(ApplicationHeader.proxy_authorization, httpRequest, null);
            logger.debug("Proxy UserPass: {}\nConfig secured? {}\nConfig tracking type: {}", proxyUserPass, config.isSecured(), config.getTrackingType());
            if (proxyUserPass == null && (config.isSecured() || TrackingType.ALWAYS == config.getTrackingType())) {
                http.writeStatus(ApplicationStatus.PROXY_AUTHENTICATION_REQUIRED);
                http.writeHeader(ApplicationHeader.proxy_authenticate, String.format(PROXY_AUTHENTICATE_FORMAT, config.getProxyRealm()));
            } else {
                RequestLine requestLine = httpRequest.getRequestLine();
                String method = requestLine.getMethod().toUpperCase();
                switch(method) {
                    case GET_METHOD:
                    case HEAD_METHOD:
                        {
                            if (proxyUserPass != null) {
                                logger.debug("Passing BASIC authentication credentials to Keycloak bearer-token translation authenticator");
                                if (!proxyAuthenticator.authenticate(proxyUserPass, http)) {
                                    break;
                                }
                            }
                            final URL url = new URL(requestLine.getUri());
                            final RemoteRepository repo = getRepository(url);
                            transfer(http, repo, url.getPath(), GET_METHOD.equals(method), proxyUserPass);
                            break;
                        }
                    case OPTIONS_METHOD:
                        {
                            http.writeStatus(ApplicationStatus.OK);
                            http.writeHeader(ApplicationHeader.allow, ALLOW_HEADER_VALUE);
                            break;
                        }
                    default:
                        {
                            http.writeStatus(ApplicationStatus.METHOD_NOT_ALLOWED);
                        }
                }
            }
            logger.info("Response complete.");
        } catch (final Throwable e) {
            error = e;
        }
    }
    if (error != null) {
        handleError(error, http);
    }
    try {
        http.close();
    } catch (final IOException e) {
        logger.error("Failed to flush/shutdown response.", e);
    }
}
Also used : RequestLine(org.apache.http.RequestLine) HttpConduitWrapper(org.commonjava.indy.httprox.util.HttpConduitWrapper) UserPass(org.commonjava.indy.subsys.http.util.UserPass) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IOException(java.io.IOException) URL(java.net.URL)

Example 4 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class UseChecksumFromTransferDecoratorForTrackingRecordTest method run.

@BMRules(rules = { @BMRule(name = "setup_metadata_countdown", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "<init>", targetLocation = "ENTRY", action = "System.out.println(\"SETUP COUNTDOWN\"); createCountDown(\"COUNTDOWN\", 1);"), @BMRule(name = "prevent_successive_metadata_additions", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "addMetadata", targetLocation = "ENTRY", binding = "path:String = $1.getPath();", condition = "path.endsWith(\"path/to/foo.class\") && countDown(\"COUNTDOWN\")", action = "System.out.println(\"RETURN NULL\"); return null;") })
@Test
public void run() throws Exception {
    final String trackingId = newName();
    final String repoId = "repo";
    final String path = "/path/to/foo.class";
    final InputStream stream = new ByteArrayInputStream("This is a test with the same content each time.".getBytes());
    server.expect(server.formatUrl(repoId, path), 200, stream);
    RemoteRepository rr = new RemoteRepository(repoId, server.formatUrl(repoId));
    rr = client.stores().create(rr, "adding test remote", RemoteRepository.class);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final InputStream in = client.module(IndyFoloContentClientModule.class).get(trackingId, remote, repoId, path);
    IOUtils.copy(in, baos);
    in.close();
    final byte[] bytes = baos.toByteArray();
    final String md5 = md5Hex(bytes);
    final String sha256 = sha256Hex(bytes);
    assertThat(md5, equalTo(DigestUtils.md5Hex(bytes)));
    assertThat(sha256, equalTo(DigestUtils.sha256Hex(bytes)));
    waitForEventPropagation();
    assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true));
    final TrackedContentDTO report = client.module(IndyFoloAdminClientModule.class).getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    final Set<TrackedContentEntryDTO> downloads = report.getDownloads();
    assertThat(downloads, notNullValue());
    assertThat(downloads.size(), equalTo(1));
    final TrackedContentEntryDTO entry = downloads.iterator().next();
    System.out.println(entry);
    assertThat(entry, notNullValue());
    assertThat(entry.getStoreKey(), equalTo(new StoreKey(remote, repoId)));
    assertThat(entry.getPath(), equalTo(path));
    assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(remote, repoId, path)));
    assertThat(entry.getOriginUrl(), equalTo(server.formatUrl(repoId, path)));
    assertThat(entry.getMd5(), equalTo(md5));
    assertThat(entry.getSha256(), equalTo(sha256));
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) BytemanTest(org.commonjava.indy.ftest.core.category.BytemanTest) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 5 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class Propagate404NotFoundTest method run.

@Test
public void run() throws Exception {
    final String testRepo = "test";
    final String url = server.formatUrl(testRepo, "org/test/foo/1/foo-1.pom");
    final HttpGet get = new HttpGet(url);
    final CloseableHttpClient client = proxiedHttp();
    CloseableHttpResponse response = null;
    final InputStream stream = null;
    try {
        response = client.execute(get, proxyContext(USER, PASS));
        assertThat(response.getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_NOT_FOUND));
    } finally {
        IOUtils.closeQuietly(stream);
        HttpResources.cleanupResources(get, response, client);
    }
    final RemoteRepository remoteRepo = this.client.stores().load(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, "httprox_127-0-0-1_" + server.getPort()), RemoteRepository.class);
    assertThat(remoteRepo, notNullValue());
    assertThat(remoteRepo.getUrl(), equalTo(server.getBaseUri()));
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Aggregations

RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)149 Test (org.junit.Test)99 InputStream (java.io.InputStream)52 Group (org.commonjava.indy.model.core.Group)48 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)32 StoreKey (org.commonjava.indy.model.core.StoreKey)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 File (java.io.File)17 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)17 HostedRepository (org.commonjava.indy.model.core.HostedRepository)17 PathInfo (org.commonjava.indy.client.core.helper.PathInfo)16 IndyDataException (org.commonjava.indy.data.IndyDataException)14 Before (org.junit.Before)13 Category (org.junit.experimental.categories.Category)12 Date (java.util.Date)10 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)10 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)10 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 HttpGet (org.apache.http.client.methods.HttpGet)9