use of okhttp3.Credentials in project JavaSDK by OpenGamma.
the class BasicTest method testAuthGood.
public void testAuthGood() {
AuthClient mockAuth = new TestingAuthClient();
@SuppressWarnings("resource") ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS).authClientFactory(inv -> mockAuth).build();
assertEquals(invoker.getServiceUrl(), SERVICE_URL);
assertEquals(invoker.getHttpClient().interceptors().size(), 3);
assertEquals(invoker.getHttpClient().followRedirects(), true);
assertEquals(invoker.getExecutor().isShutdown(), false);
invoker.close();
assertEquals(invoker.getExecutor().isShutdown(), true);
}
use of okhttp3.Credentials in project azure-tools-for-java by Microsoft.
the class IntegrationTestBase method setUpStep.
public void setUpStep() throws Exception {
if (currentTestName == null) {
currentTestName = name.getMethodName();
} else {
throw new Exception("Setting up another test in middle of a test");
}
addTextReplacementRule(GLOBAL_ENDPOINT, MOCK_URI + "/");
ApplicationTokenCredentials credentials = new TestCredentials();
String defaultSubscription = "";
if (IS_MOCKED) {
defaultSubscription = MOCK_SUBSCRIPTION;
File recordFile = getRecordFile();
ObjectMapper mapper = new ObjectMapper();
try {
testRecord = mapper.readValue(recordFile, TestRecord.class);
} catch (Exception e) {
throw new Exception("Fail read test record: " + e.getMessage());
}
} else {
try {
credentials = ApplicationTokenCredentials.fromFile(new File(azureAuthFile));
} catch (Exception e) {
throw new Exception("Fail to open auth file:" + azureAuthFile);
}
defaultSubscription = credentials.defaultSubscriptionId();
}
interceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
if (IS_MOCKED) {
return registerRecordedResponse(chain);
} else {
return chain.proceed(chain.request());
}
}
};
restClient = createRestClient(credentials);
initialize(restClient, defaultSubscription, credentials.domain());
}
use of okhttp3.Credentials in project azure-tools-for-java by Microsoft.
the class IntegrationTestBase method setUpStep.
public void setUpStep() throws Exception {
if (currentTestName == null) {
currentTestName = name.getMethodName();
} else {
throw new Exception("Setting up another test in middle of a test");
}
addTextReplacementRule(GLOBAL_ENDPOINT, MOCK_URI + "/");
ApplicationTokenCredentials credentials = new TestCredentials();
String defaultSubscription = "";
if (IS_MOCKED) {
defaultSubscription = MOCK_SUBSCRIPTION;
File recordFile = getRecordFile();
ObjectMapper mapper = new ObjectMapper();
try {
testRecord = mapper.readValue(recordFile, TestRecord.class);
} catch (Exception e) {
throw new Exception("Fail read test record: " + e.getMessage());
}
} else {
try {
credentials = ApplicationTokenCredentials.fromFile(new File(azureAuthFile));
} catch (Exception e) {
throw new Exception("Fail to open auth file:" + azureAuthFile);
}
defaultSubscription = credentials.defaultSubscriptionId();
}
interceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
if (IS_MOCKED) {
return registerRecordedResponse(chain);
} else {
return chain.proceed(chain.request());
}
}
};
restClient = createRestClient(credentials);
initialize(restClient, defaultSubscription, credentials.domain());
}
use of okhttp3.Credentials in project java-sdk by watson-developer-cloud.
the class ErrorResponseTest method testUnauthorized.
/**
* Test HTTP status code 401 (Unauthorized) error response.
*/
@Test
public void testUnauthorized() {
String message = "The request failed because the moon is full.";
server.enqueue(new MockResponse().setResponseCode(401).addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{\"error\": \"" + message + "\"}"));
try {
GenericModel response = service.testMethod().execute();
} catch (Exception e) {
assertTrue(e instanceof UnauthorizedException);
UnauthorizedException ex = (UnauthorizedException) e;
assertEquals(401, ex.getStatusCode());
assertTrue(ex.getMessage().startsWith("Unauthorized: Access is denied due to invalid credentials."));
}
}
use of okhttp3.Credentials in project zipkin by openzipkin.
the class ITZipkinServer method shouldAllowAnyOriginByDefault.
@Test
public void shouldAllowAnyOriginByDefault() throws Exception {
Response response = client.newCall(new Request.Builder().url(url(server, "/api/v2/traces")).header("Origin", "http://foo.example.com").build()).execute();
assertThat(response.isSuccessful()).isTrue();
assertThat(response.header("vary")).isNull();
assertThat(response.header("access-control-allow-credentials")).isNull();
assertThat(response.header("access-control-allow-origin")).contains("*");
}
Aggregations