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