com.squareup.okhttp.mockwebserver.RecordedRequest Java Examples

The following examples show how to use com.squareup.okhttp.mockwebserver.RecordedRequest. 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: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldSendSMSCode() throws Exception {
    mockAPI.willReturnSuccessfulPasswordlessStart();

    final MockAuthenticationCallback<Void> callback = new MockAuthenticationCallback<>();
    client.passwordlessWithSMS("+1123123123", PasswordlessType.CODE)
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/passwordless/start"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("phone_number", "+1123123123"));
    assertThat(body, hasEntry("send", "code"));
    assertThat(body, hasEntry("connection", "sms"));

    assertThat(callback, hasNoError());
}
 
Example #2
Source File: JacksonRequestTest.java    From jus with Apache License 2.0 6 votes vote down vote up
@Test
public void anImplementation() throws IOException, InterruptedException, ExecutionException {
    server.enqueue(new MockResponse().setBody("{\"theName\":\"value\"}"));
    JacksonRequest<AnImplementation> request = new JacksonRequest<AnImplementation>
            (Request.Method.POST, server.url("").toString(), mapper, AnImplementation.class)
            .setRequestData(new AnImplementation("value"));

    AnImplementation body = queue.add(request).getFuture().get();

    assertThat(body.theName).isEqualTo("value");

    RecordedRequest sRequest = server.takeRequest();
    // TODO figure out how to get Jackson to stop using AnInterface's serializer here.
    assertThat(sRequest.getBody().readUtf8()).isEqualTo("{\"name\":\"value\"}");
    assertThat(sRequest.getHeader("Accept")).isEqualTo("application/json");
    assertThat(sRequest.getHeader("Content-Type")).isEqualTo("application/json; charset=UTF-8");
}
 
Example #3
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldRevokeTokenSync() throws Exception {
    Auth0 auth0 = new Auth0(CLIENT_ID, mockAPI.getDomain(), mockAPI.getDomain());
    AuthenticationAPIClient client = new AuthenticationAPIClient(auth0);

    mockAPI.willReturnSuccessfulEmptyBody();
    client.revokeToken("refreshToken")
            .execute();

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/oauth/revoke"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("token", "refreshToken"));
}
 
Example #4
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldSendEmailCode() throws Exception {
    mockAPI.willReturnSuccessfulPasswordlessStart();

    final MockAuthenticationCallback<Void> callback = new MockAuthenticationCallback<>();
    client.passwordlessWithEmail(SUPPORT_AUTH0_COM, PasswordlessType.CODE)
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/passwordless/start"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("email", SUPPORT_AUTH0_COM));
    assertThat(body, hasEntry("send", "code"));
    assertThat(body, hasEntry("connection", "email"));

    assertThat(callback, hasNoError());
}
 
Example #5
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldSendSMSLinkSync() throws Exception {
    mockAPI.willReturnSuccessfulPasswordlessStart();

    client.passwordlessWithSMS("+1123123123", PasswordlessType.WEB_LINK)
            .execute();

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/passwordless/start"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("phone_number", "+1123123123"));
    assertThat(body, hasEntry("send", "link"));
    assertThat(body, hasEntry("connection", "sms"));
}
 
Example #6
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldRequestChangePassword() throws Exception {
    mockAPI.willReturnSuccessfulChangePassword();

    final MockAuthenticationCallback<Void> callback = new MockAuthenticationCallback<>();
    client.resetPassword(SUPPORT_AUTH0_COM, MY_CONNECTION)
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/dbconnections/change_password"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("email", SUPPORT_AUTH0_COM));
    assertThat(body, not(hasKey("username")));
    assertThat(body, not(hasKey("password")));
    assertThat(body, hasEntry("connection", MY_CONNECTION));

    assertThat(callback, hasNoError());
}
 
Example #7
Source File: GsonRequestTest.java    From jus with Apache License 2.0 6 votes vote down vote up
@Test
public void anImplementation() throws IOException, InterruptedException, ExecutionException {
    server.enqueue(new MockResponse().setBody("{\"theName\":\"value\"}"));

    GsonRequest<AnImplementation> request =
            new GsonRequest<AnImplementation>(Request.Method.POST,
                    server.url("").toString(), AnImplementation.class)
                    .setRequestData(new AnImplementation("value"), gson);

    AnImplementation body = queue.add(request)
            .getFuture().get();

    assertThat(body.theName).isEqualTo("value");

    RecordedRequest sRequest = server.takeRequest();
    assertThat(sRequest.getBody().readUtf8()).isEqualTo("{\"theName\":\"value\"}");
    assertThat(sRequest.getHeader("Content-Type")).isEqualTo("application/json; charset=UTF-8");
    assertThat(sRequest.getHeader("Accept")).isEqualTo("application/json");
}
 
