Java Code Examples for okhttp3.mockwebserver.MockWebServer#useHttps()
The following examples show how to use
okhttp3.mockwebserver.MockWebServer#useHttps() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Benchmark.java From jus with Apache License 2.0 | 7 votes |
private MockWebServer startServer(States.GenericState state) throws IOException { Logger.getLogger(MockWebServer.class.getName()).setLevel(Level.WARNING); MockWebServer server = new MockWebServer(); if (state.tls) { SslClient sslClient = SslClient.localhost(); server.useHttps(sslClient.socketFactory, false); server.setProtocols(state.protocols); } final MockResponse response = newResponse(state); server.setDispatcher(new Dispatcher() { @Override public MockResponse dispatch(RecordedRequest request) { return response; } }); server.start(); return server; }
Example 2
Source File: TestUtils.java From digdag with Apache License 2.0 | 6 votes |
public static MockWebServer startMockWebServer(boolean https) { try { MockWebServer server = new MockWebServer(); server.setDispatcher(new NopDispatcher()); if (https) { HandshakeCertificates handshakeCertificates = localhost(); SSLSocketFactory socketFactory = handshakeCertificates.sslSocketFactory(); server.useHttps(socketFactory, false); } server.start(0); return server; } catch (IOException e) { throw Throwables.propagate(e); } }
Example 3
Source File: DigdagClientTest.java From digdag with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { mockWebServer = new MockWebServer(); HandshakeCertificates handshakeCertificates = localhost(); SSLSocketFactory socketFactory = handshakeCertificates.sslSocketFactory(); mockWebServer.useHttps(socketFactory, false); mockWebServer.start(); client = DigdagClient.builder() .disableCertValidation(true) .ssl(true) .host(mockWebServer.getHostName()) .port(mockWebServer.getPort()) .build(); objectMapper = DigdagClient.objectMapper(); }
Example 4
Source File: TestHttpNotificationServiceSSL.java From nifi with Apache License 2.0 | 6 votes |
@Before public void startServer() throws IOException, TlsException { tempConfigFilePath = "./target/TestHttpNotificationService-config.xml"; Files.deleteIfExists(Paths.get(tempConfigFilePath)); mockWebServer = new MockWebServer(); TlsConfiguration tlsConfiguration = new TlsConfiguration("./src/test/resources/keystore.jks", "passwordpassword", null, "JKS", "./src/test/resources/truststore.jks", "passwordpassword", "JKS", CertificateUtils.getHighestCurrentSupportedTlsProtocolVersion()); final SSLContext sslContext = SslContextFactory.createSslContext(tlsConfiguration, SslContextFactory.ClientAuth.REQUIRED); mockWebServer.useHttps(sslContext.getSocketFactory(), false); String configFileOutput = CONFIGURATION_FILE_TEXT.replace("${test.server}", String.valueOf(mockWebServer.url("/"))); IOUtil.writeText(configFileOutput, new File(tempConfigFilePath)); }
Example 5
Source File: TestInsecureQueryRunner.java From presto with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() throws Exception { server = new MockWebServer(); SSLContext sslContext = buildTestSslContext(); server.useHttps(sslContext.getSocketFactory(), false); server.start(); }
Example 6
Source File: SessionAuthenticationServiceTest.java From okta-sdk-appauth-android with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mAuthStateManager = AuthStateManager.getInstance(RuntimeEnvironment.application); MockWebServer server = new MockWebServer(); dispatcher = new CustomDispatcher(); server.setDispatcher(dispatcher); SSLSocketFactory sslSocketFactory = TestUtils.getSSL(this); HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory); HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); server.useHttps(sslSocketFactory, false); server.start(); String baseUrl = server.url("/").toString(); authorizationRequest = TestUtils.getMinimalAuthRequestBuilder(baseUrl, ResponseTypeValues.CODE); mAuthService = new AuthorizationService(RuntimeEnvironment.application.getApplicationContext(), new AppAuthConfiguration.Builder().setConnectionBuilder(ConnectionBuilderForTest.INSTANCE).build()); sessionAuthenticationService = new SessionAuthenticationService(mAuthStateManager, mAuthService, new ConnectionBuilder() { @NonNull @Override public HttpURLConnection openConnection(@NonNull Uri uri) throws IOException { return DefaultOktaConnectionBuilder.INSTANCE.openConnection(uri); } }); request = authorizationRequest.build(); dispatcher.nonce = request.nonce; }
Example 7
Source File: HttpZipkinTracerIntegrationTest.java From zipkin-finagle with Apache License 2.0 | 5 votes |
MockWebServer createMockWebServerWithTLS() throws UnknownHostException { MockWebServer server = new MockWebServer(); String localhost = InetAddress.getByName("localhost").getCanonicalHostName(); HeldCertificate localhostCertificate = new HeldCertificate.Builder() .addSubjectAlternativeName(localhost) .build(); HandshakeCertificates serverCertificates = new HandshakeCertificates.Builder() .heldCertificate(localhostCertificate) .build(); server.useHttps(serverCertificates.sslSocketFactory(), false); return server; }
Example 8
Source File: CliProxyEnvVarIT.java From digdag with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { httpMockServer = new MockWebServer(); httpMockServer.start(); httpsMockServer = new MockWebServer(); HandshakeCertificates handshakeCertificates = localhost(); SSLSocketFactory socketFactory = handshakeCertificates.sslSocketFactory(); httpsMockServer.useHttps(socketFactory, false); httpsMockServer.start(); httpProxy = DefaultHttpProxyServer .bootstrap() .withPort(0) .plusActivityTracker(httpProxyRequestTracker) .start(); httpProxyUrl = "http://" + httpProxy.getListenAddress().getHostString() + ":" + httpProxy.getListenAddress().getPort(); httpsProxy = DefaultHttpProxyServer .bootstrap() .withPort(0) .plusActivityTracker(httpsProxyRequestTracker) .withSslEngineSource(new SelfSignedSslEngineSource()) .withAuthenticateSslClients(false) .start(); httpsProxyUrl = "https://" + httpsProxy.getListenAddress().getHostString() + ":" + httpsProxy.getListenAddress().getPort(); }
Example 9
Source File: OkHttpUnsafe.java From xio with Apache License 2.0 | 4 votes |
public static MockWebServer getSslMockWebServer(KeyManager[] keyManagers) throws Exception { MockWebServer server = new MockWebServer(); server.useHttps( OkHttpUnsafe.getUnsafeSSLSocketFactory(keyManagers, unsafeTrustManager()), false); return server; }