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));
}
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));
}
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);
}
}
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));
}
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()));
}
Aggregations