Search in sources :

Example 1 with HttpProxyServer

use of org.littleshoot.proxy.HttpProxyServer in project camel by apache.

the class SftpSimpleProduceThroughProxyTest method testSftpSimpleTwoSubPathProduceThroughProxy.

@Test
public void testSftpSimpleTwoSubPathProduceThroughProxy() throws Exception {
    if (!canTest()) {
        return;
    }
    // start http proxy
    HttpProxyServer proxyServer = new DefaultHttpProxyServer(proxyPort);
    proxyServer.addProxyAuthenticationHandler(new ProxyAuthorizationHandler() {

        @Override
        public boolean authenticate(String userName, String password) {
            return "user".equals(userName) && "password".equals(password);
        }
    });
    proxyServer.start();
    template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "/mysub/myother?username=admin&password=admin&proxy=#proxy", "Farewell World", Exchange.FILE_NAME, "farewell.txt");
    File file = new File(FTP_ROOT_DIR + "/mysub/myother/farewell.txt");
    assertTrue("File should exist: " + file, file.exists());
    assertEquals("Farewell World", context.getTypeConverter().convertTo(String.class, file));
    proxyServer.stop();
}
Also used : DefaultHttpProxyServer(org.littleshoot.proxy.DefaultHttpProxyServer) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) ProxyAuthorizationHandler(org.littleshoot.proxy.ProxyAuthorizationHandler) DefaultHttpProxyServer(org.littleshoot.proxy.DefaultHttpProxyServer) File(java.io.File) Test(org.junit.Test)

Example 2 with HttpProxyServer

use of org.littleshoot.proxy.HttpProxyServer in project camel by apache.

the class SftpSimpleConsumeThroughProxyTest method testSftpSimpleConsumeThroughProxy.

@Test
public void testSftpSimpleConsumeThroughProxy() throws Exception {
    if (!canTest()) {
        return;
    }
    // start http proxy
    HttpProxyServer proxyServer = new DefaultHttpProxyServer(proxyPort);
    proxyServer.addProxyAuthenticationHandler(new ProxyAuthorizationHandler() {

        @Override
        public boolean authenticate(String userName, String password) {
            return "user".equals(userName) && "password".equals(password);
        }
    });
    proxyServer.start();
    String expected = "Hello World";
    // create file using regular file
    template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, expected, Exchange.FILE_NAME, "hello.txt");
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt");
    mock.expectedBodiesReceived(expected);
    context.startRoute("foo");
    assertMockEndpointsSatisfied();
    proxyServer.stop();
}
Also used : DefaultHttpProxyServer(org.littleshoot.proxy.DefaultHttpProxyServer) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ProxyAuthorizationHandler(org.littleshoot.proxy.ProxyAuthorizationHandler) DefaultHttpProxyServer(org.littleshoot.proxy.DefaultHttpProxyServer) Test(org.junit.Test)

Example 3 with HttpProxyServer

use of org.littleshoot.proxy.HttpProxyServer in project jackrabbit by apache.

the class ConnectionTest method testObtainViaProxy.

