@@ -536,7 +536,7 @@ def test_create_user_pool_default_id_strategy():
536536@mock .patch .dict (os .environ , {"MOTO_COGNITO_IDP_USER_POOL_ID_STRATEGY" : "HASH" })
537537def test_create_user_pool_hash_id_strategy_with_equal_pool_name ():
538538 if settings .TEST_SERVER_MODE :
539- raise SkipTest ("Cannot set environemnt variables in ServerMode" )
539+ raise SkipTest ("Cannot set environment variables in ServerMode" )
540540
541541 conn = boto3 .client ("cognito-idp" , "us-west-2" )
542542
@@ -550,7 +550,7 @@ def test_create_user_pool_hash_id_strategy_with_equal_pool_name():
550550@mock .patch .dict (os .environ , {"MOTO_COGNITO_IDP_USER_POOL_ID_STRATEGY" : "HASH" })
551551def test_create_user_pool_hash_id_strategy_with_different_pool_name ():
552552 if settings .TEST_SERVER_MODE :
553- raise SkipTest ("Cannot set environemnt variables in ServerMode" )
553+ raise SkipTest ("Cannot set environment variables in ServerMode" )
554554
555555 conn = boto3 .client ("cognito-idp" , "us-west-2" )
556556
@@ -564,7 +564,7 @@ def test_create_user_pool_hash_id_strategy_with_different_pool_name():
564564@mock .patch .dict (os .environ , {"MOTO_COGNITO_IDP_USER_POOL_ID_STRATEGY" : "HASH" })
565565def test_create_user_pool_hash_id_strategy_with_different_attributes ():
566566 if settings .TEST_SERVER_MODE :
567- raise SkipTest ("Cannot set environemnt variables in ServerMode" )
567+ raise SkipTest ("Cannot set environment variables in ServerMode" )
568568
569569 conn = boto3 .client ("cognito-idp" , "us-west-2" )
570570
@@ -1002,7 +1002,7 @@ def test_create_user_pool_client_default_id_strategy():
10021002@mock .patch .dict (os .environ , {"MOTO_COGNITO_IDP_USER_POOL_CLIENT_ID_STRATEGY" : "HASH" })
10031003def test_create_user_pool_client_hash_id_strategy_with_equal_args ():
10041004 if settings .TEST_SERVER_MODE :
1005- raise SkipTest ("Cannot set environemnt variables in ServerMode" )
1005+ raise SkipTest ("Cannot set environment variables in ServerMode" )
10061006
10071007 conn = boto3 .client ("cognito-idp" , "us-west-2" )
10081008
@@ -1024,7 +1024,7 @@ def test_create_user_pool_client_hash_id_strategy_with_equal_args():
10241024@mock .patch .dict (os .environ , {"MOTO_COGNITO_IDP_USER_POOL_CLIENT_ID_STRATEGY" : "HASH" })
10251025def test_create_user_pool_client_hash_id_strategy_with_different_args ():
10261026 if settings .TEST_SERVER_MODE :
1027- raise SkipTest ("Cannot set environemnt variables in ServerMode" )
1027+ raise SkipTest ("Cannot set environment variables in ServerMode" )
10281028
10291029 conn = boto3 .client ("cognito-idp" , "us-west-2" )
10301030
@@ -3210,6 +3210,7 @@ def user_authentication_flow(
32103210 refresh_token = result ["AuthenticationResult" ]["RefreshToken" ]
32113211
32123212 # add mfa token
3213+ secret_code = None
32133214 if with_mfa :
32143215 resp = conn .associate_software_token (
32153216 AccessToken = result ["AuthenticationResult" ]["AccessToken" ]
@@ -3284,6 +3285,7 @@ def user_authentication_flow(
32843285 "client_id" : client_id ,
32853286 "client_secret" : client_secret ,
32863287 "secret_hash" : secret_hash ,
3288+ "secret_code" : secret_code ,
32873289 "id_token" : result ["AuthenticationResult" ]["IdToken" ],
32883290 "access_token" : result ["AuthenticationResult" ]["AccessToken" ],
32893291 "refresh_token" : refresh_token ,
@@ -4842,6 +4844,7 @@ def test_initiate_auth_USER_PASSWORD_AUTH_when_software_token_mfa_enabled():
48424844 password = result ["password" ]
48434845 client_id = result ["client_id" ]
48444846 secret_hash = result ["secret_hash" ]
4847+ secret_code = result ["secret_code" ]
48454848
48464849 result = conn .admin_get_user (UserPoolId = user_pool_id , Username = username )
48474850 assert result ["PreferredMfaSetting" ] == "SOFTWARE_TOKEN_MFA"
@@ -4856,12 +4859,15 @@ def test_initiate_auth_USER_PASSWORD_AUTH_when_software_token_mfa_enabled():
48564859 assert result ["ChallengeParameters" ] == {}
48574860 assert result ["Session" ] is not None
48584861
4862+ totp = pyotp .TOTP (secret_code )
4863+ user_code = totp .now ()
4864+
48594865 result = conn .respond_to_auth_challenge (
48604866 ClientId = client_id ,
48614867 ChallengeName = "SOFTWARE_TOKEN_MFA" ,
48624868 Session = result ["Session" ],
48634869 ChallengeResponses = {
4864- "SOFTWARE_TOKEN_MFA_CODE" : "123456" ,
4870+ "SOFTWARE_TOKEN_MFA_CODE" : user_code ,
48654871 "USERNAME" : username ,
48664872 "SECRET_HASH" : secret_hash ,
48674873 },
@@ -5372,7 +5378,8 @@ def test_admin_setting_mfa_totp_and_sms():
53725378
53735379
53745380@mock_aws
5375- def test_admin_initiate_auth_when_token_totp_masked ():
5381+ @mock .patch .dict (os .environ , {"MOTO_COGNITO_IDP_USER_POOL_ENABLE_TOTP" : "true" })
5382+ def test_admin_initiate_auth_when_token_totp_enabled ():
53765383 conn = boto3 .client ("cognito-idp" , "us-west-2" )
53775384
53785385 result = authentication_flow (conn , "ADMIN_NO_SRP_AUTH" )
@@ -5419,7 +5426,7 @@ def test_admin_initiate_auth_when_token_totp_masked():
54195426 ChallengeName = "SOFTWARE_TOKEN_MFA" ,
54205427 Session = result ["Session" ],
54215428 ChallengeResponses = {
5422- "SOFTWARE_TOKEN_MFA_CODE" : "123456" ,
5429+ "SOFTWARE_TOKEN_MFA_CODE" : totp . now () ,
54235430 "USERNAME" : username ,
54245431 },
54255432 )
@@ -5431,8 +5438,10 @@ def test_admin_initiate_auth_when_token_totp_masked():
54315438
54325439
54335440@mock_aws
5434- @mock .patch .dict (os .environ , {"MOTO_COGNITO_IDP_USER_POOL_ENABLE_TOTP" : "true" })
5435- def test_admin_initiate_auth_when_token_totp_enabled ():
5441+ def test_admin_initiate_auth_when_token_totp_disabled ():
5442+ if settings .TEST_SERVER_MODE :
5443+ raise SkipTest ("TOTP is enabled in server mode" )
5444+
54365445 conn = boto3 .client ("cognito-idp" , "us-west-2" )
54375446
54385447 result = authentication_flow (conn , "ADMIN_NO_SRP_AUTH" )
@@ -5479,7 +5488,7 @@ def test_admin_initiate_auth_when_token_totp_enabled():
54795488 ChallengeName = "SOFTWARE_TOKEN_MFA" ,
54805489 Session = result ["Session" ],
54815490 ChallengeResponses = {
5482- "SOFTWARE_TOKEN_MFA_CODE" : totp . now () ,
5491+ "SOFTWARE_TOKEN_MFA_CODE" : "123456" ,
54835492 "USERNAME" : username ,
54845493 },
54855494 )
0 commit comments