diff --git a/README.md b/README.md index 4ad25e13..c0024fd0 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ allprojects { In your application `build.gradle` file, add: ```groovy -def uport_sdk_version = "v0.4.0" +def uport_sdk_version = "v0.4.1" dependencies { //... // core SDK @@ -222,6 +222,8 @@ Want to contribute to uport-android-sdk? Cool, please read our [contribution gui ## Changelog +* 0.4.1 + * maintenance release * 0.4.0 * `core` module is a simple java library (and can be used as a dependency in JVM tests) diff --git a/build.gradle b/build.gradle index ec2b71a4..6583a6da 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,7 @@ buildscript { khex_version = "0.5" tweetnacl_k_version = "0.0.1" - uport_sdk_version = "v0.4.0" + uport_sdk_version = "v0.4.1" } repositories { diff --git a/credentials/src/main/java/me/uport/sdk/credentials/EthereumTransactionRequestParams.kt b/credentials/src/main/java/me/uport/sdk/credentials/EthereumTransactionRequestParams.kt index 408b4226..c9fac723 100644 --- a/credentials/src/main/java/me/uport/sdk/credentials/EthereumTransactionRequestParams.kt +++ b/credentials/src/main/java/me/uport/sdk/credentials/EthereumTransactionRequestParams.kt @@ -2,7 +2,6 @@ package me.uport.sdk.credentials -import org.kethereum.extensions.toHexStringNoPrefix import org.kethereum.extensions.toHexStringZeroPadded import java.math.BigInteger diff --git a/demoapp/build.gradle b/demoapp/build.gradle index 20ac6ad4..659aa907 100644 --- a/demoapp/build.gradle +++ b/demoapp/build.gradle @@ -54,6 +54,7 @@ dependencies { androidTestImplementation "com.android.support.test:rules:$test_runner_version" androidTestImplementation "com.android.support.test.espresso:espresso-core:$espresso_version" androidTestImplementation "com.android.support.test.espresso:espresso-intents:$espresso_version" + androidTestImplementation "com.android.support.test.espresso:espresso-contrib:$espresso_version" androidTestImplementation "io.mockk:mockk-android:$mockk_version" androidTestImplementation "com.willowtreeapps.assertk:assertk-jvm:$assertk_version" } diff --git a/demoapp/src/androidTest/java/me/uport/sdk/demoapp/CreateAccountTest.kt b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/CreateAccountTest.kt index ea3d8122..6cb1c4ac 100644 --- a/demoapp/src/androidTest/java/me/uport/sdk/demoapp/CreateAccountTest.kt +++ b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/CreateAccountTest.kt @@ -17,6 +17,9 @@ class CreateAccountTest { @Test fun accountIsCreated() { + + Thread.sleep(2000) + onView(withId(R.id.defaultAccountView)).check(matches(withText(not(containsString("ERROR"))))) } diff --git a/demoapp/src/androidTest/java/me/uport/sdk/demoapp/PersonalSignatureTest.kt b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/PersonalSignatureTest.kt new file mode 100644 index 00000000..0e1204f8 --- /dev/null +++ b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/PersonalSignatureTest.kt @@ -0,0 +1,67 @@ +package me.uport.sdk.demoapp + +import android.app.Activity +import android.app.Instrumentation +import android.content.Intent +import android.content.IntentFilter +import android.support.test.InstrumentationRegistry +import android.support.test.espresso.Espresso.onView +import android.support.test.espresso.action.ViewActions.click +import android.support.test.espresso.assertion.ViewAssertions.matches +import android.support.test.espresso.intent.Intents.intending +import android.support.test.espresso.intent.matcher.IntentMatchers.hasAction +import android.support.test.espresso.intent.rule.IntentsTestRule +import android.support.test.espresso.matcher.ViewMatchers.withId +import android.support.test.espresso.matcher.ViewMatchers.withText +import me.uport.sdk.demoapp.request_flows.PersonalSignRequestActivity +import me.uport.sdk.transport.RequestDispatchActivity +import org.hamcrest.CoreMatchers.not +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +class PersonalSignatureTest { + + @get:Rule + val intentsTestRule = IntentsTestRule(PersonalSignRequestActivity::class.java) + + private var instrumentation: Instrumentation? = null + private var monitor: Instrumentation.ActivityMonitor? = null + private val filter: IntentFilter? = null + + @Before + fun run_before_every_test() { + instrumentation = InstrumentationRegistry.getInstrumentation() + monitor = instrumentation?.addMonitor(filter, null, true) + } + + @After + fun run_after_every_test() { + instrumentation?.removeMonitor(monitor) + } + + @Before + fun stub_intent() { + // Mock the ActivityResult to be returned to PersonalSignRequestActivity in onActivityResult. + val resultData = Intent() + val redirectUri = "https://uport-project.github.io/uport-android-sdk/callbacks#personalSig=eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NTI0ODczMjIsImV4cCI6MTU1MjU3MzcyMiwidHlwZSI6InBlcnNvbmFsU2lnblJlc3AiLCJkYXRhIjoiVGhpcyBpcyBhIG1lc3NhZ2UgSSBuZWVkIHlvdSB0byBzaWduIiwic2lnbmF0dXJlIjp7InYiOjI3LCJyIjoiMHgzYjExMmUxMzZiMDI3MDZiNzNjZjhjYjFmNDI0ZDBjZjg1NWExZTM5OTU0ZGM3OTJjZTllYzFmNDkwZmJlZjBiIiwicyI6IjB4N2U0YTViMWU4MWM4YjNjZjJkMTY1ODdjNTUwMjUyNmNjOTM3OWU4OWUwOWI2NTNlMWI2NWUzOThkYzg5MjBjNiJ9LCJpc3MiOiJkaWQ6ZXRocjoweDNmZjI1MTE3YzBlMTcwY2E1MzBiZDU4OTE4OTljMTgzOTQ0ZGI0MzEifQ.5FtBavglhq1aeMtTM644cY5d1ij-0QvlMMLMQhmwVpUtCKOJRBjj3psXrPPuEm28_ZqAV0ISTyH7a2w1osjyzgE" + resultData.putExtra("redirect_uri", redirectUri) + val response = Instrumentation.ActivityResult(Activity.RESULT_OK, resultData) + + // This sets up what the ActivityResult to be returned whenever an intent with the below action is launched + intending(hasAction(RequestDispatchActivity.ACTION_DISPATCH_REQUEST)).respondWith(response) + } + + @Test + fun data_successfully_signed_by_uport_account() { + + // User clicks on send request. + onView(withId(R.id.send_request)).perform(click()) + + Thread.sleep(5000) + + // Response detail TextView will no longer be empty + onView(withId(R.id.response_details)).check(matches(not(withText("")))) + } +} \ No newline at end of file diff --git a/demoapp/src/androidTest/java/me/uport/sdk/demoapp/SelectiveDisclosureTest.kt b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/SelectiveDisclosureTest.kt deleted file mode 100644 index 9fb16f66..00000000 --- a/demoapp/src/androidTest/java/me/uport/sdk/demoapp/SelectiveDisclosureTest.kt +++ /dev/null @@ -1,59 +0,0 @@ -package me.uport.sdk.demoapp - -import android.app.Instrumentation -import android.content.Intent -import android.content.IntentFilter -import android.support.test.InstrumentationRegistry -import android.support.test.espresso.Espresso.onView -import android.support.test.espresso.action.ViewActions.click -import android.support.test.espresso.intent.Intents.intended -import android.support.test.espresso.intent.matcher.IntentMatchers -import android.support.test.espresso.intent.matcher.UriMatchers -import android.support.test.espresso.intent.rule.IntentsTestRule -import android.support.test.espresso.matcher.ViewMatchers.withId -import org.hamcrest.Matchers -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test - -class SelectiveDisclosureTest { - - @get:Rule - var intentsTestRule = IntentsTestRule(SelectiveDisclosureActivity::class.java, true, true) - - // used to block intent from actual broadcast - private val filter: IntentFilter? = null - private var instrumentation: Instrumentation? = null - private var monitor: Instrumentation.ActivityMonitor? = null - - @Before - fun run_before_every_test() { - instrumentation = InstrumentationRegistry.getInstrumentation() - monitor = instrumentation?.addMonitor(filter, null, true) - } - - @After - fun run_after_every_test() { - instrumentation?.removeMonitor(monitor) - } - - @Test - fun signing_intent_is_sent() { - - onView(withId(R.id.send_request)).perform(click()) - - assert((intentsTestRule.activity.requestJWT).isNotEmpty()) - - intended(Matchers.allOf( - IntentMatchers.hasAction(Matchers.equalTo(Intent.ACTION_VIEW)), - IntentMatchers.hasCategories(Matchers.hasItem(Matchers.equalTo(Intent.CATEGORY_BROWSABLE))), - IntentMatchers.hasData(Matchers.allOf( - UriMatchers.hasHost(Matchers.equalTo("id.uport.me")), - UriMatchers.hasPath(Matchers.containsString("/req/${intentsTestRule.activity.requestJWT}")) - ) - ))) - } - -} - diff --git a/demoapp/src/androidTest/java/me/uport/sdk/demoapp/SignJWTUportHDTest.kt b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/SignJWTUportHDTest.kt index bcc078d8..9e271d31 100644 --- a/demoapp/src/androidTest/java/me/uport/sdk/demoapp/SignJWTUportHDTest.kt +++ b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/SignJWTUportHDTest.kt @@ -1,8 +1,5 @@ package me.uport.sdk.demoapp -import android.support.test.espresso.Espresso.onView -import android.support.test.espresso.action.ViewActions.click -import android.support.test.espresso.matcher.ViewMatchers.withId import android.support.test.rule.ActivityTestRule import assertk.assert import assertk.assertions.isNotEqualTo @@ -16,10 +13,10 @@ class SignJWTUportHDTest { val activityRule = ActivityTestRule(SignJWTUportHDSignerActivity::class.java) @Test - fun keyIsCreated() { + fun signerIsCreated() { - onView(withId(R.id.submit_btn_one)).perform(click()) + Thread.sleep(1000) - assert(activityRule.activity.issuerDID).isNotEqualTo("null") + assert(activityRule.activity.issuerDID).isNotEqualTo("") } } \ No newline at end of file diff --git a/demoapp/src/androidTest/java/me/uport/sdk/demoapp/TransactionRequestTest.kt b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/TransactionRequestTest.kt new file mode 100644 index 00000000..35cbc96f --- /dev/null +++ b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/TransactionRequestTest.kt @@ -0,0 +1,66 @@ +package me.uport.sdk.demoapp + +import android.app.Activity +import android.app.Instrumentation +import android.content.Intent +import android.content.IntentFilter +import android.support.test.InstrumentationRegistry +import android.support.test.espresso.Espresso.onView +import android.support.test.espresso.action.ViewActions.click +import android.support.test.espresso.assertion.ViewAssertions.matches +import android.support.test.espresso.intent.Intents.intending +import android.support.test.espresso.intent.matcher.IntentMatchers.hasAction +import android.support.test.espresso.intent.rule.IntentsTestRule +import android.support.test.espresso.matcher.ViewMatchers.withId +import android.support.test.espresso.matcher.ViewMatchers.withText +import me.uport.sdk.demoapp.request_flows.EthereumTransactionActivity +import me.uport.sdk.transport.RequestDispatchActivity +import org.hamcrest.CoreMatchers.not +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +class TransactionRequestTest { + + @get:Rule + val intentsTestRule = IntentsTestRule(EthereumTransactionActivity::class.java) + + private var instrumentation: Instrumentation? = null + private var monitor: Instrumentation.ActivityMonitor? = null + private val filter: IntentFilter? = null + + @Before + fun run_before_every_test() { + instrumentation = InstrumentationRegistry.getInstrumentation() + monitor = instrumentation?.addMonitor(filter, null, true) + } + + @After + fun run_after_every_test() { + instrumentation?.removeMonitor(monitor) + } + + @Before + fun stub_intent() { + // Mock the ActivityResult to be returned to EthereumTransactionActivity in onActivityResult. + val resultData = Intent() + val redirectUri = "https://uport-project.github.io/uport-android-sdk/callbacks#tx=6146ccf6a66d994f7c363db875e31ca35581450a4bf6d3be6cc9ac79233a69d0" + resultData.putExtra("redirect_uri", redirectUri) + val response = Instrumentation.ActivityResult(Activity.RESULT_OK, resultData) + + // This sets up what the ActivityResult to be returned whenever an intent with the below action is launched + intending(hasAction(RequestDispatchActivity.ACTION_DISPATCH_REQUEST)).respondWith(response) + } + + @Test + fun transaction_request_successfully_approved_by_uport_account() { + // User clicks on send request. + onView(withId(R.id.send_request)).perform(click()) + + Thread.sleep(5000) + + // Response detail TextView will no longer be empty + onView(withId(R.id.response_details)).check(matches(not(withText("")))) + } +} \ No newline at end of file diff --git a/demoapp/src/androidTest/java/me/uport/sdk/demoapp/TypedDataTests.kt b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/TypedDataTests.kt new file mode 100644 index 00000000..2a1c8cc4 --- /dev/null +++ b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/TypedDataTests.kt @@ -0,0 +1,67 @@ +package me.uport.sdk.demoapp + +import android.app.Activity +import android.app.Instrumentation +import android.content.Intent +import android.content.IntentFilter +import android.support.test.InstrumentationRegistry +import android.support.test.espresso.Espresso.onView +import android.support.test.espresso.action.ViewActions.click +import android.support.test.espresso.assertion.ViewAssertions.matches +import android.support.test.espresso.intent.Intents.intending +import android.support.test.espresso.intent.matcher.IntentMatchers.hasAction +import android.support.test.espresso.intent.rule.IntentsTestRule +import android.support.test.espresso.matcher.ViewMatchers.withId +import android.support.test.espresso.matcher.ViewMatchers.withText +import me.uport.sdk.demoapp.request_flows.TypedDataRequestActivity +import me.uport.sdk.transport.RequestDispatchActivity +import org.hamcrest.CoreMatchers.not +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +class TypedDataTests { + + @get:Rule + val intentsTestRule = IntentsTestRule(TypedDataRequestActivity::class.java) + + private var instrumentation: Instrumentation? = null + private var monitor: Instrumentation.ActivityMonitor? = null + private val filter: IntentFilter? = null + + @Before + fun run_before_every_test() { + instrumentation = InstrumentationRegistry.getInstrumentation() + monitor = instrumentation?.addMonitor(filter, null, true) + } + + @After + fun run_after_every_test() { + instrumentation?.removeMonitor(monitor) + } + + @Before + fun stub_intent() { + // Mock the ActivityResult to be returned to TypedDataRequestActivity in onActivityResult. + val resultData = Intent() + val redirectUri = "https://uport-project.github.io/uport-android-sdk/callbacks#typedDataSig=eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NTI0ODk1NDEsImV4cCI6MTU1MjU3NTk0MSwidHlwZSI6ImVpcDcxMlJlc3AiLCJyZXF1ZXN0Ijp7InR5cGVzIjp7IkVJUDcxMkRvbWFpbiI6W3sibmFtZSI6Im5hbWUiLCJ0eXBlIjoic3RyaW5nIn0seyJuYW1lIjoidmVyc2lvbiIsInR5cGUiOiJzdHJpbmcifSx7Im5hbWUiOiJjaGFpbklkIiwidHlwZSI6InVpbnQyNTYifSx7Im5hbWUiOiJ2ZXJpZnlpbmdDb250cmFjdCIsInR5cGUiOiJhZGRyZXNzIn1dLCJQZXJzb24iOlt7Im5hbWUiOiJuYW1lIiwidHlwZSI6InN0cmluZyJ9LHsibmFtZSI6IndhbGxldCIsInR5cGUiOiJhZGRyZXNzIn1dLCJNYWlsIjpbeyJuYW1lIjoiZnJvbSIsInR5cGUiOiJQZXJzb24ifSx7Im5hbWUiOiJ0byIsInR5cGUiOiJQZXJzb24ifSx7Im5hbWUiOiJjb250ZW50cyIsInR5cGUiOiJzdHJpbmcifV19LCJkb21haW4iOnsibmFtZSI6IkV0aGVyIE1haWwiLCJ2ZXJzaW9uIjoiMSIsImNoYWluSWQiOiIxIiwidmVyaWZ5aW5nQ29udHJhY3QiOiIweENjQ0NjY2NjQ0NDQ2NDQ0NDQ0NjQ2NDY2NDY0NDQ2NDY2NjY2NjY0MifSwibWVzc2FnZSI6eyJjb250ZW50cyI6IkhlbGxvIEJvYiIsImZyb20iOnsibmFtZSI6IkNvdyIsIndhbGxldCI6IjB4Q0QyYTNkOUY5MzhFMTNDRDk0N0VjMDVBYkM3RkU3MzREZjhERDgyNiJ9LCJ0byI6eyJuYW1lIjoidG8iLCJ3YWxsZXQiOiIweGJCYkJCQkJiYkJCQmJiYkJiYkJiYmJiQkJiQmJiYmJCYkJiYkJCYkIifX0sInByaW1hcnlUeXBlIjoiTWFpbCJ9LCJzaWduYXR1cmUiOnsidiI6MjgsInIiOiIweDlkZjliMDBiOTJiMzYwZDM0NDU2MTg5MDc1MzQ3NzhhOWU1MGRiMDY5ZmQ4NGNmODJiNThmYTFhN2YzNjBkZTUiLCJzIjoiMHg1YjQyOGE2MjVkNDAxZjdmMzQ1N2YxYzk1YjM5MzQ5NTBlZjI3M2JhNjY5MTY3MzNhZGNjYWIyMGEwYTA3YzUxIn0sImlzcyI6ImRpZDpldGhyOjB4M2ZmMjUxMTdjMGUxNzBjYTUzMGJkNTg5MTg5OWMxODM5NDRkYjQzMSJ9.kEwFlT-hQF0eAhv9uS0A_qmc13J0-w3nTjk6ZMbVWOhxGqp_4HKzfYKJuHyKsWJKq2NMzX2jVcvx7Thfqnrc7wE" + resultData.putExtra("redirect_uri", redirectUri) + val response = Instrumentation.ActivityResult(Activity.RESULT_OK, resultData) + + // This sets up what the ActivityResult to be returned whenever an intent with the below action is launched + intending(hasAction(RequestDispatchActivity.ACTION_DISPATCH_REQUEST)).respondWith(response) + } + + @Test + fun typed_data_successfully_signed_by_uport_account() { + + // User clicks on send request. + onView(withId(R.id.send_request)).perform(click()) + + Thread.sleep(5000) + + // Response detail TextView will no longer be empty + onView(withId(R.id.response_details)).check(matches(not(withText("")))) + } +} \ No newline at end of file diff --git a/demoapp/src/androidTest/java/me/uport/sdk/demoapp/VerifiedClaimTest.kt b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/VerifiedClaimTest.kt new file mode 100644 index 00000000..0705177c --- /dev/null +++ b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/VerifiedClaimTest.kt @@ -0,0 +1,67 @@ +package me.uport.sdk.demoapp + +import android.app.Activity +import android.app.Instrumentation +import android.content.Intent +import android.content.IntentFilter +import android.support.test.InstrumentationRegistry +import android.support.test.espresso.Espresso.onView +import android.support.test.espresso.action.ViewActions.click +import android.support.test.espresso.assertion.ViewAssertions.matches +import android.support.test.espresso.intent.Intents.intending +import android.support.test.espresso.intent.matcher.IntentMatchers.hasAction +import android.support.test.espresso.intent.rule.IntentsTestRule +import android.support.test.espresso.matcher.ViewMatchers.withId +import android.support.test.espresso.matcher.ViewMatchers.withText +import me.uport.sdk.demoapp.request_flows.VerifiedClaimRequestActivity +import me.uport.sdk.transport.RequestDispatchActivity +import org.hamcrest.CoreMatchers.not +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +class VerifiedClaimTest { + + @get:Rule + val intentsTestRule = IntentsTestRule(VerifiedClaimRequestActivity::class.java) + + private var instrumentation: Instrumentation? = null + private var monitor: Instrumentation.ActivityMonitor? = null + private val filter: IntentFilter? = null + + @Before + fun run_before_every_test() { + instrumentation = InstrumentationRegistry.getInstrumentation() + monitor = instrumentation?.addMonitor(filter, null, true) + } + + @After + fun run_after_every_test() { + instrumentation?.removeMonitor(monitor) + } + + @Before + fun stub_intent() { + // Mock the ActivityResult to be returned to VerifiedClaimRequestActivity in onActivityResult. + val resultData = Intent() + val redirectUri = "https://uport-project.github.io/uport-android-sdk/callbacks#access_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NTI0MzU4MzAsImV4cCI6MTU1MjUyMjIzMCwic3ViIjoiZGlkOmV0aHI6MHgzZmYyNTExN2MwZTE3MGNhNTMwYmQ1ODkxODk5YzE4Mzk0NGRiNDMxIiwiY2xhaW0iOnsiY2l0aXplbiBvZiBDbGV2ZXJsYW5kIjp0cnVlfSwiaXNzIjoiZGlkOmV0aHI6MHgzZmYyNTExN2MwZTE3MGNhNTMwYmQ1ODkxODk5YzE4Mzk0NGRiNDMxIn0.vLENXTTjnbPGTDgSMg4KvH7srlYaXupJrxOZ1Ic_uBzp-paAHoCy2f0Qcfn60RQ0vXuD9Cb3p9tJyvBfkNYUdAA" + resultData.putExtra("redirect_uri", redirectUri) + val response = Instrumentation.ActivityResult(Activity.RESULT_OK, resultData) + + // This sets up what the ActivityResult to be returned whenever an intent with the below action is launched + intending(hasAction(RequestDispatchActivity.ACTION_DISPATCH_REQUEST)).respondWith(response) + } + + @Test + fun claim_successfully_signed_by_uport() { + + // User clicks on send request. + onView(withId(R.id.send_request)).perform(click()) + + Thread.sleep(5000) + + // Response detail textview will no longer be empty + onView(withId(R.id.response_details)).check(matches(not(withText("")))) + } +} \ No newline at end of file diff --git a/demoapp/src/androidTest/java/me/uport/sdk/demoapp/uPortLoginTest.kt b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/uPortLoginTest.kt new file mode 100644 index 00000000..73e93043 --- /dev/null +++ b/demoapp/src/androidTest/java/me/uport/sdk/demoapp/uPortLoginTest.kt @@ -0,0 +1,72 @@ +package me.uport.sdk.demoapp + +import android.app.Activity +import android.app.Instrumentation +import android.content.Intent +import android.content.IntentFilter +import android.support.test.InstrumentationRegistry +import android.support.test.espresso.Espresso.onView +import android.support.test.espresso.action.ViewActions.click +import android.support.test.espresso.assertion.ViewAssertions.matches +import android.support.test.espresso.intent.Intents.intending +import android.support.test.espresso.intent.matcher.IntentMatchers.hasAction +import android.support.test.espresso.intent.rule.IntentsTestRule +import android.support.test.espresso.matcher.ViewMatchers.isDisplayed +import android.support.test.espresso.matcher.ViewMatchers.withId +import me.uport.sdk.demoapp.request_flows.uPortLoginActivity +import me.uport.sdk.transport.RequestDispatchActivity +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test + + +class uPortLoginTest { + + @get:Rule + val intentsTestRule = IntentsTestRule(uPortLoginActivity::class.java) + + private var instrumentation: Instrumentation? = null + private var monitor: Instrumentation.ActivityMonitor? = null + private val filter: IntentFilter? = null + + @Before + fun run_before_every_test() { + instrumentation = InstrumentationRegistry.getInstrumentation() + monitor = instrumentation?.addMonitor(filter, null, true) + } + + @After + fun run_after_every_test() { + instrumentation?.removeMonitor(monitor) + } + + @Before + fun stub_intent() { + + // Mock the ActivityResult to be returned to uPortLoginActivity in onActivityResult. + val resultData = Intent() + val redirectUri = "https://uport-project.github.io/uport-android-sdk/callbacks#access_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NTI0MzIzMDAsImV4cCI6MTU1MjUxODcwMCwiYXVkIjoiZGlkOmV0aHI6MHhjZjAzZGQwYTg5NGVmNzljYjViNjAxYTQzYzRiMjVlM2FlNGM2N2VkIiwidHlwZSI6InNoYXJlUmVzcCIsIm5hZCI6IjJvaGpmdGhLb2sxV2d2OFhoZTNKcjFEUnh3ckRjM1JhMVpaIiwib3duIjp7Im5hbWUiOiJ1UG9ydCBVc2VyIn0sInJlcSI6ImV5SjBlWEFpT2lKS1YxUWlMQ0poYkdjaU9pSkZVekkxTmtzdFVpSjkuZXlKallXeHNZbUZqYXlJNkltaDBkSEJ6T2k4dmRYQnZjblF0Y0hKdmFtVmpkQzVuYVhSb2RXSXVhVzh2ZFhCdmNuUXRZVzVrY205cFpDMXpaR3N2WTJGc2JHSmhZMnR6SWl3aWNtVnhkV1Z6ZEdWa0lqcGJJbTVoYldVaVhTd2lZV04wSWpvaVoyVnVaWEpoYkNJc0luUjVjR1VpT2lKemFHRnlaVkpsY1NJc0ltbGhkQ0k2TVRVMU1qUXpNakl5TlN3aVpYaHdJam94TlRVeU5ETXlPREkxTENKcGMzTWlPaUprYVdRNlpYUm9jam93ZUdObU1ETmtaREJoT0RrMFpXWTNPV05pTldJMk1ERmhORE5qTkdJeU5XVXpZV1UwWXpZM1pXUWlmUS5DV00zbVVhLWVMQlYwa1JyLXptc2tvRDFmQ2FiYVh5S19URFVwczc1Y3paN0kxWmRzdUE2c1N6M3d0dGltZmttQlRaWU5iZnFYcDh1ZFptTm1TV2Q2UUUiLCJpc3MiOiJkaWQ6ZXRocjoweDNmZjI1MTE3YzBlMTcwY2E1MzBiZDU4OTE4OTljMTgzOTQ0ZGI0MzEifQ.FeJ3qtIZdR5LlIIH1lgzWdhEmbygOc_SzvMxxOBd21bFBxeJt_RyXVuCAPQkUelN9qXrw12veQTHedQNQraQFw" + resultData.putExtra("redirect_uri", redirectUri) + val response = Instrumentation.ActivityResult(Activity.RESULT_OK, resultData) + + // This sets up what the ActivityResult to be returned whenever an intent with the below action is launched + intending(hasAction(RequestDispatchActivity.ACTION_DISPATCH_REQUEST)).respondWith(response) + } + + @Test + fun uport_login_successful() { + + // User starts the uport login activity. + onView(withId(R.id.btn_send_request)).perform(click()) + + Thread.sleep(5000) + + // Check if other request flow buttons visible after successful login + onView(withId(R.id.btn_verified_claim)).check(matches(isDisplayed())) + onView(withId(R.id.btn_personal_signature)).check(matches(isDisplayed())) + onView(withId(R.id.btn_typed_data)).check(matches(isDisplayed())) + onView(withId(R.id.btn_ethereum_transaction)).check(matches(isDisplayed())) + } +} + diff --git a/demoapp/src/main/java/me/uport/sdk/demoapp/MainListActivity.kt b/demoapp/src/main/java/me/uport/sdk/demoapp/MainListActivity.kt index d0491f6f..f995b114 100644 --- a/demoapp/src/main/java/me/uport/sdk/demoapp/MainListActivity.kt +++ b/demoapp/src/main/java/me/uport/sdk/demoapp/MainListActivity.kt @@ -9,7 +9,6 @@ import kotlinx.android.synthetic.main.simple_list.* import me.uport.sdk.demoapp.key_protection.KeyProtectionListActivity import me.uport.sdk.demoapp.managing_jwt.SignJWTListActivity import me.uport.sdk.demoapp.managing_jwt.VerifyJWTActivity -import me.uport.sdk.demoapp.request_flows.getNetworkAndAddressFromDID import me.uport.sdk.demoapp.request_flows.uPortLoginActivity /** diff --git a/demoapp/src/main/java/me/uport/sdk/demoapp/managing_jwt/SignJWTUportHDSignerActivity.kt b/demoapp/src/main/java/me/uport/sdk/demoapp/managing_jwt/SignJWTUportHDSignerActivity.kt index 975b8133..ece41c05 100644 --- a/demoapp/src/main/java/me/uport/sdk/demoapp/managing_jwt/SignJWTUportHDSignerActivity.kt +++ b/demoapp/src/main/java/me/uport/sdk/demoapp/managing_jwt/SignJWTUportHDSignerActivity.kt @@ -27,7 +27,6 @@ class SignJWTUportHDSignerActivity : AppCompatActivity() { submit_btn_one.text = "Sign JWT" - // mock a JWT payload val payload = mapOf( "claims" to mapOf( @@ -63,7 +62,7 @@ class SignJWTUportHDSignerActivity : AppCompatActivity() { GlobalScope.launch(UI) { val signedJWT: String? = try { - JWTTools().createJWT(payload, issuerDID!!, signer!!, 5000) + JWTTools().createJWT(payload, issuerDID!!, signer!!,5000) } catch (exception: Exception) { null } @@ -73,4 +72,4 @@ class SignJWTUportHDSignerActivity : AppCompatActivity() { } } } -} \ No newline at end of file +} diff --git a/demoapp/src/main/java/me/uport/sdk/demoapp/request_flows/EthrTransactionUtils.kt b/demoapp/src/main/java/me/uport/sdk/demoapp/request_flows/EthrTransactionUtils.kt index 56e71c2f..0615c06e 100644 --- a/demoapp/src/main/java/me/uport/sdk/demoapp/request_flows/EthrTransactionUtils.kt +++ b/demoapp/src/main/java/me/uport/sdk/demoapp/request_flows/EthrTransactionUtils.kt @@ -16,7 +16,9 @@ import java.lang.IllegalArgumentException * TODO: Move this functionality to the SDK and create an API so apps can easily fetch an address from a DID */ -fun getNetworkAndAddressFromDID(did: String): Pair { +fun getNetworkAndAddressFromDID(did: String?): Pair { + + if (did.isNullOrBlank()) { return ("" to "") } // converts possible ethr DIDs to a Pair of Network and Address val ethrMatchResult = EthrDIDResolver.identityExtractPattern.find(did) diff --git a/demoapp/src/main/java/me/uport/sdk/demoapp/request_flows/uPortLoginActivity.kt b/demoapp/src/main/java/me/uport/sdk/demoapp/request_flows/uPortLoginActivity.kt index 1a83c0d0..04545b65 100644 --- a/demoapp/src/main/java/me/uport/sdk/demoapp/request_flows/uPortLoginActivity.kt +++ b/demoapp/src/main/java/me/uport/sdk/demoapp/request_flows/uPortLoginActivity.kt @@ -14,11 +14,7 @@ import me.uport.sdk.credentials.Credentials import me.uport.sdk.credentials.SelectiveDisclosureRequestParams import me.uport.sdk.demoapp.R import me.uport.sdk.jwt.JWTTools -import me.uport.sdk.transport.ErrorUriResponse -import me.uport.sdk.transport.JWTUriResponse -import me.uport.sdk.transport.ResponseParser -import me.uport.sdk.transport.Transports -import me.uport.sdk.transport.UriResponse +import me.uport.sdk.transport.* /** * This allows the users initiate a uPort login using [SelectiveDisclosureRequest] @@ -69,6 +65,7 @@ class uPortLoginActivity : AppCompatActivity() { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) + val response: UriResponse? = ResponseParser.parseActivityResult(requestCode, resultCode, data) when (response) { diff --git a/demoapp/src/main/res/layout/request_flow.xml b/demoapp/src/main/res/layout/request_flow.xml index 54b6f331..6b704856 100644 --- a/demoapp/src/main/res/layout/request_flow.xml +++ b/demoapp/src/main/res/layout/request_flow.xml @@ -43,7 +43,7 @@ android:layout_height="wrap_content" android:layout_marginTop="32dp" android:gravity="left" - tools:text="response details" /> + tools:text="" />