public void testObtainViaProxy() throws URISyntaxException, RepositoryException {
    HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(// use arbitrary port
    0).start();
    try {
        Map<String, String> parameters = new HashMap<>();
        ConnectionOptions.Builder builder = ConnectionOptions.builder();
        builder.proxyHost("127.0.0.1");
        builder.proxyPort(proxyServer.getListenAddress().getPort());
        parameters.putAll(builder.build().toServiceFactoryParameters());
        RepositoryService repositoryService = createRepositoryService(false, parameters);
        repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
    } finally {
        proxyServer.stop();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) DefaultHttpProxyServer(org.littleshoot.proxy.impl.DefaultHttpProxyServer) HashMap(java.util.HashMap) RepositoryService(org.apache.jackrabbit.spi.RepositoryService)

Example 4 with HttpProxyServer

use of org.littleshoot.proxy.HttpProxyServer in project jackrabbit by apache.

the class ConnectionTest method testObtainViaProxyWithInvalidCredentials.

public void testObtainViaProxyWithInvalidCredentials() throws URISyntaxException, RepositoryException {
    ProxyAuthenticator authenticator = new ProxyAuthenticator() {

        @Override
        public String getRealm() {
            return null;
        }

        @Override
        public boolean authenticate(String userName, String password) {
            return false;
        }
    };
    HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(// use arbitrary port
    0).withProxyAuthenticator(authenticator).start();
    try {
        Map<String, String> parameters = new HashMap<>();
        ConnectionOptions.Builder builder = ConnectionOptions.builder();
        builder.proxyHost("127.0.0.1");
        builder.proxyPort(proxyServer.getListenAddress().getPort());
        builder.proxyUsername("test");
        builder.proxyPassword("invalid");
        parameters.putAll(builder.build().toServiceFactoryParameters());
        RepositoryService repositoryService = createRepositoryService(false, parameters);
        try {
            repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
            fail("should have failed with proxy authentication failure!");
        } catch (RepositoryException expected) {
        }
    } finally {
        proxyServer.stop();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) DefaultHttpProxyServer(org.littleshoot.proxy.impl.DefaultHttpProxyServer) ProxyAuthenticator(org.littleshoot.proxy.ProxyAuthenticator) HashMap(java.util.HashMap) RepositoryException(javax.jcr.RepositoryException) RepositoryService(org.apache.jackrabbit.spi.RepositoryService)

Example 5 with HttpProxyServer

use of org.littleshoot.proxy.HttpProxyServer in project azure-iot-sdk-java by Azure.

the class GetTwinTests method testGetDeviceTwinWithProxy.

@Test
@StandardTierHubOnlyTest
public void testGetDeviceTwinWithProxy() throws IOException, InterruptedException, IotHubException, GeneralSecurityException, ModuleClientException, URISyntaxException {
    if (testInstance.protocol != IotHubClientProtocol.MQTT || testInstance.authenticationType != AuthenticationType.SAS || testInstance.clientType != ClientType.DEVICE_CLIENT) {
        // when the device is using MQTT with SAS auth
        return;
    }
    super.setUpNewDeviceAndModule();
    String testProxyHostname = "127.0.0.1";
    int testProxyPort = 8892;
    HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(testProxyPort).start();
    try {
        Proxy serviceSideProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(testProxyHostname, testProxyPort));
        ProxyOptions proxyOptions = new ProxyOptions(serviceSideProxy);
        DeviceTwinClientOptions options = DeviceTwinClientOptions.builder().proxyOptions(proxyOptions).build();
        testInstance.twinServiceClient = DeviceTwin.createFromConnectionString(iotHubConnectionString, options);
        super.testGetDeviceTwin();
    } finally {
        proxyServer.stop();
    }
}
Also used : DefaultHttpProxyServer(org.littleshoot.proxy.impl.DefaultHttpProxyServer) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) Proxy(java.net.Proxy) ProxyOptions(com.microsoft.azure.sdk.iot.service.ProxyOptions) InetSocketAddress(java.net.InetSocketAddress) DeviceTwinClientOptions(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinClientOptions) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test)

Aggregations

HttpProxyServer (org.littleshoot.proxy.HttpProxyServer)9 Test (org.junit.Test)6 DefaultHttpProxyServer (org.littleshoot.proxy.impl.DefaultHttpProxyServer)5 DefaultHttpProxyServer (org.littleshoot.proxy.DefaultHttpProxyServer)4 ProxyAuthorizationHandler (org.littleshoot.proxy.ProxyAuthorizationHandler)4 File (java.io.File)3 HashMap (java.util.HashMap)3 SimpleCredentials (javax.jcr.SimpleCredentials)3 RepositoryService (org.apache.jackrabbit.spi.RepositoryService)3 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)2 ProxyOptions (com.microsoft.azure.sdk.iot.service.ProxyOptions)2 InetSocketAddress (java.net.InetSocketAddress)2 Proxy (java.net.Proxy)2 ProxyAuthenticator (org.littleshoot.proxy.ProxyAuthenticator)2 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)2 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)2 DeviceMethodClientOptions (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethodClientOptions)1 DeviceTwinClientOptions (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinClientOptions)1 RepositoryException (javax.jcr.RepositoryException)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1