@@ -181,3 +181,94 @@ def test_admin_create_user_without_authentication():
181181 assert "AuthenticationResult" in response
182182 assert "IdToken" in response ["AuthenticationResult" ]
183183 assert "AccessToken" in response ["AuthenticationResult" ]
184+
185+
186+ def test_associate_software_token ():
187+ backend = server .create_backend_app ("cognito-idp" )
188+ test_client = backend .test_client ()
189+
190+ # Create User Pool
191+ res = test_client .post (
192+ "/" ,
193+ data = '{"PoolName": "test-pool"}' ,
194+ headers = {
195+ "X-Amz-Target" : "AWSCognitoIdentityProviderService.CreateUserPool" ,
196+ "Authorization" : "AWS4-HMAC-SHA256 Credential=abcd/20010101/us-east-2/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=..." ,
197+ },
198+ )
199+ user_pool_id = json .loads (res .data )["UserPool" ]["Id" ]
200+
201+ # Create User Pool Client
202+ data = {
203+ "UserPoolId" : user_pool_id ,
204+ "ClientName" : "some-client" ,
205+ "GenerateSecret" : False ,
206+ "ExplicitAuthFlows" : ["ALLOW_USER_PASSWORD_AUTH" ],
207+ }
208+ res = test_client .post (
209+ "/" ,
210+ data = json .dumps (data ),
211+ headers = {
212+ "X-Amz-Target" : "AWSCognitoIdentityProviderService.CreateUserPoolClient" ,
213+ "Authorization" : "AWS4-HMAC-SHA256 Credential=abcd/20010101/us-east-2/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=..." ,
214+ },
215+ )
216+ client_id = json .loads (res .data )["UserPoolClient" ]["ClientId" ]
217+
218+ # Sign Up User
219+ data = {
220+ "ClientId" : client_id ,
221+ "Username" : "user_2_mfa" ,
222+ "Password" : "12312sdfasASDFDSF$" ,
223+ }
224+ res = test_client .post (
225+ "/" ,
226+ data = json .dumps (data ),
227+ headers = {"X-Amz-Target" : "AWSCognitoIdentityProviderService.SignUp" },
228+ )
229+ assert res .status_code == 200
230+ assert json .loads (res .data )["UserConfirmed" ] is False
231+
232+ # Confirm Sign Up User
233+ data = {"ClientId" : client_id , "Username" : "user_2_mfa" , "ConfirmationCode" : "sth" }
234+ res = test_client .post (
235+ "/" ,
236+ data = json .dumps (data ),
237+ headers = {"X-Amz-Target" : "AWSCognitoIdentityProviderService.ConfirmSignUp" },
238+ )
239+
240+ # Initiate Auth
241+ data = {
242+ "AuthFlow" : "USER_PASSWORD_AUTH" ,
243+ "AuthParameters" : {
244+ "USERNAME" : "user_2_mfa" ,
245+ "PASSWORD" : "12312sdfasASDFDSF$" ,
246+ "SECRET_HASH" : "kIWuIv6ElVe9ahZHJ+gqvZe6CgEkVE/BjQmJcMSgF3E=" ,
247+ },
248+ "ClientId" : client_id ,
249+ }
250+ res = test_client .post (
251+ "/" ,
252+ data = json .dumps (data ),
253+ headers = {"X-Amz-Target" : "AWSCognitoIdentityProviderService.InitiateAuth" },
254+ )
255+ auth_data = json .loads (res .data .decode ("utf-8" ))["AuthenticationResult" ]
256+
257+ # Get User
258+ data = {"AccessToken" : auth_data ["AccessToken" ]}
259+ res = test_client .post (
260+ "/" ,
261+ data = json .dumps (data ),
262+ headers = {"X-Amz-Target" : "AWSCognitoIdentityProviderService.GetUser" },
263+ )
264+
265+ # Associate Software Token
266+ data = {"AccessToken" : auth_data ["AccessToken" ]}
267+ res = test_client .post (
268+ "/" ,
269+ data = json .dumps (data ),
270+ headers = {
271+ "X-Amz-Target" : "AWSCognitoIdentityProviderService.AssociateSoftwareToken"
272+ },
273+ )
274+ assert json .loads (res .data .decode ("utf-8" )) == {"SecretCode" : "asdfasdfasdf" }
0 commit comments