Search in sources :

Example 1 with Authorization

use of com.braintreepayments.api.models.Authorization in project braintree_android by braintree.

the class VenmoUnitTest method performAppSwitch_persistsIfVaultTrue.

@Test
public void performAppSwitch_persistsIfVaultTrue() throws InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).authorization(clientToken).build();
    Venmo.authorizeAccount(fragment, true);
    SharedPreferences prefs = SharedPreferencesHelper.getSharedPreferences(fragment.getApplicationContext());
    assertTrue(prefs.getBoolean("com.braintreepayments.api.Venmo.VAULT_VENMO_KEY", false));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) SharedPreferencesHelper.clearSharedPreferences(com.braintreepayments.testutils.SharedPreferencesHelper.clearSharedPreferences) SharedPreferences(android.content.SharedPreferences) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with Authorization

use of com.braintreepayments.api.models.Authorization in project braintree_android by braintree.

the class VenmoUnitTest method onActivityResult_withFailedVaultCall_postsCallbackToErrorListener.

@Test
public void onActivityResult_withFailedVaultCall_postsCallbackToErrorListener() throws InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).authorization(clientToken).sessionId("session-id").errorResponse(new AuthorizationException("Bad fingerprint")).build();
    ArgumentCaptor<Exception> responseCaptor = ArgumentCaptor.forClass(Exception.class);
    Venmo.authorizeAccount(fragment, true);
    Intent responseIntent = new Intent().putExtra(Venmo.EXTRA_PAYMENT_METHOD_NONCE, "nonce");
    Venmo.onActivityResult(fragment, Activity.RESULT_OK, responseIntent);
    verify(fragment).postCallback(responseCaptor.capture());
    Exception exception = responseCaptor.getValue();
    assertTrue(exception instanceof AuthorizationException);
    assertEquals("Bad fingerprint", exception.getMessage());
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) Intent(android.content.Intent) AppSwitchNotAvailableException(com.braintreepayments.api.exceptions.AppSwitchNotAvailableException) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with Authorization

use of com.braintreepayments.api.models.Authorization in project braintree_android by braintree.

the class VenmoUnitTest method getLaunchIntent_doesNotContainAuthFingerprintWhenUsingTokenziationkey.

@Test
public void getLaunchIntent_doesNotContainAuthFingerprintWhenUsingTokenziationkey() throws JSONException, InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(TestTokenizationKey.TOKENIZATION_KEY);
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).authorization(clientToken).configuration(configuration).build();
    when(fragment.getSessionId()).thenReturn("a-session-id");
    when(fragment.getIntegrationType()).thenReturn("custom");
    Venmo.authorizeAccount(fragment, false);
    ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).startActivityForResult(captor.capture(), eq(BraintreeRequestCodes.VENMO));
    assertEquals("com.venmo/com.venmo.controller.SetupMerchantActivity", captor.getValue().getComponent().flattenToString());
    Bundle extras = captor.getValue().getExtras();
    assertEquals("merchant-id", extras.getString(Venmo.EXTRA_MERCHANT_ID));
    assertEquals("access-token", extras.getString(Venmo.EXTRA_ACCESS_TOKEN));
    assertEquals("environment", extras.getString(Venmo.EXTRA_ENVIRONMENT));
    JSONObject braintreeData = new JSONObject(extras.getString(Venmo.EXTRA_BRAINTREE_DATA));
    assertNull(Json.optString(braintreeData, "authorization_fingerprint", null));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with Authorization

use of com.braintreepayments.api.models.Authorization in project braintree_android by braintree.

the class VenmoUnitTest method performAppSwitch_persistsFalseIfTokenizationKeyUsed.

@Test
public void performAppSwitch_persistsFalseIfTokenizationKeyUsed() throws InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization tokenizationkey = Authorization.fromString("sandbox_tk_abcd");
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).authorization(tokenizationkey).sessionId("session-id").build();
    Venmo.authorizeAccount(fragment, true);
    SharedPreferences prefs = SharedPreferencesHelper.getSharedPreferences(fragment.getApplicationContext());
    assertFalse(prefs.getBoolean("com.braintreepayments.api.Venmo.VAULT_VENMO_KEY", true));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) SharedPreferencesHelper.clearSharedPreferences(com.braintreepayments.testutils.SharedPreferencesHelper.clearSharedPreferences) SharedPreferences(android.content.SharedPreferences) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with Authorization

use of com.braintreepayments.api.models.Authorization in project braintree_android by braintree.

the class VenmoUnitTest method performAppSwitch_appSwitchesWithVenmoLaunchIntent.

@Test
public void performAppSwitch_appSwitchesWithVenmoLaunchIntent() throws InvalidArgumentException, JSONException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).authorization(clientToken).configuration(configuration).build();
    when(fragment.getSessionId()).thenReturn("a-session-id");
    when(fragment.getIntegrationType()).thenReturn("custom");
    Venmo.authorizeAccount(fragment, false);
    ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).startActivityForResult(captor.capture(), eq(BraintreeRequestCodes.VENMO));
    assertEquals("com.venmo/com.venmo.controller.SetupMerchantActivity", captor.getValue().getComponent().flattenToString());
    Bundle extras = captor.getValue().getExtras();
    assertEquals("merchant-id", extras.getString(Venmo.EXTRA_MERCHANT_ID));
    assertEquals("access-token", extras.getString(Venmo.EXTRA_ACCESS_TOKEN));
    assertEquals("environment", extras.getString(Venmo.EXTRA_ENVIRONMENT));
    JSONObject braintreeData = new JSONObject(extras.getString(Venmo.EXTRA_BRAINTREE_DATA));
    JSONObject meta = braintreeData.getJSONObject("_meta");
    assertNotNull(meta);
    assertEquals(fragment.getSessionId(), meta.getString("sessionId"));
    assertEquals(fragment.getIntegrationType(), meta.getString("integration"));
    assertEquals(BuildConfig.VERSION_NAME, meta.getString("version"));
    assertEquals("android", meta.getString("platform"));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Authorization (com.braintreepayments.api.models.Authorization)17 Configuration (com.braintreepayments.api.models.Configuration)14 Test (org.junit.Test)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Intent (android.content.Intent)9 Bundle (android.os.Bundle)5 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)4 SharedPreferences (android.content.SharedPreferences)3 SharedPreferencesHelper.clearSharedPreferences (com.braintreepayments.testutils.SharedPreferencesHelper.clearSharedPreferences)3 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 FragmentManager (android.app.FragmentManager)1 Context (android.content.Context)1 AppSwitchNotAvailableException (com.braintreepayments.api.exceptions.AppSwitchNotAvailableException)1 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)1 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)1 VenmoAccountBuilder (com.braintreepayments.api.models.VenmoAccountBuilder)1 VenmoAccountNonce (com.braintreepayments.api.models.VenmoAccountNonce)1 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)1