@@ -23,6 +23,7 @@ import com.nhaarman.mockitokotlin2.reset
23
23
import com.nhaarman.mockitokotlin2.stub
24
24
import com.nhaarman.mockitokotlin2.times
25
25
import com.nhaarman.mockitokotlin2.verify
26
+ import kotlinx.coroutines.runBlocking
26
27
import org.assertj.core.api.Assertions.assertThat
27
28
import org.assertj.core.api.Assertions.assertThatThrownBy
28
29
import org.assertj.core.api.Condition
@@ -42,6 +43,7 @@ import software.amazon.awssdk.http.SdkHttpFullResponse
42
43
import software.aws.toolkits.core.credentials.CredentialIdentifier
43
44
import software.aws.toolkits.core.credentials.CredentialsChangeEvent
44
45
import software.aws.toolkits.core.credentials.CredentialsChangeListener
46
+ import software.aws.toolkits.core.credentials.sso.SsoCache
45
47
import software.aws.toolkits.core.region.ToolkitRegionProvider
46
48
import software.aws.toolkits.core.rules.SystemPropertyHelper
47
49
import software.aws.toolkits.jetbrains.core.credentials.profiles.ProfileCredentialProviderFactory
@@ -648,6 +650,62 @@ class ProfileCredentialProviderFactoryTest {
648
650
}
649
651
}
650
652
653
+ @Test
654
+ fun mfaProfilesAlwaysNeedLogin () {
655
+ profileFile.writeToFile(
656
+ """
657
+ [profile role]
658
+ role_arn=arn1
659
+ role_session_name=testSession
660
+ external_id=externalId
661
+ mfa_serial=someSerialArn
662
+ source_profile=source_profile
663
+
664
+ [profile source_profile]
665
+ aws_access_key_id=BarAccessKey
666
+ aws_secret_access_key=BarSecretKey
667
+ """ .trimIndent()
668
+ )
669
+
670
+ createProviderFactory()
671
+
672
+ assertThat(runBlocking { (findCredentialIdentifier(" role" ) as InteractiveCredential ).userActionRequired() }).isTrue()
673
+ }
674
+
675
+ @Test
676
+ fun ssoProfilesCanIdentifyIfTheyNeedLogin () {
677
+ profileFile.writeToFile(
678
+ """
679
+ [profile valid]
680
+ sso_start_url=ValidUrl
681
+ sso_region=us-east-2
682
+ sso_account_id=111222333444
683
+ sso_role_name=RoleName
684
+
685
+ [profile expired]
686
+ sso_start_url=ExpiredUrl
687
+ sso_region=us-east-2
688
+ sso_account_id=111222333444
689
+ sso_role_name=RoleName
690
+
691
+ [profile chain]
692
+ source_profile = valid
693
+ role_arn = AssumedRoleArn
694
+ """ .trimIndent()
695
+ )
696
+
697
+ val ssoCache = mock<SsoCache > {
698
+ on { loadAccessToken((" ValidUrl" )) }.thenReturn(mock())
699
+ on { loadAccessToken((" ExpiredUrl" )) }.thenReturn(null )
700
+ }
701
+
702
+ createProviderFactory(ssoCache)
703
+
704
+ assertThat(runBlocking { (findCredentialIdentifier(" valid" ) as InteractiveCredential ).userActionRequired() }).isFalse()
705
+ assertThat(runBlocking { (findCredentialIdentifier(" expired" ) as InteractiveCredential ).userActionRequired() }).isTrue()
706
+ assertThat(runBlocking { (findCredentialIdentifier(" chain" ) as InteractiveCredential ).userActionRequired() }).isFalse()
707
+ }
708
+
651
709
private fun File.writeToFile (content : String ) {
652
710
WriteCommandAction .runWriteCommandAction(projectRule.project) {
653
711
FileUtil .createIfDoesntExist(this )
@@ -663,8 +721,8 @@ class ProfileCredentialProviderFactoryTest {
663
721
}
664
722
}
665
723
666
- private fun createProviderFactory (): ProfileCredentialProviderFactory {
667
- val factory = ProfileCredentialProviderFactory ()
724
+ private fun createProviderFactory (ssoCache : SsoCache = mock() ): ProfileCredentialProviderFactory {
725
+ val factory = ProfileCredentialProviderFactory (ssoCache )
668
726
factory.setUp(profileLoadCallback)
669
727
670
728
return factory
0 commit comments