use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.
the class HttpTestServerTest method testDefault.
public void testDefault() throws Exception {
try (HttpTestServer http = getHttp()) {
URL uri = http.getBaseURI().toURL();
String s = aQute.lib.io.IO.collect(uri.openStream());
System.out.println(s);
}
}
use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.
the class HttpTestServerTest method testBasicAuth.
public void testBasicAuth() throws Exception {
try (HttpTestServer http = getHttp()) {
URL uri = new URL(http.getBaseURI() + "/basic-auth/john/doe");
HttpURLConnection hrc = (HttpURLConnection) uri.openConnection();
hrc.setRequestProperty("Authorization", "Basic " + aQute.lib.base64.Base64.encodeBase64("john:doe".getBytes("UTF-8")));
hrc.connect();
assertEquals(200, hrc.getResponseCode());
}
}
use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.
the class HttpTestServerTest method testBasicFalseAuth.
public void testBasicFalseAuth() throws Exception {
try (HttpTestServer http = getHttp()) {
URL uri = new URL(http.getBaseURI() + "/basic-auth/john/xxxxxxx");
HttpURLConnection hrc = (HttpURLConnection) uri.openConnection();
hrc.setRequestProperty("Authorization", "Basic " + aQute.lib.base64.Base64.encodeBase64("john:doe".getBytes("UTF-8")));
hrc.connect();
assertEquals(401, hrc.getResponseCode());
}
}
use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.
the class IndexedReposWithComms method http.
HttpTestServer http() throws Exception, IOException {
HttpTestServer.Config config = new HttpTestServer.Config();
config.host = "localhost";
HttpTestServer ht = new HS(config);
ht.start();
return ht;
}
use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.
the class IndexedReposWithComms method testBasicWorkspace.
public void testBasicWorkspace() throws Exception {
HttpTestServer ht = http();
try {
createSecureSocks5();
Workspace ws = Workspace.getWorkspace(aQute.lib.io.IO.getFile("workspaces/basic"));
assertNotNull(ws);
List<URLConnector> connectors = ws.getPlugins(URLConnector.class);
assertNotNull(connectors);
assertEquals(1, connectors.size());
assertTrue(connectors.get(0) instanceof HttpClient);
HttpClient hc = (HttpClient) connectors.get(0);
InputStream connect = hc.connect(new URL(ht.getBaseURI() + "/basic-auth/user/good"));
assertNotNull(connect);
aQute.lib.io.IO.copy(connect, System.out);
connect.close();
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
} finally {
ht.close();
}
}
Aggregations