-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from braintree/pwv
Pay With Venmo
- Loading branch information
Showing
51 changed files
with
1,504 additions
and
72 deletions.
There are no files selected for viewing
6 changes: 0 additions & 6 deletions
6
BraintreeApi/src/androidTest/assets/fixtures/configuration_with_null_venmo.json
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
BraintreeApi/src/androidTest/assets/fixtures/configuration_with_offline_venmo.json
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
BraintreeApi/src/androidTest/assets/fixtures/configuration_with_pay_with_venmo.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"clientApiUrl": "client_api_url", | ||
"environment": "test", | ||
"merchantId": "integration_merchant_id", | ||
"merchantAccountId": "integration_merchant_account_id", | ||
"payWithVenmo": { | ||
"accessToken" : "access-token" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
379 changes: 379 additions & 0 deletions
379
BraintreeApi/src/androidTest/java/com/braintreepayments/api/VenmoTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
...pi/src/androidTest/java/com/braintreepayments/api/internal/SignatureVerificationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.braintreepayments.api.internal; | ||
|
||
import android.os.SystemClock; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import android.test.suitebuilder.annotation.LargeTest; | ||
import android.util.Log; | ||
|
||
import com.braintreepayments.api.BuildConfig; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static android.support.test.InstrumentationRegistry.getTargetContext; | ||
import static junit.framework.Assert.assertFalse; | ||
import static junit.framework.Assert.assertTrue; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class SignatureVerificationTest { | ||
|
||
@Test(timeout = 15000) | ||
@LargeTest | ||
public void isSignatureValid_returnsFalseWhenAppNotInstalled() { | ||
if (!BuildConfig.RUN_ALL_TESTS) { | ||
return; | ||
} | ||
|
||
Log.d("request_command", "uninstall fakewallet"); | ||
SystemClock.sleep(10000); | ||
|
||
assertFalse(checkSignature()); | ||
} | ||
|
||
@Test(timeout = 65000) | ||
@LargeTest | ||
public void isSignatureValid_returnsTrueWhenAppIsInstalled() { | ||
if (!BuildConfig.RUN_ALL_TESTS) { | ||
return; | ||
} | ||
|
||
Log.d("request_command", "install fakewallet"); | ||
SystemClock.sleep(60000); | ||
|
||
assertTrue(checkSignature()); | ||
} | ||
|
||
private boolean checkSignature() { | ||
return SignatureVerification.isSignatureValid(getTargetContext(), "com.braintreepayments.fake.wallet", | ||
"CN=Android Debug,O=Android,C=US", "CN=Android Debug,O=Android,C=US", 496242318); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...c/androidTest/java/com/braintreepayments/api/internal/SignatureVerificationTestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.braintreepayments.api.internal; | ||
|
||
public class SignatureVerificationTestUtils { | ||
|
||
public static void disableSignatureVerification() { | ||
SignatureVerification.sEnableSignatureVerification = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ntreeApi/src/androidTest/java/com/braintreepayments/api/models/VenmoAccountNonceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.braintreepayments.api.models; | ||
|
||
import android.os.Parcel; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import android.test.suitebuilder.annotation.SmallTest; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@SmallTest | ||
public class VenmoAccountNonceTest { | ||
|
||
private static final String NONCE = "nonce"; | ||
private static final String DESCRIPTION = "description"; | ||
private static final String USERNAME = "username"; | ||
private static final VenmoAccountNonce | ||
VENMO_NONCE = new VenmoAccountNonce(NONCE, DESCRIPTION, USERNAME); | ||
|
||
@Test(timeout = 1000) | ||
public void getTypeLabel_returnsPayWithVenmo() { | ||
assertEquals("Venmo", VENMO_NONCE.getTypeLabel()); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void getNonce_returnsNonce() { | ||
assertEquals(NONCE, VENMO_NONCE.getNonce()); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void getDescription_returnsDescription() { | ||
assertEquals(DESCRIPTION, VENMO_NONCE.getDescription()); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void getUsername_returnsUsername() { | ||
assertEquals(USERNAME, VENMO_NONCE.getUsername()); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void writeToParcel_parcelsVenmoAccountNonce() { | ||
Parcel parcel = Parcel.obtain(); | ||
VENMO_NONCE.writeToParcel(parcel, 0); | ||
parcel.setDataPosition(0); | ||
|
||
VenmoAccountNonce venmoAccountNonce = new VenmoAccountNonce(parcel); | ||
assertEquals(NONCE, venmoAccountNonce.getNonce()); | ||
assertEquals(DESCRIPTION, venmoAccountNonce.getDescription()); | ||
assertEquals(USERNAME, venmoAccountNonce.getUsername()); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...treeApi/src/androidTest/java/com/braintreepayments/api/models/VenmoConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.braintreepayments.api.models; | ||
|
||
import android.support.test.runner.AndroidJUnit4; | ||
import android.test.mock.MockContext; | ||
import android.test.suitebuilder.annotation.SmallTest; | ||
import android.text.TextUtils; | ||
|
||
import com.braintreepayments.api.internal.SignatureVerificationTestUtils; | ||
import com.braintreepayments.testutils.MockContextForVenmo; | ||
|
||
import org.json.JSONException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static com.braintreepayments.testutils.FixturesHelper.stringFromFixture; | ||
import static junit.framework.Assert.assertEquals; | ||
import static junit.framework.Assert.assertFalse; | ||
import static junit.framework.Assert.assertTrue; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@SmallTest | ||
public class VenmoConfigurationTest { | ||
|
||
private Configuration configurationWithVenmo; | ||
|
||
@Before | ||
public void setup() throws JSONException { | ||
configurationWithVenmo = Configuration.fromJson( | ||
stringFromFixture("configuration_with_pay_with_venmo.json")); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void fromJson_parsesPayWithVenmoConfiguration() throws JSONException { | ||
assertEquals("access-token", configurationWithVenmo.getPayWithVenmo().getAccessToken()); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void fromJson_parsesEmptyVenmoConfigurationWhenConfigurationDoesntHavePayWithVenmo() | ||
throws JSONException { | ||
Configuration configuration = Configuration.fromJson( | ||
stringFromFixture("configuration.json")); | ||
|
||
VenmoConfiguration venmoConfiguration = configuration.getPayWithVenmo(); | ||
assertEquals("", venmoConfiguration.getAccessToken()); | ||
assertTrue(TextUtils.isEmpty(venmoConfiguration.getAccessToken())); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void isEnabled_returnsTrueWhenEnabled() throws JSONException { | ||
VenmoConfiguration venmoConfiguration = configurationWithVenmo.getPayWithVenmo(); | ||
assertFalse(TextUtils.isEmpty(venmoConfiguration.getAccessToken())); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void isVenmoWhitelisted_returnsTrueForWhitelist() throws JSONException { | ||
MockContext mockContext = new MockContextForVenmo() | ||
.whitelistValue("true") | ||
.build(); | ||
|
||
assertTrue(configurationWithVenmo.getPayWithVenmo() | ||
.isVenmoWhitelisted(mockContext.getContentResolver())); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void isVenmoWhitelisted_returnsFalseForInvalidWhitelist() { | ||
MockContext mockContext = new MockContextForVenmo() | ||
.whitelistValue("false") | ||
.build(); | ||
|
||
assertFalse(configurationWithVenmo.getPayWithVenmo() | ||
.isVenmoWhitelisted(mockContext.getContentResolver())); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void isVenmoWhitelisted_returnsFalseForJunkContentProviderAndExceptionIsPosted() { | ||
MockContext mockContext = new MockContextForVenmo() | ||
.whitelistValue("neither") | ||
.build(); | ||
|
||
assertFalse(configurationWithVenmo.getPayWithVenmo() | ||
.isVenmoWhitelisted(mockContext.getContentResolver())); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void isEnabled_returnsTrueWhenAppIsInstalled() throws JSONException { | ||
MockContext mockContext = new MockContextForVenmo() | ||
.whitelistValue("true") | ||
.venmoInstalled() | ||
.build(); | ||
|
||
SignatureVerificationTestUtils.disableSignatureVerification(); | ||
|
||
assertTrue(configurationWithVenmo.getPayWithVenmo().isEnabled(mockContext)); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void isEnabled_returnsFalseForNotInstalled() { | ||
MockContext mockContext = new MockContextForVenmo() | ||
.whitelistValue("true") | ||
.build(); | ||
|
||
SignatureVerificationTestUtils.disableSignatureVerification(); | ||
|
||
assertFalse(configurationWithVenmo.getPayWithVenmo().isEnabled(mockContext)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.