Example #8
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldCallDelegation() throws Exception {
    mockAPI.willReturnGenericDelegationToken();

    final MockAuthenticationCallback<Map<String, Object>> callback = new MockAuthenticationCallback<>();
    client.delegation()
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/delegation"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_JWT));
    assertThat(body, hasEntry("client_id", CLIENT_ID));

    Map<String, Object> payload = new HashMap<>();
    payload.put("token", GENERIC_TOKEN);
    assertThat(callback, hasPayload(payload));
}
 
Example #9
Source File: JsonElementRequestTest.java    From jus with Apache License 2.0 6 votes vote down vote up
@Test
public void aJsonArray() throws IOException, InterruptedException, ExecutionException {
    server.enqueue(new MockResponse().setBody(
            "[{\"theName\":\"value1\"}, " +
                    "{\"theName\":\"value2\"}]"));

    JsonObjectArrayWrapper<RespWrapper> body =
            service.aJsonArray(new JsonObjectArrayWrapper()
                    .wrap(JsonArray.readFrom("[\"name\",\"value\"]").asJsonArray(),
                            ReqWrapper.class))
                    .getFuture().get();
    assertThat(body.get(0).getTheName()).isEqualTo("value1");
    assertThat(body.get(1).getTheName()).isEqualTo("value2");

    RecordedRequest request = server.takeRequest();

    assertThat(request.getBody().readUtf8()).isEqualTo("[\"name\",\"value\"]");
    assertThat(request.getHeader("Content-Type")).isEqualTo("application/json; charset=UTF-8");
    assertThat(request.getHeader("Accept")).isEqualTo("application/json");
}
 
Example #10
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldSendSMSLinkAndroidSync() throws Exception {
    mockAPI.willReturnSuccessfulPasswordlessStart();

    client.passwordlessWithSMS("+1123123123", PasswordlessType.ANDROID_LINK)
            .execute();

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/passwordless/start"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("phone_number", "+1123123123"));
    assertThat(body, hasEntry("send", "link_android"));
    assertThat(body, hasEntry("connection", "sms"));
}
 
Example #11
Source File: AuthTest.java    From jus with Apache License 2.0 6 votes vote down vote up
@Test
public void authRetryOn401Fail() throws Exception {
    server.enqueue(new MockResponse().setResponseCode(401)
            .setBody("Invalid token"));
    server.enqueue(new MockResponse().setResponseCode(401)
            .setBody("Invalid token"));
    try {
        queue.add(new StringRequest("POST", server.url("/").toString())
                .setRequestBody("try me!")).getFuture().get();
        fail("Must not retry 2 times");
    } catch (Exception ex) {
        assertThat(ex).hasCauseExactlyInstanceOf(AuthError.class);
    }
    RecordedRequest request = server.takeRequest();

    assertThat(request.getBody().readByteString().utf8()).isEqualTo("try me!");

    server.shutdown();
}
 
Example #12
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldLoginWithUserAndPasswordSync() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    final Credentials credentials = client
            .login(SUPPORT_AUTH0_COM, "voidpassword", MY_CONNECTION)
            .execute();

    assertThat(credentials, is(notNullValue()));

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("connection", MY_CONNECTION));
    assertThat(body, not(hasKey("realm")));
}
 
Example #13
Source File: WaspTest.java    From wasp with Apache License 2.0 6 votes vote down vote up
@Test
public void syncGetForFailure() throws Exception {
  server.enqueue(new MockResponse().setStatus("404"));

  MyApiSync myApi = new Wasp.Builder(context)
      .setEndpoint(server.url("/v1").toString())
      .setNetworkStack(VolleyNetworkStack.newInstance(requestQueue))
      .build()
      .create(MyApiSync.class);

  try {
    myApi.getUser();
    fail();
  } catch (Exception e) {
    //TODO add WaspError
    // assertThat(e).isInstanceOf(WaspError.class);
    assertTrue(e.getMessage(), true);
  }

  RecordedRequest request = server.takeRequest();
  assertThat(request.getPath()).isEqualTo("/v1/user");

  verify(executor).execute(any(Runnable.class));
  verifyNoMoreInteractions(executor);
}
 
Example #14
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldLoginWithUserAndPasswordUsingOAuthTokenEndpoint() throws Exception {
    mockAPI.willReturnSuccessfulLogin();
    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();

    client.login(SUPPORT_AUTH0_COM, "some-password")
            .start(callback);
    assertThat(callback, hasPayloadOfType(Credentials.class));

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getPath(), is("/oauth/token"));
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("grant_type", "password"));
    assertThat(body, hasEntry("username", SUPPORT_AUTH0_COM));
    assertThat(body, hasEntry("password", "some-password"));
    assertThat(body, not(hasKey("realm")));
    assertThat(body, not(hasKey("connection")));
    assertThat(body, not(hasKey("scope")));
    assertThat(body, not(hasKey("audience")));
}
 
