Search in sources :

Example 16 with HttpTestServer

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);
    }
}
Also used : HttpTestServer(aQute.http.testservers.HttpTestServer) URL(java.net.URL)

Example 17 with HttpTestServer

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());
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HttpTestServer(aQute.http.testservers.HttpTestServer) URL(java.net.URL)

Example 18 with HttpTestServer

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());
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HttpTestServer(aQute.http.testservers.HttpTestServer) URL(java.net.URL)

Example 19 with HttpTestServer

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;
}
Also used : HttpTestServer(aQute.http.testservers.HttpTestServer)

Example 20 with HttpTestServer

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();
    }
}
Also used : InputStream(java.io.InputStream) HttpClient(aQute.bnd.http.HttpClient) URLConnector(aQute.bnd.service.url.URLConnector) HttpTestServer(aQute.http.testservers.HttpTestServer) URL(java.net.URL) CloseSessionException(sockslib.server.listener.CloseSessionException) IOException(java.io.IOException) AuthenticationException(sockslib.common.AuthenticationException) Workspace(aQute.bnd.build.Workspace)

Aggregations

HttpTestServer (aQute.http.testservers.HttpTestServer)22 URL (java.net.URL)10 HttpURLConnection (java.net.HttpURLConnection)7 Workspace (aQute.bnd.build.Workspace)5 FixedIndexedRepo (aQute.bnd.deployer.repository.FixedIndexedRepo)2 Repository (aQute.bnd.jpm.Repository)2 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)2 Config (aQute.http.testservers.HttpTestServer.Config)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URI (java.net.URI)2 HttpClient (aQute.bnd.http.HttpClient)1 URLConnector (aQute.bnd.service.url.URLConnector)1 Version (aQute.bnd.version.Version)1 Httpbin (aQute.http.testservers.Httpbin)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 X509Certificate (java.security.cert.X509Certificate)1 Matcher (java.util.regex.Matcher)1 GZIPInputStream (java.util.zip.GZIPInputStream)1