Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
44afe84
Apply LoggerCheckHelper.kt (applied for those NativeAuthPublicClientA…
Yuki-YuXin Oct 23, 2024
17f6a07
Update the NativeAuthPublicClientApplicationAbstractTest structure to…
Yuki-YuXin Oct 23, 2024
3a1df81
Finish sign up otp
Yuki-YuXin Oct 29, 2024
b1150ff
Merge branch 'dev' into yuki/signup-e2e
Yuki-YuXin Oct 31, 2024
18326e3
Remove ignore tag
Yuki-YuXin Oct 31, 2024
839611a
Comment out the logger check
Yuki-YuXin Oct 31, 2024
45b81a6
Clean up the name
Yuki-YuXin Oct 31, 2024
145ff57
Remove logger
Yuki-YuXin Oct 31, 2024
122b73c
Add loggerCheckHelper
Yuki-YuXin Oct 31, 2024
43f9339
loggerCheck = setupLoggerCheckHelper()
Yuki-YuXin Oct 31, 2024
db78d7f
Double checking the work scopes have been all included
Yuki-YuXin Nov 1, 2024
a2da64d
Remove LoggerCheckHelper.kt experiment since it is out of scope
Yuki-YuXin Nov 19, 2024
7178cec
Fix SignUpEmailPasswordTest.kt testSignInAfterSignUp()
Yuki-YuXin Nov 20, 2024
e897b06
Remove LoggerCheckHelper.kt
Yuki-YuXin Nov 20, 2024
627ef91
Merge branch 'dev' into yuki/signup-e2e
Yuki-YuXin Nov 20, 2024
91bac62
Remove @Ignore MFA
Yuki-YuXin Nov 20, 2024
4b8c24c
Merge remote-tracking branch 'origin/yuki/signup-e2e' into yuki/signu…
Yuki-YuXin Nov 20, 2024
6a1710d
Re-add the ignore tag because of the failure
Yuki-YuXin Nov 21, 2024
242b66c
Address testResendCode comment and situation
Yuki-YuXin Nov 21, 2024
bd75314
ALl test cases apply new AbstractTest to extract configuration initia…
Yuki-YuXin Nov 26, 2024
6027036
Merge branch 'dev' into yuki/signup-e2e
Yuki-YuXin Nov 26, 2024
c2e96b6
Remove overlap MFA test case
Yuki-YuXin Nov 26, 2024
38f1f2d
Add config modification for the testSuccess, which causes the failure
Yuki-YuXin Nov 26, 2024
adc64bc
Merge branch 'dev' into yuki/signup-e2e
Yuki-YuXin Nov 27, 2024
fa13a6a
Address comments
Yuki-YuXin Nov 27, 2024
5abc55e
Merge remote-tracking branch 'origin/yuki/signup-e2e' into yuki/signu…
Yuki-YuXin Nov 27, 2024
4cfcce0
Use SIGN_IN_MFA_MULTI_AUTH config instead of SINGLE for the failed MF…
Yuki-YuXin Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,8 @@ import com.microsoft.identity.internal.testutils.labutils.LabConstants
import com.microsoft.identity.internal.testutils.labutils.LabUserHelper
import com.microsoft.identity.internal.testutils.labutils.LabUserQuery
import com.microsoft.identity.internal.testutils.nativeauth.ConfigType
import com.microsoft.identity.internal.testutils.nativeauth.api.TemporaryEmailService
import com.microsoft.identity.internal.testutils.nativeauth.api.models.NativeAuthTestConfig
import com.microsoft.identity.nativeauth.INativeAuthPublicClientApplication
import com.microsoft.identity.nativeauth.statemachine.errors.SubmitCodeError
import com.microsoft.identity.nativeauth.statemachine.results.MFASubmitChallengeResult
import com.microsoft.identity.nativeauth.statemachine.results.ResetPasswordSubmitCodeResult
import com.microsoft.identity.nativeauth.statemachine.results.SignInSubmitCodeResult
import com.microsoft.identity.nativeauth.statemachine.results.SignUpSubmitCodeResult
import com.microsoft.identity.nativeauth.statemachine.states.MFARequiredState
import com.microsoft.identity.nativeauth.statemachine.states.ResetPasswordCodeRequiredState
import com.microsoft.identity.nativeauth.statemachine.states.SignInCodeRequiredState
import com.microsoft.identity.nativeauth.statemachine.states.SignUpCodeRequiredState
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.setMain
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.client.e2e.tests.network.nativeauth

import android.app.Activity
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.microsoft.identity.client.ILoggerCallback
import com.microsoft.identity.client.Logger
import com.microsoft.identity.client.PublicClientApplication
import com.microsoft.identity.client.e2e.shadows.ShadowAndroidSdkStorageEncryptionManager
import com.microsoft.identity.client.e2e.tests.IPublicClientApplicationTest
import com.microsoft.identity.client.exception.MsalException
import com.microsoft.identity.common.internal.controllers.CommandDispatcherHelper
import com.microsoft.identity.internal.testutils.TestUtils
import com.microsoft.identity.internal.testutils.labutils.KeyVaultFetchHelper
import com.microsoft.identity.internal.testutils.labutils.LabConstants
import com.microsoft.identity.internal.testutils.labutils.LabUserHelper
import com.microsoft.identity.internal.testutils.labutils.LabUserQuery
import com.microsoft.identity.internal.testutils.nativeauth.ConfigType
import com.microsoft.identity.internal.testutils.nativeauth.api.models.NativeAuthTestConfig
import com.microsoft.identity.nativeauth.INativeAuthPublicClientApplication
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.runner.RunWith
import org.mockito.Mockito
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode

// TODO: move to "PAUSED". A work in RoboTestUtils will be needed though.
@LooperMode(LooperMode.Mode.LEGACY)
@RunWith(RobolectricTestRunner::class)
@Config(shadows = [ShadowAndroidSdkStorageEncryptionManager::class])
abstract class NativeAuthPublicClientApplicationAnotherAbstractTest : IPublicClientApplicationTest {
companion object{
const val SHARED_PREFERENCES_NAME = "com.microsoft.identity.client.account_credential_cache"
const val INVALID_EMAIL = "invalid_email"
const val INVALID_PASSWORD = "invalid_password"
}

private lateinit var context: Context
private lateinit var activity: Activity

// Remove default Coroutine test timeout of 10 seconds.
private val testDispatcher = StandardTestDispatcher()

override fun getConfigFilePath(): String {
return "" // Not needed for native auth flows
}

@Before
open fun setup() {
context = ApplicationProvider.getApplicationContext()
activity = Mockito.mock(Activity::class.java)
Mockito.`when`(activity.applicationContext).thenReturn(context)
CommandDispatcherHelper.clear()
Dispatchers.setMain(testDispatcher)
}

@After
open fun cleanup() {
// remove everything from cache after test ends
TestUtils.clearCache(SHARED_PREFERENCES_NAME)
}

fun getSafePassword(): String {
val query = LabUserQuery()
query.federationProvider = LabConstants.FederationProvider.CIAM_CUD
query.signInAudience = LabConstants.SignInAudience.AZURE_AD_MY_ORG
val credential = LabUserHelper.getCredentials(query)
return credential.password
}

private fun getConfigsThroughSecretValue(): Map<String, NativeAuthTestConfig.Config>? {
val secretValue = KeyVaultFetchHelper.getSecretForBuildAutomation("msalandroidnativeauthautomationconfjsonfile")
val type = TypeToken.getParameterized(
Map::class.java,
String::class.java,
NativeAuthTestConfig.Config::class.java
).type

return Gson().fromJson(secretValue, type)
}

fun getConfig(configType: ConfigType): NativeAuthTestConfig.Config {
val secretValue = getConfigsThroughSecretValue()
return secretValue?.get(configType.stringValue)
?: throw IllegalStateException("Config not $secretValue")
}

fun setupPCA(config: NativeAuthTestConfig.Config, challengeTypes: List<String>): INativeAuthPublicClientApplication {
return try {
PublicClientApplication.createNativeAuthPublicClientApplication(
context,
config.clientId,
config.authorityUrl,
null,
challengeTypes
)
} catch (e: MsalException) {
Assert.fail(e.message)
throw e
}
}

fun <T> retryOperation(
maxRetries: Int = 5,
authFlow: () -> T
) {
var retryCount = 0
var shouldRetry = true

while (shouldRetry) {
try {
authFlow()
shouldRetry = false // authFlow() has succeeded, so we don't need to retry.
} catch (e: Exception) {
//1secmail occasionally has a delay for emails to arrive / return from the API, or throws an internal server error, which causes tests to fail
//In this case, retry the test
if (retryCount >= maxRetries) {
Assert.fail(e.message)
shouldRetry = false
} else {
retryCount++
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ import com.microsoft.identity.nativeauth.statemachine.errors.ResetPasswordError
import com.microsoft.identity.nativeauth.statemachine.results.ResetPasswordResult
import com.microsoft.identity.nativeauth.statemachine.results.ResetPasswordStartResult
import com.microsoft.identity.nativeauth.statemachine.results.ResetPasswordSubmitCodeResult
import com.microsoft.identity.nativeauth.statemachine.results.SignUpResult
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.Assert
import org.junit.Ignore
import org.junit.Test

class SSPRTest : NativeAuthPublicClientApplicationAbstractTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class SignInEmailPasswordTest : NativeAuthPublicClientApplicationAbstractTest()
Assert.assertTrue((result as SignInError).isInvalidCredentials())
}

@Test
@Ignore("Ignore until MFA is available on test slice")
@Test
fun testSignInMFASimple() = runTest {
val nativeAuthConfigField = application.javaClass.getDeclaredField("nativeAuthConfig")
nativeAuthConfigField.isAccessible = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Ignore
import org.junit.Test
import java.lang.Thread.sleep

class SignInMFATest : NativeAuthPublicClientApplicationAbstractTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ import com.microsoft.identity.client.e2e.utils.assertResult
import com.microsoft.identity.internal.testutils.nativeauth.ConfigType
import com.microsoft.identity.internal.testutils.nativeauth.api.TemporaryEmailService
import com.microsoft.identity.nativeauth.UserAttributes
import com.microsoft.identity.nativeauth.statemachine.results.SignInResult
import com.microsoft.identity.nativeauth.statemachine.results.SignUpResult
import kotlinx.coroutines.runBlocking
import org.junit.Assert
import org.junit.Ignore
import org.junit.Test

class SignUpEmailOTPAttributesTest : NativeAuthPublicClientApplicationAbstractTest() {
Expand Down
Loading