Example #15
Source File: UsersAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldLinkAccountSync() throws Exception {
    mockAPI.willReturnSuccessfulLink();

    final List<UserIdentity> result = client.link(USER_ID_PRIMARY, TOKEN_SECONDARY)
            .execute();

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getPath(), equalTo("/api/v2/users/" + USER_ID_PRIMARY + "/identities"));

    assertThat(request.getHeader(HEADER_AUTHORIZATION), equalTo(BEARER + TOKEN_PRIMARY));
    assertThat(request.getMethod(), equalTo(METHOD_POST));
    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry(KEY_LINK_WITH, TOKEN_SECONDARY));


    TypeToken<List<UserIdentity>> typeToken = new TypeToken<List<UserIdentity>>() {
    };
    assertThat(result, TypeTokenMatcher.isA(typeToken));
    assertThat(result.size(), is(2));
}
 
Example #16
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldSendSMSLinkAndroid() throws Exception {
    mockAPI.willReturnSuccessfulPasswordlessStart();

    final MockAuthenticationCallback<Void> callback = new MockAuthenticationCallback<>();
    client.passwordlessWithSMS("+1123123123", PasswordlessType.ANDROID_LINK)
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/passwordless/start"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("phone_number", "+1123123123"));
    assertThat(body, hasEntry("send", "link_android"));
    assertThat(body, hasEntry("connection", "sms"));

    assertThat(callback, hasNoError());
}
 
Example #17
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldFetchTokenInfoSync() throws Exception {
    mockAPI.willReturnTokenInfo();

    final UserProfile profile = client
            .tokenInfo("ID_TOKEN")
            .execute();

    assertThat(profile, is(notNullValue()));

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/tokeninfo"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("id_token", "ID_TOKEN"));
}
 
Example #18
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldCreateUserWithoutUsernameSync() throws Exception {
    mockAPI.willReturnSuccessfulSignUp();

    final DatabaseUser user = client
            .createUser(SUPPORT_AUTH0_COM, PASSWORD, MY_CONNECTION)
            .execute();

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/dbconnections/signup"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("email", SUPPORT_AUTH0_COM));
    assertThat(body, not(hasKey("username")));
    assertThat(body, hasEntry("password", PASSWORD));
    assertThat(body, hasEntry("connection", MY_CONNECTION));

    assertThat(user, is(notNullValue()));
}
 
Example #19
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldCreateUserWithoutUsername() throws Exception {
    mockAPI.willReturnSuccessfulSignUp();

    final MockAuthenticationCallback<DatabaseUser> callback = new MockAuthenticationCallback<>();
    client.createUser(SUPPORT_AUTH0_COM, PASSWORD, MY_CONNECTION)
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/dbconnections/signup"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("email", SUPPORT_AUTH0_COM));
    assertThat(body, not(hasKey("username")));
    assertThat(body, hasEntry("password", PASSWORD));
    assertThat(body, hasEntry("connection", MY_CONNECTION));

    assertThat(callback, hasPayloadOfType(DatabaseUser.class));
}
 
