Search in sources :

Example 1 with ServerDTO

use of aQute.bnd.connection.settings.ServerDTO in project bnd by bndtools.

the class HttpClientProxyTest method assertSocks5Proxy.

@SuppressWarnings("resource")
void assertSocks5Proxy(String password, boolean authenticationCalled) throws MalformedURLException, Exception {
    Processor p = new Processor();
    p.setProperty("-connectionsettings", "" + false);
    HttpClient hc = new HttpClient();
    ConnectionSettings cs = new ConnectionSettings(p, hc);
    if (socks5Proxy != null) {
        ProxyDTO proxy = new ProxyDTO();
        proxy.active = true;
        proxy.host = "localhost";
        proxy.port = socksProxyPort;
        proxy.protocol = Type.SOCKS;
        if (password != null) {
            proxy.username = "proxyuser";
            proxy.password = password;
        }
        hc.addProxyHandler(ConnectionSettings.createProxyHandler(proxy));
    }
    ServerDTO server = new ServerDTO();
    server.id = httpTestServer.getBaseURI().toString();
    server.verify = false;
    server.trust = Strings.join(httpTestServer.getTrustedCertificateFiles(IO.getFile("generated")));
    cs.add(server);
    URL url = new URL(httpTestServer.getBaseURI() + "/get-tag/ABCDEFGH");
    TaggedData tag = hc.connectTagged(url);
    assertNotNull(tag);
    assertEquals("ABCDEFGH", tag.getTag());
    String s = IO.collect(tag.getInputStream());
    assertNotNull(s);
    assertTrue(s.trim().startsWith("{"));
// assertTrue(this.authenticationCalled.get() == authenticationCalled);
}
Also used : ProxyDTO(aQute.bnd.connection.settings.ProxyDTO) ServerDTO(aQute.bnd.connection.settings.ServerDTO) Processor(aQute.bnd.osgi.Processor) HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData) ConnectionSettings(aQute.bnd.connection.settings.ConnectionSettings) URL(java.net.URL)

Example 2 with ServerDTO

use of aQute.bnd.connection.settings.ServerDTO in project bnd by bndtools.

the class HttpClientProxyTest method assertHttpProxy.

@SuppressWarnings("resource")
void assertHttpProxy(String password, boolean authenticationCalled) throws MalformedURLException, Exception {
    Processor p = new Processor();
    p.setProperty("-connectionsettings", "" + false);
    HttpClient hc = new HttpClient();
    ConnectionSettings cs = new ConnectionSettings(p, hc);
    if (httpProxy != null) {
        ProxyDTO proxy = new ProxyDTO();
        proxy.active = true;
        proxy.host = "localhost";
        proxy.port = httpProxyPort;
        proxy.protocol = Type.HTTP;
        if (password != null) {
            proxy.username = "proxyuser";
            proxy.password = password;
        }
        hc.addProxyHandler(ConnectionSettings.createProxyHandler(proxy));
    }
    ServerDTO server = new ServerDTO();
    server.id = httpTestServer.getBaseURI().toString();
    server.verify = false;
    server.trust = Strings.join(httpTestServer.getTrustedCertificateFiles(IO.getFile("generated")));
    cs.add(server);
    URL url = new URL(httpTestServer.getBaseURI() + "/get-tag/ABCDEFGH");
    TaggedData tag = hc.connectTagged(url);
    assertNotNull(tag);
    if (tag.getState() != State.OTHER)
        assertEquals("ABCDEFGH", tag.getTag());
    String s = IO.collect(tag.getInputStream());
    assertNotNull(s);
    assertTrue(s.trim().startsWith("{"));
    assertTrue(this.authenticationCalled.get() == authenticationCalled);
}
Also used : ProxyDTO(aQute.bnd.connection.settings.ProxyDTO) ServerDTO(aQute.bnd.connection.settings.ServerDTO) Processor(aQute.bnd.osgi.Processor) HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData) ConnectionSettings(aQute.bnd.connection.settings.ConnectionSettings) URL(java.net.URL)

Example 3 with ServerDTO

