|
1 | 1 | package com.auth0.android.authentication |
2 | 2 |
|
3 | 3 | import com.auth0.android.authentication.MfaException.* |
4 | | -import com.auth0.android.authentication.storage.CredentialsManagerException |
5 | | -import com.auth0.android.result.MfaFactor |
6 | | -import com.auth0.android.result.MfaRequiredErrorPayload |
7 | | -import com.auth0.android.result.MfaRequirements |
8 | 4 | import org.hamcrest.MatcherAssert.assertThat |
9 | 5 | import org.hamcrest.Matchers.* |
10 | 6 | import org.junit.Test |
@@ -303,110 +299,4 @@ public class MfaExceptionTest { |
303 | 299 | assertThat(verifyException.message, containsString("custom_error_code")) |
304 | 300 | } |
305 | 301 |
|
306 | | - // ========== CredentialsManagerException MFA Tests ========== |
307 | | - |
308 | | - @Test |
309 | | - public fun shouldCredentialsManagerExceptionHaveNullMfaPayloadByDefault(): Unit { |
310 | | - val exception = CredentialsManagerException.RENEW_FAILED |
311 | | - |
312 | | - assertThat(exception.mfaRequiredErrorPayload, `is`(nullValue())) |
313 | | - assertThat(exception.mfaToken, `is`(nullValue())) |
314 | | - } |
315 | | - |
316 | | - @Test |
317 | | - public fun shouldCredentialsManagerExceptionMfaRequiredHaveCorrectMessage(): Unit { |
318 | | - val exception = CredentialsManagerException.MFA_REQUIRED |
319 | | - |
320 | | - assertThat(exception.message, containsString("Multi-factor authentication is required")) |
321 | | - } |
322 | | - |
323 | | - @Test |
324 | | - public fun shouldCredentialsManagerExceptionMfaTokenReturnCorrectValue(): Unit { |
325 | | - // Create an MFA payload with a token |
326 | | - val mfaPayload = MfaRequiredErrorPayload( |
327 | | - error = "mfa_required", |
328 | | - errorDescription = "Multifactor authentication required", |
329 | | - mfaToken = "test_mfa_token_123", |
330 | | - mfaRequirements = null |
331 | | - ) |
332 | | - |
333 | | - // Use reflection to create exception with payload since constructor is internal |
334 | | - val exceptionClass = CredentialsManagerException::class.java |
335 | | - val constructor = exceptionClass.getDeclaredConstructor( |
336 | | - CredentialsManagerException.Code::class.java, |
337 | | - String::class.java, |
338 | | - Throwable::class.java, |
339 | | - MfaRequiredErrorPayload::class.java |
340 | | - ) |
341 | | - constructor.isAccessible = true |
342 | | - |
343 | | - val codeClass = Class.forName("com.auth0.android.authentication.storage.CredentialsManagerException\$Code") |
344 | | - val mfaRequiredCode = codeClass.getDeclaredField("MFA_REQUIRED").get(null) |
345 | | - |
346 | | - val exception = constructor.newInstance( |
347 | | - mfaRequiredCode, |
348 | | - "MFA required", |
349 | | - null, |
350 | | - mfaPayload |
351 | | - ) as CredentialsManagerException |
352 | | - |
353 | | - assertThat(exception.mfaRequiredErrorPayload, `is`(notNullValue())) |
354 | | - assertThat(exception.mfaToken, `is`("test_mfa_token_123")) |
355 | | - assertThat(exception.mfaRequiredErrorPayload?.mfaToken, `is`("test_mfa_token_123")) |
356 | | - } |
357 | | - |
358 | | - @Test |
359 | | - public fun shouldCredentialsManagerExceptionMfaPayloadContainRequirements(): Unit { |
360 | | - // Create MFA requirements with challenge |
361 | | - val challengeFactors = listOf(MfaFactor(type = "otp"), MfaFactor(type = "sms")) |
362 | | - val requirements = MfaRequirements(challenge = challengeFactors, enroll = null) |
363 | | - val mfaPayload = MfaRequiredErrorPayload( |
364 | | - error = "mfa_required", |
365 | | - errorDescription = "Multifactor authentication required", |
366 | | - mfaToken = "token_with_requirements", |
367 | | - mfaRequirements = requirements |
368 | | - ) |
369 | | - |
370 | | - // Use reflection to create exception with payload |
371 | | - val exceptionClass = CredentialsManagerException::class.java |
372 | | - val constructor = exceptionClass.getDeclaredConstructor( |
373 | | - CredentialsManagerException.Code::class.java, |
374 | | - String::class.java, |
375 | | - Throwable::class.java, |
376 | | - MfaRequiredErrorPayload::class.java |
377 | | - ) |
378 | | - constructor.isAccessible = true |
379 | | - |
380 | | - val codeClass = Class.forName("com.auth0.android.authentication.storage.CredentialsManagerException\$Code") |
381 | | - val mfaRequiredCode = codeClass.getDeclaredField("MFA_REQUIRED").get(null) |
382 | | - |
383 | | - val exception = constructor.newInstance( |
384 | | - mfaRequiredCode, |
385 | | - "MFA required", |
386 | | - null, |
387 | | - mfaPayload |
388 | | - ) as CredentialsManagerException |
389 | | - |
390 | | - assertThat(exception.mfaRequiredErrorPayload, `is`(notNullValue())) |
391 | | - assertThat(exception.mfaRequiredErrorPayload?.mfaRequirements, `is`(notNullValue())) |
392 | | - assertThat(exception.mfaRequiredErrorPayload?.mfaRequirements?.challenge?.map { it.type }, `is`(listOf("otp", "sms"))) |
393 | | - } |
394 | | - |
395 | | - @Test |
396 | | - public fun shouldCredentialsManagerExceptionEqualityIgnoreMfaPayload(): Unit { |
397 | | - // Two MFA_REQUIRED exceptions should be equal regardless of payload |
398 | | - val exception1 = CredentialsManagerException.MFA_REQUIRED |
399 | | - val exception2 = CredentialsManagerException.MFA_REQUIRED |
400 | | - |
401 | | - assertThat(exception1, `is`(exception2)) |
402 | | - assertThat(exception1.hashCode(), `is`(exception2.hashCode())) |
403 | | - } |
404 | | - |
405 | | - @Test |
406 | | - public fun shouldCredentialsManagerExceptionStaticInstancesBeDistinct(): Unit { |
407 | | - assertThat(CredentialsManagerException.MFA_REQUIRED, `is`(not(CredentialsManagerException.RENEW_FAILED))) |
408 | | - assertThat(CredentialsManagerException.MFA_REQUIRED, `is`(not(CredentialsManagerException.NO_CREDENTIALS))) |
409 | | - assertThat(CredentialsManagerException.MFA_REQUIRED, `is`(not(CredentialsManagerException.API_ERROR))) |
410 | | - } |
411 | | - |
412 | 302 | } |
0 commit comments