Example #20
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldLoginWithNativeSocialToken() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.loginWithNativeSocialToken("test-token-value", "test-token-type")
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/oauth/token"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_TOKEN_EXCHANGE));
    assertThat(body, hasEntry("subject_token", "test-token-value"));
    assertThat(body, hasEntry("subject_token_type", "test-token-type"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
Example #21
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldRenewAuthWithDelegationIfNotOIDCConformant() throws Exception {
    Auth0 auth0 = new Auth0(CLIENT_ID, mockAPI.getDomain(), mockAPI.getDomain());
    auth0.setOIDCConformant(false);
    AuthenticationAPIClient client = new AuthenticationAPIClient(auth0);

    mockAPI.willReturnSuccessfulLogin();
    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.renewAuth("refreshToken")
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/delegation"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("refresh_token", "refreshToken"));
    assertThat(body, hasEntry("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer"));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
Example #22
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldLoginWithPhoneNumberWithCustomConnectionWithOTPGrantIfOIDCConformant() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    Auth0 auth0 = new Auth0(CLIENT_ID, mockAPI.getDomain(), mockAPI.getDomain());
    auth0.setOIDCConformant(true);
    AuthenticationAPIClient client = new AuthenticationAPIClient(auth0);

    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.loginWithPhoneNumber("+10101010101", "1234", MY_CONNECTION)
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/oauth/token"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_PASSWORDLESS_OTP));
    assertThat(body, hasEntry("realm", MY_CONNECTION));
    assertThat(body, hasEntry("username", "+10101010101"));
    assertThat(body, hasEntry("otp", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
Example #23
Source File: GsonRequestTest.java    From jus with Apache License 2.0 6 votes vote down vote up
@Test
public void serializeUsesConfiguration() throws IOException, InterruptedException,
        ExecutionException {
    server.enqueue(new MockResponse().setBody("{}"));

    GsonRequest<AnImplementation> request =
            new GsonRequest<AnImplementation>(Request.Method.POST,
                    server.url("").toString(), AnImplementation.class)
                    .setRequestData(new AnImplementation(null));

    queue.add(request).getFuture().get();

    RecordedRequest sRequest = server.takeRequest();
    assertThat(sRequest.getBody().readUtf8()).isEqualTo("{}"); // Null value was not serialized.
    assertThat(sRequest.getHeader("Content-Type")).isEqualTo("application/json; charset=UTF-8");
    assertThat(sRequest.getHeader("Accept")).isEqualTo("application/json");
}
 
Example #24
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldLoginWithEmailOnlySync() throws Exception {
    mockAPI.willReturnSuccessfulLogin()
            .willReturnTokenInfo();

    final Credentials credentials = client
            .loginWithEmail(SUPPORT_AUTH0_COM, "1234")
            .execute();

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/oauth/ro"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_PASSWORD));
    assertThat(body, hasEntry("connection", "email"));
    assertThat(body, hasEntry("username", SUPPORT_AUTH0_COM));
    assertThat(body, hasEntry("password", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(credentials, is(notNullValue()));
}
 
Example #25
Source File: PubsubTest.java    From async-google-pubsub-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testListSubscriptions() throws Exception {
  final PubsubFuture<SubscriptionList> future = pubsub.listSubscriptions(PROJECT);

  final String expectedPath = BASE_PATH + "projects/" + PROJECT + "/subscriptions";

  assertThat(future.operation(), is("list subscriptions"));
  assertThat(future.method(), is("GET"));
  assertThat(future.uri(), is(server.getUrl(expectedPath).toString()));
  assertThat(future.payloadSize(), is(0L));

  final RecordedRequest request = server.takeRequest(10, SECONDS);

  assertThat(request.getMethod(), is("GET"));
  assertThat(request.getPath(), is(expectedPath));
  assertRequestHeaders(request);

  final SubscriptionList response = SubscriptionList.of(Subscription.of(PROJECT, SUBSCRIPTION_1, TOPIC_1),
                                                        Subscription.of(PROJECT, SUBSCRIPTION_2, TOPIC_2));
  server.enqueue(new MockResponse().setBody(json(response)));

  final SubscriptionList subscriptionList = future.get(10, SECONDS);
  assertThat(subscriptionList, is(response));
}
 
Example #26
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldSendEmailLinkAndroidWithCustomConnection() throws Exception {
    mockAPI.willReturnSuccessfulPasswordlessStart();

    final MockAuthenticationCallback<Void> callback = new MockAuthenticationCallback<>();
    client.passwordlessWithEmail(SUPPORT_AUTH0_COM, PasswordlessType.ANDROID_LINK, MY_CONNECTION)
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/passwordless/start"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("email", SUPPORT_AUTH0_COM));
    assertThat(body, hasEntry("send", "link_android"));
    assertThat(body, hasEntry("connection", MY_CONNECTION));

    assertThat(callback, hasNoError());
}
 
Example #27
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldLoginWithPhoneNumberWithCustomConnection() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.loginWithPhoneNumber("+10101010101", "1234", MY_CONNECTION)
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/oauth/ro"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_PASSWORD));
    assertThat(body, hasEntry("connection", MY_CONNECTION));
    assertThat(body, hasEntry("username", "+10101010101"));
    assertThat(body, hasEntry("password", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
Example #28
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldLoginWithPhoneNumber() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.loginWithPhoneNumber("+10101010101", "1234")
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/oauth/ro"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_PASSWORD));
    assertThat(body, hasEntry("connection", "sms"));
    assertThat(body, hasEntry("username", "+10101010101"));
    assertThat(body, hasEntry("password", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
Example #29
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldLoginWithPhoneNumberSync() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    final Credentials credentials = client
            .loginWithPhoneNumber("+10101010101", "1234")
            .execute();

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/oauth/ro"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_PASSWORD));
    assertThat(body, hasEntry("connection", "sms"));
    assertThat(body, hasEntry("username", "+10101010101"));
    assertThat(body, hasEntry("password", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(credentials, is(notNullValue()));
}
 
Example #30
Source File: AuthenticationAPIClientTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldLoginWithEmailOnly() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.loginWithEmail(SUPPORT_AUTH0_COM, "1234")
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/oauth/ro"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_PASSWORD));
    assertThat(body, hasEntry("connection", "email"));
    assertThat(body, hasEntry("username", SUPPORT_AUTH0_COM));
    assertThat(body, hasEntry("password", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}