From 73efb00368e461f0f910f0705bcb16bb51c4c510 Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Mon, 8 Nov 2021 23:51:07 +0200 Subject: [PATCH 01/14] Added basic notifications to the user For when exceptions occur when communicating with the ID-card --- .../mobileauthapp/AuthFragment.kt | 38 +++++++++++++++---- .../mobileauthapp/NFC/Comms.java | 9 +++-- .../mobileauthapp/auth/AuthAppException.kt | 10 +++++ .../mobileauthapp/auth/InvalidCANException.kt | 7 ++++ .../app/src/main/res/values-en/strings.xml | 7 +++- .../app/src/main/res/values-et/strings.xml | 7 +++- .../app/src/main/res/values/strings.xml | 7 +++- 7 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/AuthAppException.kt create mode 100644 MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/InvalidCANException.kt diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt index fa5de12..55f82f3 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt @@ -5,7 +5,6 @@ import android.nfc.NfcAdapter import android.nfc.tech.IsoDep import android.os.Bundle import android.os.CountDownTimer -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -15,10 +14,14 @@ import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.tarkvaraprojekt.mobileauthapp.NFC.Comms +import com.tarkvaraprojekt.mobileauthapp.auth.AuthAppException +import com.tarkvaraprojekt.mobileauthapp.auth.InvalidCANException import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentAuthBinding import com.tarkvaraprojekt.mobileauthapp.model.ParametersViewModel import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel +import java.io.IOException import java.lang.Exception +import java.security.GeneralSecurityException import kotlin.system.exitProcess /** @@ -80,6 +83,8 @@ class AuthFragment : Fragment() { requireActivity().runOnUiThread { binding!!.timeCounter.text = getString(R.string.card_detected) } + var msgCode = 0 + val card = IsoDep.get(tag) card.timeout = 32768 card.use { @@ -95,17 +100,36 @@ class AuthFragment : Fragment() { requireActivity().runOnUiThread { binding!!.timeCounter.text = getString(R.string.data_read) } - } catch (e: Exception) { - requireActivity().runOnUiThread { - binding!!.timeCounter.text = getString(R.string.no_success) - } + + } catch (e: android.nfc.TagLostException) { + msgCode = R.string.tag_lost + } catch (e: InvalidCANException) { + msgCode = R.string.invalid_can // If the CAN is wrong we will also delete the saved CAN so that the user won't use it again. viewModel.deleteCan(requireContext()) + } catch (e: AuthAppException) { + msgCode = when (e.code) { + 448 -> R.string.err_bad_data + 500 -> R.string.err_internal + else -> R.string.err_unknown + } + } catch (e: GeneralSecurityException) { + msgCode = R.string.err_internal + } catch (e: IOException) { + msgCode = R.string.err_reading_card + } catch (e: Exception) { + msgCode = R.string.err_unknown + } finally { + adapter.disableReaderMode(activity) + } + + if (msgCode != 0) { + requireActivity().runOnUiThread { + binding!!.timeCounter.text = getString(msgCode) + } // Gives user some time to read the error message Thread.sleep(1000) goToTheStart() - } finally { - adapter.disableReaderMode(activity) } } }, NfcAdapter.FLAG_READER_NFC_A, null) diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/NFC/Comms.java b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/NFC/Comms.java index a4d184b..76b8c4f 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/NFC/Comms.java +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/NFC/Comms.java @@ -3,6 +3,9 @@ package com.tarkvaraprojekt.mobileauthapp.NFC; import android.nfc.tech.IsoDep; import android.util.Log; +import com.tarkvaraprojekt.mobileauthapp.auth.AuthAppException; +import com.tarkvaraprojekt.mobileauthapp.auth.InvalidCANException; + import org.bouncycastle.crypto.BlockCipher; import org.bouncycastle.crypto.engines.AESEngine; import org.bouncycastle.crypto.macs.CMac; @@ -209,13 +212,13 @@ public class Comms { Log.i("Mutual authentication", Hex.toHexString(response)); // if the chip-side verification fails, crash and burn - if (response.length == 2) throw new RuntimeException("Invalid CAN."); + if (response.length == 2) throw new InvalidCANException(); // otherwise verify chip's MAC and return session keys APDU = createAPDU(dataForMACIncomplete, publicKey.getEncoded(false), 65); MAC = getMAC(APDU, keyMAC); if (!Hex.toHexString(response, 4, 8).equals(Hex.toHexString(MAC))) { - throw new RuntimeException("Could not verify chip's MAC."); // Should never happen. + throw new AuthAppException("Could not verify chip's MAC.", 448); // Should never happen. } return new byte[][]{keyEnc, keyMAC}; @@ -304,7 +307,7 @@ public class Comms { for (int i = 0; i < FID.length; i++) { byte index = FID[i]; - if (index > 15 || index < 1) throw new RuntimeException("Invalid personal data FID."); + if (index > 15 || index < 1) throw new AuthAppException("Invalid personal data FID.", 500); data[1] = index; APDU = createSecureAPDU(data, personal); diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/AuthAppException.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/AuthAppException.kt new file mode 100644 index 0000000..96b05d5 --- /dev/null +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/AuthAppException.kt @@ -0,0 +1,10 @@ +package com.tarkvaraprojekt.mobileauthapp.auth + +/** + * A specialised RuntimeException class for exceptions related to the mobile authentication app. + * Possible error codes can be found at + * https://github.com/TanelOrumaa/Estonian-ID-card-mobile-authenticator-POC/wiki/Error-codes + * @param message Error message + * @param code An error code defined in the project wiki + */ +open class AuthAppException(message: String, var code: Int) : RuntimeException(message) \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/InvalidCANException.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/InvalidCANException.kt new file mode 100644 index 0000000..073c790 --- /dev/null +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/InvalidCANException.kt @@ -0,0 +1,7 @@ +package com.tarkvaraprojekt.mobileauthapp.auth + +/** + * An AuthAppException for when the user entered CAN does not match the one read from the ID-card + * @see AuthAppException + */ +class InvalidCANException : AuthAppException("Invalid CAN", 400) \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/res/values-en/strings.xml b/MobileAuthApp/app/src/main/res/values-en/strings.xml index 7aa4439..f169ccd 100644 --- a/MobileAuthApp/app/src/main/res/values-en/strings.xml +++ b/MobileAuthApp/app/src/main/res/values-en/strings.xml @@ -44,7 +44,9 @@ Put the ID card against the phone to establish connection Time left %d sek No time left - Wrong CAN + Unknown error + Wrong CAN + Connection between device and ID-card lost NAME @@ -75,4 +77,7 @@ **** Settings currently unavailabe CAN is currently not saved. Do you wish to save the CAN? Saved CAN will be entered automatically in the future. Saved CAN can be changed and deleted in the settings menu. + Failed to read data from the ID-card + Internal error + Read bad data from the ID-card, try using the card again \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/res/values-et/strings.xml b/MobileAuthApp/app/src/main/res/values-et/strings.xml index 66afcfb..b630b90 100644 --- a/MobileAuthApp/app/src/main/res/values-et/strings.xml +++ b/MobileAuthApp/app/src/main/res/values-et/strings.xml @@ -43,7 +43,9 @@ ID kaardiga ühenduse loomiseks pane kaart vastu telefoni Aega on jäänud %d sek Aeg on otsas - Vale CAN + Tundmatu viga + Vale CAN + Ühendus seadme ja kaardi vahel katkes NIMI @@ -73,4 +75,7 @@ PEIDA **** Seaded pole hetkel saadaval + Ei saanud ID-kaardilt andmeid lugeda + Rakendusesisene viga + ID-kaardilt loeti vigased andmed, proovi uuesti kaarti kasutada \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/res/values/strings.xml b/MobileAuthApp/app/src/main/res/values/strings.xml index 0a39206..178763c 100644 --- a/MobileAuthApp/app/src/main/res/values/strings.xml +++ b/MobileAuthApp/app/src/main/res/values/strings.xml @@ -43,7 +43,9 @@ Put the ID card against the phone to establish connection Time left %d sek No time left - Wrong CAN + Unknown error + Wrong CAN + Connection between device and ID-card lost NAME @@ -73,4 +75,7 @@ HIDE **** Settings currently unavailable + Failed to read data from the ID-card + Internal error + Read bad data from the ID-card, try using the card again \ No newline at end of file From 0e15bede78afd2d8466301f56dd18b5076a9b39f Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Sat, 4 Dec 2021 14:28:52 +0200 Subject: [PATCH 02/14] UC4 test --- MobileAuthApp/app/build.gradle | 2 + .../tarkvaraprojekt/mobileauthapp/UC4Test.kt | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt diff --git a/MobileAuthApp/app/build.gradle b/MobileAuthApp/app/build.gradle index a65bc6e..9a0b3dc 100644 --- a/MobileAuthApp/app/build.gradle +++ b/MobileAuthApp/app/build.gradle @@ -44,7 +44,9 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test:rules:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + debugImplementation 'androidx.fragment:fragment-testing:1.4.0' //To use activityViewModels implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt new file mode 100644 index 0000000..c41ab64 --- /dev/null +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -0,0 +1,50 @@ +package com.tarkvaraprojekt.mobileauthapp + +import androidx.fragment.app.testing.launchFragmentInContainer +import androidx.lifecycle.Lifecycle +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.IdlingPolicies +import androidx.test.espresso.action.ViewActions.* +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.RootMatchers.* +import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.rule.ActivityTestRule +import org.hamcrest.CoreMatchers.`is` +import org.hamcrest.CoreMatchers.not +import org.junit.Assert.* + +import org.junit.* +import org.junit.runner.RunWith +import java.util.concurrent.TimeUnit + +@RunWith(AndroidJUnit4::class) +class UC4Test { + @get:Rule + var activityActivityTestRule: ActivityTestRule = ActivityTestRule( + MainActivity::class.java + ) + + @Before + fun setUp() { + IdlingPolicies.setMasterPolicyTimeout(1, TimeUnit.SECONDS) + IdlingPolicies.setIdlingResourceTimeout(1, TimeUnit.SECONDS) + activityActivityTestRule.activity + .supportFragmentManager.beginTransaction() + } + + @After + fun tearDown() { + } + + @Test + fun test() { + onView(withId(R.id.menu_settings_option)).perform(click()) + onView(withId(R.id.can_menu_action)).perform(click()) + onView(supportsInputMethods()).perform(typeText("123456")) + onView(withId(R.id.next_button)).perform(click()) + onView(withText(R.string.can_status_saved)).inRoot( + withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) + ).check(matches(isDisplayed())) + } +} \ No newline at end of file From 339fa0a378e2b4a0a7fdc128b7b2f69f5b6dbd44 Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Mon, 8 Nov 2021 23:51:07 +0200 Subject: [PATCH 03/14] Added basic notifications to the user For when exceptions occur when communicating with the ID-card --- .../mobileauthapp/auth/AuthAppException.kt | 10 ++++++++++ .../mobileauthapp/auth/InvalidCANException.kt | 7 +++++++ MobileAuthApp/app/src/main/res/values-en/strings.xml | 7 ++++++- MobileAuthApp/app/src/main/res/values-et/strings.xml | 7 ++++++- MobileAuthApp/app/src/main/res/values/strings.xml | 7 ++++++- 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/AuthAppException.kt create mode 100644 MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/InvalidCANException.kt diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/AuthAppException.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/AuthAppException.kt new file mode 100644 index 0000000..96b05d5 --- /dev/null +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/AuthAppException.kt @@ -0,0 +1,10 @@ +package com.tarkvaraprojekt.mobileauthapp.auth + +/** + * A specialised RuntimeException class for exceptions related to the mobile authentication app. + * Possible error codes can be found at + * https://github.com/TanelOrumaa/Estonian-ID-card-mobile-authenticator-POC/wiki/Error-codes + * @param message Error message + * @param code An error code defined in the project wiki + */ +open class AuthAppException(message: String, var code: Int) : RuntimeException(message) \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/InvalidCANException.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/InvalidCANException.kt new file mode 100644 index 0000000..073c790 --- /dev/null +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/InvalidCANException.kt @@ -0,0 +1,7 @@ +package com.tarkvaraprojekt.mobileauthapp.auth + +/** + * An AuthAppException for when the user entered CAN does not match the one read from the ID-card + * @see AuthAppException + */ +class InvalidCANException : AuthAppException("Invalid CAN", 400) \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/res/values-en/strings.xml b/MobileAuthApp/app/src/main/res/values-en/strings.xml index 36dce82..69af501 100644 --- a/MobileAuthApp/app/src/main/res/values-en/strings.xml +++ b/MobileAuthApp/app/src/main/res/values-en/strings.xml @@ -44,7 +44,9 @@ Put the ID card against the phone to establish connection Time left %d sek No time left - Wrong CAN + Unknown error + Wrong CAN + Connection between device and ID-card lost NAME @@ -75,4 +77,7 @@ **** Settings currently unavailabe CAN is currently not saved. Do you wish to save the CAN? Saved CAN will be entered automatically in the future. Saved CAN can be changed and deleted in the settings menu. + Failed to read data from the ID-card + Internal error + Read bad data from the ID-card, try using the card again \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/res/values-et/strings.xml b/MobileAuthApp/app/src/main/res/values-et/strings.xml index 63c0eae..1dedbd0 100644 --- a/MobileAuthApp/app/src/main/res/values-et/strings.xml +++ b/MobileAuthApp/app/src/main/res/values-et/strings.xml @@ -43,7 +43,9 @@ ID kaardiga ühenduse loomiseks pane kaart vastu telefoni Aega on jäänud %d sek Aeg on otsas - Vale CAN + Tundmatu viga + Vale CAN + Ühendus seadme ja kaardi vahel katkes NIMI @@ -73,4 +75,7 @@ PEIDA **** Seaded pole hetkel saadaval + Ei saanud ID-kaardilt andmeid lugeda + Rakendusesisene viga + ID-kaardilt loeti vigased andmed, proovi uuesti kaarti kasutada \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/res/values/strings.xml b/MobileAuthApp/app/src/main/res/values/strings.xml index 9c2d2a7..ac0d78b 100644 --- a/MobileAuthApp/app/src/main/res/values/strings.xml +++ b/MobileAuthApp/app/src/main/res/values/strings.xml @@ -43,7 +43,9 @@ Put the ID card against the phone to establish connection Time left %d sek No time left - Wrong CAN + Unknown error + Wrong CAN + Connection between device and ID-card lost NAME @@ -73,4 +75,7 @@ HIDE **** Settings currently unavailable + Failed to read data from the ID-card + Internal error + Read bad data from the ID-card, try using the card again \ No newline at end of file From 73b94adcd3a12b47286a7ccac13a71c02aeefcef Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Sat, 4 Dec 2021 14:28:52 +0200 Subject: [PATCH 04/14] UC4 test --- MobileAuthApp/app/build.gradle | 2 + .../tarkvaraprojekt/mobileauthapp/UC4Test.kt | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt diff --git a/MobileAuthApp/app/build.gradle b/MobileAuthApp/app/build.gradle index bc4a034..5c362f0 100644 --- a/MobileAuthApp/app/build.gradle +++ b/MobileAuthApp/app/build.gradle @@ -44,7 +44,9 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test:rules:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + debugImplementation 'androidx.fragment:fragment-testing:1.4.0' //To use activityViewModels implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt new file mode 100644 index 0000000..c41ab64 --- /dev/null +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -0,0 +1,50 @@ +package com.tarkvaraprojekt.mobileauthapp + +import androidx.fragment.app.testing.launchFragmentInContainer +import androidx.lifecycle.Lifecycle +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.IdlingPolicies +import androidx.test.espresso.action.ViewActions.* +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.RootMatchers.* +import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.rule.ActivityTestRule +import org.hamcrest.CoreMatchers.`is` +import org.hamcrest.CoreMatchers.not +import org.junit.Assert.* + +import org.junit.* +import org.junit.runner.RunWith +import java.util.concurrent.TimeUnit + +@RunWith(AndroidJUnit4::class) +class UC4Test { + @get:Rule + var activityActivityTestRule: ActivityTestRule = ActivityTestRule( + MainActivity::class.java + ) + + @Before + fun setUp() { + IdlingPolicies.setMasterPolicyTimeout(1, TimeUnit.SECONDS) + IdlingPolicies.setIdlingResourceTimeout(1, TimeUnit.SECONDS) + activityActivityTestRule.activity + .supportFragmentManager.beginTransaction() + } + + @After + fun tearDown() { + } + + @Test + fun test() { + onView(withId(R.id.menu_settings_option)).perform(click()) + onView(withId(R.id.can_menu_action)).perform(click()) + onView(supportsInputMethods()).perform(typeText("123456")) + onView(withId(R.id.next_button)).perform(click()) + onView(withText(R.string.can_status_saved)).inRoot( + withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) + ).check(matches(isDisplayed())) + } +} \ No newline at end of file From da2ba0b0da3e2e7c5ab53318126e064a64f88376 Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Sat, 4 Dec 2021 21:53:11 +0200 Subject: [PATCH 05/14] Add invalidCAN test to UC4 test case and rebase --- .../tarkvaraprojekt/mobileauthapp/UC4Test.kt | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt index c41ab64..72f86b7 100644 --- a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -1,9 +1,9 @@ package com.tarkvaraprojekt.mobileauthapp import androidx.fragment.app.testing.launchFragmentInContainer -import androidx.lifecycle.Lifecycle import androidx.test.espresso.Espresso.onView import androidx.test.espresso.IdlingPolicies +import androidx.test.espresso.NoMatchingViewException import androidx.test.espresso.action.ViewActions.* import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.RootMatchers.* @@ -12,7 +12,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.rule.ActivityTestRule import org.hamcrest.CoreMatchers.`is` import org.hamcrest.CoreMatchers.not -import org.junit.Assert.* import org.junit.* import org.junit.runner.RunWith @@ -27,8 +26,8 @@ class UC4Test { @Before fun setUp() { - IdlingPolicies.setMasterPolicyTimeout(1, TimeUnit.SECONDS) - IdlingPolicies.setIdlingResourceTimeout(1, TimeUnit.SECONDS) + IdlingPolicies.setMasterPolicyTimeout(3, TimeUnit.SECONDS) + IdlingPolicies.setIdlingResourceTimeout(3, TimeUnit.SECONDS) activityActivityTestRule.activity .supportFragmentManager.beginTransaction() } @@ -37,14 +36,36 @@ class UC4Test { fun tearDown() { } - @Test - fun test() { + fun navigateToCANView() { onView(withId(R.id.menu_settings_option)).perform(click()) + try { + // Delete existing CAN + onView(withText(R.string.can_delete)).perform(click()) + } catch (ignore: NoMatchingViewException) {} + onView(withId(R.id.can_menu_action)).perform(click()) + } + + @Test + fun validCAN() { + navigateToCANView() onView(supportsInputMethods()).perform(typeText("123456")) onView(withId(R.id.next_button)).perform(click()) + onView(withText(R.string.can_status_saved)).inRoot( withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) ).check(matches(isDisplayed())) } + + @Test + fun invalidCAN() { + navigateToCANView() + onView(supportsInputMethods()).perform(typeText("12345")) + onView(withId(R.id.next_button)).perform(click()) + + onView(withText(R.string.length_can)).inRoot( + withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) + ).check(matches(isDisplayed())) + onView(withId(R.id.next_button)).check(matches(isDisplayed())) + } } \ No newline at end of file From 6ddfe9af46d403eee5c5edffbbe3c6ef7c308ef7 Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Mon, 8 Nov 2021 23:51:07 +0200 Subject: [PATCH 06/14] Added basic notifications to the user For when exceptions occur when communicating with the ID-card --- .../mobileauthapp/auth/AuthAppException.kt | 10 ++++++++++ .../mobileauthapp/auth/InvalidCANException.kt | 7 +++++++ 2 files changed, 17 insertions(+) create mode 100644 MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/AuthAppException.kt create mode 100644 MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/InvalidCANException.kt diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/AuthAppException.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/AuthAppException.kt new file mode 100644 index 0000000..96b05d5 --- /dev/null +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/AuthAppException.kt @@ -0,0 +1,10 @@ +package com.tarkvaraprojekt.mobileauthapp.auth + +/** + * A specialised RuntimeException class for exceptions related to the mobile authentication app. + * Possible error codes can be found at + * https://github.com/TanelOrumaa/Estonian-ID-card-mobile-authenticator-POC/wiki/Error-codes + * @param message Error message + * @param code An error code defined in the project wiki + */ +open class AuthAppException(message: String, var code: Int) : RuntimeException(message) \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/InvalidCANException.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/InvalidCANException.kt new file mode 100644 index 0000000..073c790 --- /dev/null +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/auth/InvalidCANException.kt @@ -0,0 +1,7 @@ +package com.tarkvaraprojekt.mobileauthapp.auth + +/** + * An AuthAppException for when the user entered CAN does not match the one read from the ID-card + * @see AuthAppException + */ +class InvalidCANException : AuthAppException("Invalid CAN", 400) \ No newline at end of file From 24980b325306efc01bbf74e67c5ce7cc7c93b928 Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Sat, 4 Dec 2021 14:28:52 +0200 Subject: [PATCH 07/14] UC4 test --- MobileAuthApp/app/build.gradle | 2 + .../tarkvaraprojekt/mobileauthapp/UC4Test.kt | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt diff --git a/MobileAuthApp/app/build.gradle b/MobileAuthApp/app/build.gradle index 38896fb..2fd1c20 100644 --- a/MobileAuthApp/app/build.gradle +++ b/MobileAuthApp/app/build.gradle @@ -44,7 +44,9 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test:rules:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + debugImplementation 'androidx.fragment:fragment-testing:1.4.0' //To use activityViewModels implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt new file mode 100644 index 0000000..c41ab64 --- /dev/null +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -0,0 +1,50 @@ +package com.tarkvaraprojekt.mobileauthapp + +import androidx.fragment.app.testing.launchFragmentInContainer +import androidx.lifecycle.Lifecycle +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.IdlingPolicies +import androidx.test.espresso.action.ViewActions.* +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.RootMatchers.* +import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.rule.ActivityTestRule +import org.hamcrest.CoreMatchers.`is` +import org.hamcrest.CoreMatchers.not +import org.junit.Assert.* + +import org.junit.* +import org.junit.runner.RunWith +import java.util.concurrent.TimeUnit + +@RunWith(AndroidJUnit4::class) +class UC4Test { + @get:Rule + var activityActivityTestRule: ActivityTestRule = ActivityTestRule( + MainActivity::class.java + ) + + @Before + fun setUp() { + IdlingPolicies.setMasterPolicyTimeout(1, TimeUnit.SECONDS) + IdlingPolicies.setIdlingResourceTimeout(1, TimeUnit.SECONDS) + activityActivityTestRule.activity + .supportFragmentManager.beginTransaction() + } + + @After + fun tearDown() { + } + + @Test + fun test() { + onView(withId(R.id.menu_settings_option)).perform(click()) + onView(withId(R.id.can_menu_action)).perform(click()) + onView(supportsInputMethods()).perform(typeText("123456")) + onView(withId(R.id.next_button)).perform(click()) + onView(withText(R.string.can_status_saved)).inRoot( + withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) + ).check(matches(isDisplayed())) + } +} \ No newline at end of file From e4a06b4fc90d6fac0f808bde44bbd749defce83e Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Sat, 4 Dec 2021 21:53:11 +0200 Subject: [PATCH 08/14] Add invalidCAN test to UC4 test case and rebase --- .../tarkvaraprojekt/mobileauthapp/UC4Test.kt | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt index c41ab64..72f86b7 100644 --- a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -1,9 +1,9 @@ package com.tarkvaraprojekt.mobileauthapp import androidx.fragment.app.testing.launchFragmentInContainer -import androidx.lifecycle.Lifecycle import androidx.test.espresso.Espresso.onView import androidx.test.espresso.IdlingPolicies +import androidx.test.espresso.NoMatchingViewException import androidx.test.espresso.action.ViewActions.* import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.RootMatchers.* @@ -12,7 +12,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.rule.ActivityTestRule import org.hamcrest.CoreMatchers.`is` import org.hamcrest.CoreMatchers.not -import org.junit.Assert.* import org.junit.* import org.junit.runner.RunWith @@ -27,8 +26,8 @@ class UC4Test { @Before fun setUp() { - IdlingPolicies.setMasterPolicyTimeout(1, TimeUnit.SECONDS) - IdlingPolicies.setIdlingResourceTimeout(1, TimeUnit.SECONDS) + IdlingPolicies.setMasterPolicyTimeout(3, TimeUnit.SECONDS) + IdlingPolicies.setIdlingResourceTimeout(3, TimeUnit.SECONDS) activityActivityTestRule.activity .supportFragmentManager.beginTransaction() } @@ -37,14 +36,36 @@ class UC4Test { fun tearDown() { } - @Test - fun test() { + fun navigateToCANView() { onView(withId(R.id.menu_settings_option)).perform(click()) + try { + // Delete existing CAN + onView(withText(R.string.can_delete)).perform(click()) + } catch (ignore: NoMatchingViewException) {} + onView(withId(R.id.can_menu_action)).perform(click()) + } + + @Test + fun validCAN() { + navigateToCANView() onView(supportsInputMethods()).perform(typeText("123456")) onView(withId(R.id.next_button)).perform(click()) + onView(withText(R.string.can_status_saved)).inRoot( withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) ).check(matches(isDisplayed())) } + + @Test + fun invalidCAN() { + navigateToCANView() + onView(supportsInputMethods()).perform(typeText("12345")) + onView(withId(R.id.next_button)).perform(click()) + + onView(withText(R.string.length_can)).inRoot( + withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) + ).check(matches(isDisplayed())) + onView(withId(R.id.next_button)).check(matches(isDisplayed())) + } } \ No newline at end of file From 515eea14bb002a26ec01aa7cd8cc600868bebddc Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Mon, 6 Dec 2021 23:58:46 +0200 Subject: [PATCH 09/14] update test --- .../java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt index 72f86b7..2bd93ca 100644 --- a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -1,6 +1,6 @@ package com.tarkvaraprojekt.mobileauthapp -import androidx.fragment.app.testing.launchFragmentInContainer +//import androidx.fragment.app.testing.launchFragmentInContainer import androidx.test.espresso.Espresso.onView import androidx.test.espresso.IdlingPolicies import androidx.test.espresso.NoMatchingViewException @@ -50,7 +50,6 @@ class UC4Test { fun validCAN() { navigateToCANView() onView(supportsInputMethods()).perform(typeText("123456")) - onView(withId(R.id.next_button)).perform(click()) onView(withText(R.string.can_status_saved)).inRoot( withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) @@ -61,11 +60,6 @@ class UC4Test { fun invalidCAN() { navigateToCANView() onView(supportsInputMethods()).perform(typeText("12345")) - onView(withId(R.id.next_button)).perform(click()) - - onView(withText(R.string.length_can)).inRoot( - withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) - ).check(matches(isDisplayed())) - onView(withId(R.id.next_button)).check(matches(isDisplayed())) + onView(withText(R.string.can_helper_text)).check(matches(isDisplayed())) } } \ No newline at end of file From f274b48d68c98469e369be3d5866856495901d82 Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Tue, 7 Dec 2021 00:34:15 +0200 Subject: [PATCH 10/14] update UC4Test --- .../java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt index 2bd93ca..3c03951 100644 --- a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -6,12 +6,9 @@ import androidx.test.espresso.IdlingPolicies import androidx.test.espresso.NoMatchingViewException import androidx.test.espresso.action.ViewActions.* import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.matcher.RootMatchers.* import androidx.test.espresso.matcher.ViewMatchers.* import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.rule.ActivityTestRule -import org.hamcrest.CoreMatchers.`is` -import org.hamcrest.CoreMatchers.not import org.junit.* import org.junit.runner.RunWith @@ -49,11 +46,11 @@ class UC4Test { @Test fun validCAN() { navigateToCANView() + onView(withText(R.string.can_helper_text)).check(matches(isDisplayed())) onView(supportsInputMethods()).perform(typeText("123456")) + onView(withText(R.string.can_delete)).perform(closeSoftKeyboard()) - onView(withText(R.string.can_status_saved)).inRoot( - withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) - ).check(matches(isDisplayed())) + onView(withText(R.string.can_status_saved)).check(matches(isDisplayed())) } @Test From bf87eb1c07c97f9890e791efb0252419425d8a05 Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Sat, 4 Dec 2021 14:28:52 +0200 Subject: [PATCH 11/14] UC4 test --- .../tarkvaraprojekt/mobileauthapp/UC4Test.kt | 40 +++++++------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt index 3c03951..c41ab64 100644 --- a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -1,14 +1,18 @@ package com.tarkvaraprojekt.mobileauthapp -//import androidx.fragment.app.testing.launchFragmentInContainer +import androidx.fragment.app.testing.launchFragmentInContainer +import androidx.lifecycle.Lifecycle import androidx.test.espresso.Espresso.onView import androidx.test.espresso.IdlingPolicies -import androidx.test.espresso.NoMatchingViewException import androidx.test.espresso.action.ViewActions.* import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.RootMatchers.* import androidx.test.espresso.matcher.ViewMatchers.* import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.rule.ActivityTestRule +import org.hamcrest.CoreMatchers.`is` +import org.hamcrest.CoreMatchers.not +import org.junit.Assert.* import org.junit.* import org.junit.runner.RunWith @@ -23,8 +27,8 @@ class UC4Test { @Before fun setUp() { - IdlingPolicies.setMasterPolicyTimeout(3, TimeUnit.SECONDS) - IdlingPolicies.setIdlingResourceTimeout(3, TimeUnit.SECONDS) + IdlingPolicies.setMasterPolicyTimeout(1, TimeUnit.SECONDS) + IdlingPolicies.setIdlingResourceTimeout(1, TimeUnit.SECONDS) activityActivityTestRule.activity .supportFragmentManager.beginTransaction() } @@ -33,30 +37,14 @@ class UC4Test { fun tearDown() { } - fun navigateToCANView() { + @Test + fun test() { onView(withId(R.id.menu_settings_option)).perform(click()) - try { - // Delete existing CAN - onView(withText(R.string.can_delete)).perform(click()) - } catch (ignore: NoMatchingViewException) {} - onView(withId(R.id.can_menu_action)).perform(click()) - } - - @Test - fun validCAN() { - navigateToCANView() - onView(withText(R.string.can_helper_text)).check(matches(isDisplayed())) onView(supportsInputMethods()).perform(typeText("123456")) - onView(withText(R.string.can_delete)).perform(closeSoftKeyboard()) - - onView(withText(R.string.can_status_saved)).check(matches(isDisplayed())) - } - - @Test - fun invalidCAN() { - navigateToCANView() - onView(supportsInputMethods()).perform(typeText("12345")) - onView(withText(R.string.can_helper_text)).check(matches(isDisplayed())) + onView(withId(R.id.next_button)).perform(click()) + onView(withText(R.string.can_status_saved)).inRoot( + withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) + ).check(matches(isDisplayed())) } } \ No newline at end of file From 8d5a55c00e200eb2363a8a499e36e22b412554e8 Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Sat, 4 Dec 2021 21:53:11 +0200 Subject: [PATCH 12/14] Add invalidCAN test to UC4 test case and rebase --- .../tarkvaraprojekt/mobileauthapp/UC4Test.kt | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt index c41ab64..72f86b7 100644 --- a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -1,9 +1,9 @@ package com.tarkvaraprojekt.mobileauthapp import androidx.fragment.app.testing.launchFragmentInContainer -import androidx.lifecycle.Lifecycle import androidx.test.espresso.Espresso.onView import androidx.test.espresso.IdlingPolicies +import androidx.test.espresso.NoMatchingViewException import androidx.test.espresso.action.ViewActions.* import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.RootMatchers.* @@ -12,7 +12,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.rule.ActivityTestRule import org.hamcrest.CoreMatchers.`is` import org.hamcrest.CoreMatchers.not -import org.junit.Assert.* import org.junit.* import org.junit.runner.RunWith @@ -27,8 +26,8 @@ class UC4Test { @Before fun setUp() { - IdlingPolicies.setMasterPolicyTimeout(1, TimeUnit.SECONDS) - IdlingPolicies.setIdlingResourceTimeout(1, TimeUnit.SECONDS) + IdlingPolicies.setMasterPolicyTimeout(3, TimeUnit.SECONDS) + IdlingPolicies.setIdlingResourceTimeout(3, TimeUnit.SECONDS) activityActivityTestRule.activity .supportFragmentManager.beginTransaction() } @@ -37,14 +36,36 @@ class UC4Test { fun tearDown() { } - @Test - fun test() { + fun navigateToCANView() { onView(withId(R.id.menu_settings_option)).perform(click()) + try { + // Delete existing CAN + onView(withText(R.string.can_delete)).perform(click()) + } catch (ignore: NoMatchingViewException) {} + onView(withId(R.id.can_menu_action)).perform(click()) + } + + @Test + fun validCAN() { + navigateToCANView() onView(supportsInputMethods()).perform(typeText("123456")) onView(withId(R.id.next_button)).perform(click()) + onView(withText(R.string.can_status_saved)).inRoot( withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) ).check(matches(isDisplayed())) } + + @Test + fun invalidCAN() { + navigateToCANView() + onView(supportsInputMethods()).perform(typeText("12345")) + onView(withId(R.id.next_button)).perform(click()) + + onView(withText(R.string.length_can)).inRoot( + withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) + ).check(matches(isDisplayed())) + onView(withId(R.id.next_button)).check(matches(isDisplayed())) + } } \ No newline at end of file From a61ea0b6cc9bd790d0aff730bc6f1b94e9a39e51 Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Sat, 4 Dec 2021 14:28:52 +0200 Subject: [PATCH 13/14] UC4 test --- .../tarkvaraprojekt/mobileauthapp/UC4Test.kt | 35 ++++--------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt index 72f86b7..c41ab64 100644 --- a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -1,9 +1,9 @@ package com.tarkvaraprojekt.mobileauthapp import androidx.fragment.app.testing.launchFragmentInContainer +import androidx.lifecycle.Lifecycle import androidx.test.espresso.Espresso.onView import androidx.test.espresso.IdlingPolicies -import androidx.test.espresso.NoMatchingViewException import androidx.test.espresso.action.ViewActions.* import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.RootMatchers.* @@ -12,6 +12,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.rule.ActivityTestRule import org.hamcrest.CoreMatchers.`is` import org.hamcrest.CoreMatchers.not +import org.junit.Assert.* import org.junit.* import org.junit.runner.RunWith @@ -26,8 +27,8 @@ class UC4Test { @Before fun setUp() { - IdlingPolicies.setMasterPolicyTimeout(3, TimeUnit.SECONDS) - IdlingPolicies.setIdlingResourceTimeout(3, TimeUnit.SECONDS) + IdlingPolicies.setMasterPolicyTimeout(1, TimeUnit.SECONDS) + IdlingPolicies.setIdlingResourceTimeout(1, TimeUnit.SECONDS) activityActivityTestRule.activity .supportFragmentManager.beginTransaction() } @@ -36,36 +37,14 @@ class UC4Test { fun tearDown() { } - fun navigateToCANView() { - onView(withId(R.id.menu_settings_option)).perform(click()) - try { - // Delete existing CAN - onView(withText(R.string.can_delete)).perform(click()) - } catch (ignore: NoMatchingViewException) {} - - onView(withId(R.id.can_menu_action)).perform(click()) - } - @Test - fun validCAN() { - navigateToCANView() + fun test() { + onView(withId(R.id.menu_settings_option)).perform(click()) + onView(withId(R.id.can_menu_action)).perform(click()) onView(supportsInputMethods()).perform(typeText("123456")) onView(withId(R.id.next_button)).perform(click()) - onView(withText(R.string.can_status_saved)).inRoot( withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) ).check(matches(isDisplayed())) } - - @Test - fun invalidCAN() { - navigateToCANView() - onView(supportsInputMethods()).perform(typeText("12345")) - onView(withId(R.id.next_button)).perform(click()) - - onView(withText(R.string.length_can)).inRoot( - withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) - ).check(matches(isDisplayed())) - onView(withId(R.id.next_button)).check(matches(isDisplayed())) - } } \ No newline at end of file From 5c1f141405b974d12570d35c51327719c597c3e7 Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Tue, 7 Dec 2021 00:37:38 +0200 Subject: [PATCH 14/14] rebase --- .../tarkvaraprojekt/mobileauthapp/UC4Test.kt | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt index c41ab64..3c03951 100644 --- a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -1,18 +1,14 @@ package com.tarkvaraprojekt.mobileauthapp -import androidx.fragment.app.testing.launchFragmentInContainer -import androidx.lifecycle.Lifecycle +//import androidx.fragment.app.testing.launchFragmentInContainer import androidx.test.espresso.Espresso.onView import androidx.test.espresso.IdlingPolicies +import androidx.test.espresso.NoMatchingViewException import androidx.test.espresso.action.ViewActions.* import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.matcher.RootMatchers.* import androidx.test.espresso.matcher.ViewMatchers.* import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.rule.ActivityTestRule -import org.hamcrest.CoreMatchers.`is` -import org.hamcrest.CoreMatchers.not -import org.junit.Assert.* import org.junit.* import org.junit.runner.RunWith @@ -27,8 +23,8 @@ class UC4Test { @Before fun setUp() { - IdlingPolicies.setMasterPolicyTimeout(1, TimeUnit.SECONDS) - IdlingPolicies.setIdlingResourceTimeout(1, TimeUnit.SECONDS) + IdlingPolicies.setMasterPolicyTimeout(3, TimeUnit.SECONDS) + IdlingPolicies.setIdlingResourceTimeout(3, TimeUnit.SECONDS) activityActivityTestRule.activity .supportFragmentManager.beginTransaction() } @@ -37,14 +33,30 @@ class UC4Test { fun tearDown() { } - @Test - fun test() { + fun navigateToCANView() { onView(withId(R.id.menu_settings_option)).perform(click()) + try { + // Delete existing CAN + onView(withText(R.string.can_delete)).perform(click()) + } catch (ignore: NoMatchingViewException) {} + onView(withId(R.id.can_menu_action)).perform(click()) + } + + @Test + fun validCAN() { + navigateToCANView() + onView(withText(R.string.can_helper_text)).check(matches(isDisplayed())) onView(supportsInputMethods()).perform(typeText("123456")) - onView(withId(R.id.next_button)).perform(click()) - onView(withText(R.string.can_status_saved)).inRoot( - withDecorView(not(`is`(activityActivityTestRule.activity.getWindow().getDecorView()))) - ).check(matches(isDisplayed())) + onView(withText(R.string.can_delete)).perform(closeSoftKeyboard()) + + onView(withText(R.string.can_status_saved)).check(matches(isDisplayed())) + } + + @Test + fun invalidCAN() { + navigateToCANView() + onView(supportsInputMethods()).perform(typeText("12345")) + onView(withText(R.string.can_helper_text)).check(matches(isDisplayed())) } } \ No newline at end of file