use of aQute.bnd.connection.settings.ServerDTO in project bnd by bndtools.

the class SettingsParserTest method testMavenEncryptedPassword.

public void testMavenEncryptedPassword() throws Exception {
    System.setProperty(ConnectionSettings.M2_SETTINGS_SECURITY_PROPERTY, "testresources/settings-security.xml");
    Processor proc = new Processor();
    proc.setProperty("-connection-settings", "testresources/server-maven-encrypted-selection.xml");
    try (ConnectionSettings cs = new ConnectionSettings(proc, new HttpClient())) {
        cs.readSettings();
        List<ServerDTO> serverDTOs = cs.getServerDTOs();
        assertEquals(1, serverDTOs.size());
        ServerDTO s = serverDTOs.get(0);
        assertEquals("encrypted-password", s.id);
        assertEquals("FOOBAR", s.password);
    }
}
Also used : ServerDTO(aQute.bnd.connection.settings.ServerDTO) Processor(aQute.bnd.osgi.Processor) HttpClient(aQute.bnd.http.HttpClient) ConnectionSettings(aQute.bnd.connection.settings.ConnectionSettings)

Example 4 with ServerDTO

use of aQute.bnd.connection.settings.ServerDTO in project bnd by bndtools.

the class SettingsParserTest method testServerSelection.

public void testServerSelection() throws Exception {
    SettingsDTO settings = getSettings("server-selection.xml");
    assertEquals(1, settings.servers.size());
    ServerDTO p = settings.servers.get(0);
    assertEquals("httpbin.org", p.id);
    assertEquals(null, p.passphrase);
    assertEquals(null, p.privateKey);
    assertEquals("user", p.username);
    assertEquals("passwd", p.password);
}
Also used : ServerDTO(aQute.bnd.connection.settings.ServerDTO) SettingsDTO(aQute.bnd.connection.settings.SettingsDTO)

Example 5 with ServerDTO

use of aQute.bnd.connection.settings.ServerDTO in project bnd by bndtools.

the class HttpClientServerTest method assertOk.

@SuppressWarnings("resource")
private void assertOk(String password, boolean verify) throws Exception {
    File log = new File(tmp, "log");
    Processor p = new Processor();
    p.setProperty("-connection-log", log.toURI().getPath());
    HttpClient hc = new HttpClient();
    hc.setLog(log);
    ConnectionSettings cs = new ConnectionSettings(p, hc);
    ServerDTO server = new ServerDTO();
    server.id = httpServer.getBaseURI().toString();
    server.verify = verify;
    if (password != null) {
        server.username = "user";
        server.password = password;
    }
    server.trust = Strings.join(httpServer.getTrustedCertificateFiles(IO.getFile("generated")));
    cs.add(server);
    System.out.println(httpServer.getBaseURI());
    URL url = password == null ? new URL(httpServer.getBaseURI() + "/get") : new URL(httpServer.getBaseURI() + "/basic-auth/user/good");
    TaggedData tag = hc.connectTagged(url);
    assertNotNull(tag);
    String s = IO.collect(tag.getInputStream());
    assertNotNull(s);
    assertTrue(s.trim().startsWith("{"));
    IO.copy(log, System.out);
}
Also used : ServerDTO(aQute.bnd.connection.settings.ServerDTO) Processor(aQute.bnd.osgi.Processor) HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData) File(java.io.File) ConnectionSettings(aQute.bnd.connection.settings.ConnectionSettings) URL(java.net.URL)

Aggregations

ServerDTO (aQute.bnd.connection.settings.ServerDTO)6 ConnectionSettings (aQute.bnd.connection.settings.ConnectionSettings)4 HttpClient (aQute.bnd.http.HttpClient)4 Processor (aQute.bnd.osgi.Processor)4 TaggedData (aQute.bnd.service.url.TaggedData)3 URL (java.net.URL)3 ProxyDTO (aQute.bnd.connection.settings.ProxyDTO)2 SettingsDTO (aQute.bnd.connection.settings.SettingsDTO)2 File (java.io.File)1