@@ -670,33 +670,107 @@ def test_set_cluster_credentials_refreshes_stale_credentials(
670670 )
671671
672672
673+ def test_get_authentication_type_for_iam_with_profile ():
674+ provider = AWSCredentialsProvider ()
675+ provider .profile = "test"
676+ assert IamHelper .get_authentication_type (provider ) == IamHelper .IAMAuthenticationType .PROFILE
677+
678+
679+ def test_get_authentication_type_for_iam_with_key_session ():
680+ provider = AWSCredentialsProvider ()
681+ provider .access_key_id = "test_key"
682+ provider .session_token = "test_token"
683+ provider .secret_access_key = "test_secret_key"
684+ assert IamHelper .get_authentication_type (provider ) == IamHelper .IAMAuthenticationType .IAM_KEYS_WITH_SESSION
685+
686+
687+ def test_get_authentication_type_for_iam_with_key ():
688+ provider = AWSCredentialsProvider ()
689+ provider .access_key_id = "test_key"
690+ provider .secret_access_key = "test_secret_key"
691+ assert IamHelper .get_authentication_type (provider ) == IamHelper .IAMAuthenticationType .IAM_KEYS
692+
693+
694+ def test_get_authentication_type_for_iam_with_plugin ():
695+ provider = BrowserSamlCredentialsProvider ()
696+ assert IamHelper .get_authentication_type (provider ) == IamHelper .IAMAuthenticationType .PLUGIN
697+
698+
673699@pytest .mark .parametrize (
674- "conn_params, exp_result" ,
700+ "conn_params, provider, exp_result" ,
675701 (
676- ({"credentials_provider" : "BrowserSamlCredentialsProvider" }, IamHelper .GetClusterCredentialsAPIType .IAM_V1 ),
677- ({"group_federation" : True }, IamHelper .GetClusterCredentialsAPIType .IAM_V2 ),
678- ({"is_serverless" : True }, IamHelper .GetClusterCredentialsAPIType .SERVERLESS_V1 ),
679- ({"is_serverless" : True , "group_federation" : True }, IamHelper .GetClusterCredentialsAPIType .IAM_V2 ),
702+ (
703+ {"credentials_provider" : "BrowserSamlCredentialsProvider" },
704+ IamHelper .IAMAuthenticationType .PLUGIN ,
705+ IamHelper .GetClusterCredentialsAPIType .IAM_V1 ,
706+ ),
707+ (
708+ {"group_federation" : True },
709+ IamHelper .IAMAuthenticationType .PROFILE ,
710+ IamHelper .GetClusterCredentialsAPIType .IAM_V2 ,
711+ ),
712+ (
713+ {"is_serverless" : True },
714+ IamHelper .IAMAuthenticationType .PROFILE ,
715+ IamHelper .GetClusterCredentialsAPIType .SERVERLESS_V1 ,
716+ ),
717+ (
718+ {"is_serverless" : True , "group_federation" : True },
719+ IamHelper .IAMAuthenticationType .IAM_KEYS ,
720+ IamHelper .GetClusterCredentialsAPIType .IAM_V2 ,
721+ ),
722+ (
723+ {"group_federation" : True },
724+ IamHelper .IAMAuthenticationType .IAM_KEYS ,
725+ IamHelper .GetClusterCredentialsAPIType .IAM_V2 ,
726+ ),
727+ (
728+ {"is_serverless" : True },
729+ IamHelper .IAMAuthenticationType .IAM_KEYS ,
730+ IamHelper .GetClusterCredentialsAPIType .SERVERLESS_V1 ,
731+ ),
732+ (
733+ {"is_serverless" : True , "group_federation" : True },
734+ IamHelper .IAMAuthenticationType .IAM_KEYS_WITH_SESSION ,
735+ IamHelper .GetClusterCredentialsAPIType .IAM_V2 ,
736+ ),
737+ (
738+ {"group_federation" : True },
739+ IamHelper .IAMAuthenticationType .IAM_KEYS_WITH_SESSION ,
740+ IamHelper .GetClusterCredentialsAPIType .IAM_V2 ,
741+ ),
742+ (
743+ {"is_serverless" : True },
744+ IamHelper .IAMAuthenticationType .IAM_KEYS_WITH_SESSION ,
745+ IamHelper .GetClusterCredentialsAPIType .SERVERLESS_V1 ,
746+ ),
747+ (
748+ {"is_serverless" : True , "group_federation" : True },
749+ IamHelper .IAMAuthenticationType .PROFILE ,
750+ IamHelper .GetClusterCredentialsAPIType .IAM_V2 ,
751+ ),
680752 (
681753 {"group_federation" : True , "credentials_provider" : "BrowserSamlCredentialsProvider" },
754+ IamHelper .IAMAuthenticationType .PLUGIN ,
682755 "Authentication with plugin is not supported for group federation" ,
683756 ),
684757 (
685758 {"is_serverless" : True , "group_federation" : True , "credentials_provider" : "BrowserSamlCredentialsProvider" },
759+ IamHelper .IAMAuthenticationType .PLUGIN ,
686760 "Authentication with plugin is not supported for group federation" ,
687761 ),
688762 ),
689763)
690- def test_get_cluster_credentials_api_type_will_use_correct_api (conn_params , exp_result ):
764+ def test_get_cluster_credentials_api_type_will_use_correct_api (conn_params , provider , exp_result ):
691765 info = RedshiftProperty ()
692766 for param in conn_params .items ():
693767 info .put (param [0 ], param [1 ])
694768
695769 if isinstance (exp_result , IamHelper .GetClusterCredentialsAPIType ):
696- assert IamHelper .get_cluster_credentials_api_type (info ) == exp_result
770+ assert IamHelper .get_cluster_credentials_api_type (info , provider ) == exp_result
697771 else :
698772 with pytest .raises (InterfaceError , match = exp_result ):
699- IamHelper .get_cluster_credentials_api_type (info )
773+ IamHelper .get_cluster_credentials_api_type (info , provider )
700774
701775
702776@pytest .mark .parametrize (
0 commit comments