mirror of
https://github.com/TanelOrumaa/Estonian-ID-card-mobile-authenticator-POC.git
synced 2025-08-29 23:00:59 +03:00
Compare commits
2 Commits
compatibil
...
Tests
Author | SHA1 | Date | |
---|---|---|---|
|
6bb9638418 | ||
|
fc3161be51 |
@@ -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"
|
||||
|
@@ -0,0 +1,30 @@
|
||||
package com.tarkvaraprojekt.mobileauthapp
|
||||
|
||||
//import androidx.fragment.app.testing.launchFragmentInContainer
|
||||
import androidx.test.espresso.IdlingPolicies
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.rule.ActivityTestRule
|
||||
|
||||
import org.junit.*
|
||||
import org.junit.runner.RunWith
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
open class BaseUCTest {
|
||||
@get:Rule
|
||||
var activityActivityTestRule: ActivityTestRule<MainActivity> = ActivityTestRule(
|
||||
MainActivity::class.java
|
||||
)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
IdlingPolicies.setMasterPolicyTimeout(3, TimeUnit.SECONDS)
|
||||
IdlingPolicies.setIdlingResourceTimeout(3, TimeUnit.SECONDS)
|
||||
activityActivityTestRule.activity
|
||||
.supportFragmentManager.beginTransaction()
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
package com.tarkvaraprojekt.mobileauthapp
|
||||
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.NoMatchingViewException
|
||||
import androidx.test.espresso.action.ViewActions.*
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers.*
|
||||
|
||||
import org.junit.*
|
||||
|
||||
class UC12Test : BaseUCTest() {
|
||||
|
||||
private fun navigateToPINView() {
|
||||
onView(withId(R.id.menu_settings_option)).perform(click())
|
||||
try {
|
||||
// Delete existing PIN
|
||||
onView(withText(R.string.pin1_delete)).perform(click())
|
||||
} catch (ignore: NoMatchingViewException) {}
|
||||
|
||||
onView(withId(R.id.pin_menu_action)).perform(click())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun validPIN() {
|
||||
navigateToPINView()
|
||||
onView(withText(R.string.pin_helper_text)).check(matches(isDisplayed()))
|
||||
onView(supportsInputMethods()).perform(typeText("0000"))
|
||||
onView(withText(R.string.continue_button)).perform(click())
|
||||
|
||||
onView(withText(R.string.pin_status_saved)).check(matches(isDisplayed()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tooShortPIN() {
|
||||
navigateToPINView()
|
||||
onView(supportsInputMethods()).perform(typeText("000"))
|
||||
onView(withText(R.string.continue_button)).perform(click())
|
||||
|
||||
onView(withText(R.string.pin_helper_text)).check(matches(isDisplayed()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tooLongPIN() {
|
||||
navigateToPINView()
|
||||
onView(supportsInputMethods()).perform(typeText("0".repeat(13)))
|
||||
onView(withText(R.string.continue_button)).perform(click())
|
||||
|
||||
onView(withText(R.string.pin_helper_text)).check(matches(isDisplayed()))
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package com.tarkvaraprojekt.mobileauthapp
|
||||
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.NoMatchingViewException
|
||||
import androidx.test.espresso.action.ViewActions.*
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers.*
|
||||
|
||||
import org.junit.*
|
||||
|
||||
class UC4Test : BaseUCTest() {
|
||||
|
||||
private 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(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()))
|
||||
}
|
||||
}
|
@@ -20,14 +20,11 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.koushikdutta.ion.Ion
|
||||
import com.tarkvaraprojekt.mobileauthapp.NFC.Comms
|
||||
import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentHomeBinding
|
||||
import com.tarkvaraprojekt.mobileauthapp.model.ParametersViewModel
|
||||
import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel
|
||||
import java.lang.Exception
|
||||
import java.lang.RuntimeException
|
||||
import java.net.URL
|
||||
|
||||
/**
|
||||
* HomeFragment is only shown to the user when then the user launches the application. When the application
|
||||
@@ -107,42 +104,15 @@ class HomeFragment : Fragment() {
|
||||
intentParams.setChallenge(requireActivity().intent.getStringExtra("challenge")!!)
|
||||
intentParams.setAuthUrl(requireActivity().intent.getStringExtra("authUrl")!!)
|
||||
intentParams.setOrigin(requireActivity().intent.getStringExtra("originUrl")!!)
|
||||
goToTheNextFragment(mobile)
|
||||
} else { //Website
|
||||
/*
|
||||
var challenge = requireActivity().intent.data!!.getQueryParameter("challenge")!!
|
||||
// TODO: Since due to encoding plus gets converted to space, temporary solution is to replace it back.
|
||||
challenge = challenge.replace(" ", "+")
|
||||
intentParams.setChallenge(challenge)
|
||||
intentParams.setAuthUrl(requireActivity().intent.data!!.getQueryParameter("authUrl")!!)
|
||||
intentParams.setOrigin(requireActivity().intent.data!!.getQueryParameter("originUrl")!!)
|
||||
*/
|
||||
var getAuthChallengeUrl = requireActivity().intent.data!!.getQueryParameter("getAuthChallengeUrl")!!
|
||||
getAuthChallengeUrl = getAuthChallengeUrl.substring(1, getAuthChallengeUrl.length - 1)
|
||||
var postAuthTokenUrl = requireActivity().intent.data!!.getQueryParameter("postAuthTokenUrl")!!
|
||||
postAuthTokenUrl = postAuthTokenUrl.substring(1, postAuthTokenUrl.length - 1)
|
||||
val headers = requireActivity().intent.data!!.getQueryParameter("headers")!!
|
||||
intentParams.setAuthUrl(postAuthTokenUrl)
|
||||
val address = "https://" + URL(getAuthChallengeUrl).host
|
||||
intentParams.setOrigin(address)
|
||||
intentParams.setHeaders(headers)
|
||||
Ion.getDefault(activity).conscryptMiddleware.enable(false)
|
||||
Ion.with(activity)
|
||||
.load(getAuthChallengeUrl)
|
||||
.asJsonObject()
|
||||
.setCallback { _, result ->
|
||||
try {
|
||||
// Get data from the result and call launchAuth method
|
||||
val challenge = result.asJsonObject["nonce"].toString().replace("\"", "")
|
||||
intentParams.setChallenge(challenge)
|
||||
goToTheNextFragment(mobile)
|
||||
} catch (e: Exception) {
|
||||
Log.i("GETrequest", "was unsuccessful")
|
||||
throw RuntimeException()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
goToTheNextFragment(mobile)
|
||||
} catch (e: Exception) {
|
||||
// There was a problem with parameters, which means that authentication is not possible.
|
||||
// In that case we will cancel the authentication immediately as it would be waste of the user's time to carry on
|
||||
|
@@ -16,9 +16,6 @@ class ParametersViewModel: ViewModel() {
|
||||
private var _origin: String = ""
|
||||
val origin get() = _origin
|
||||
|
||||
private var _headers: String = ""
|
||||
val headers get() =_headers
|
||||
|
||||
fun setChallenge(newChallenge: String) {
|
||||
_challenge = newChallenge
|
||||
}
|
||||
@@ -34,8 +31,4 @@ class ParametersViewModel: ViewModel() {
|
||||
fun setOrigin(newOrigin: String) {
|
||||
_origin = newOrigin
|
||||
}
|
||||
|
||||
fun setHeaders(newHeaders: String) {
|
||||
_headers = newHeaders
|
||||
}
|
||||
}
|
@@ -11,7 +11,6 @@ import androidx.activity.result.contract.ActivityResultContracts
|
||||
import com.example.testmobileapp.databinding.ActivityMainBinding
|
||||
import com.koushikdutta.ion.Ion
|
||||
import org.json.JSONObject
|
||||
import java.net.URL
|
||||
|
||||
/**
|
||||
* Base url where the requests should be made. Add yours here. It must use https.
|
||||
@@ -32,7 +31,7 @@ class MainActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
Log.i("myLoggingStuff", URL("https://www.google.ee/?hl=et").host.toString())
|
||||
|
||||
authLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { response ->
|
||||
if (response.resultCode == Activity.RESULT_OK) {
|
||||
binding.loginTextView.text = getString(R.string.auth_success)
|
||||
|
Reference in New Issue
Block a user