コード例 #1
0
 def test_correct_phone_number(self):
     custommessage = CustomMessage(event={}, context="", dynamodb=dynamodb)
     result = validate({'phone_number': '+818012345678'},
                       custommessage.get_schema())
     self.assertEqual(result, None)
     result = validate({'phone_number': '+816012345678'},
                       custommessage.get_schema())
     self.assertEqual(result, None)
コード例 #2
0
 def test_main_ok_get_verification_code_for_phone_number_already_confirmed_with_exists_token(
         self):
     with patch('custom_message.boto3.client') as mock:
         cognito_mock = MagicMock()
         cognito_mock.user_list = MagicMock(return_value=[])
         mock.return_value = cognito_mock
         os.environ['DOMAIN'] = "alis.example.com"
         event = {
             'version': '1',
             'region': 'us-east-1',
             'userPoolId': 'us-east-1_xxxxxxxxx',
             'userName': '******',
             'callerContext': {
                 'awsSdkVersion': 'aws-sdk-js-2.6.4',
                 'clientId': 'abcdefghijklmnopqrstuvwxy'
             },
             'triggerSource': 'CustomMessage_VerifyUserAttribute',
             'request': {
                 'userAttributes': {
                     'sub': '12345678-877a-4925-85e1-137c022e8c33',
                     'email_verified': 'true',
                     'cognito:user_status': 'UNCONFIRMED',
                     'phone_number_verified': 'true',
                     'phone_number': '+819000001234',
                     'email': '*****@*****.**',
                     'custom:private_eth_address': '0xaaaa'
                 },
                 'codeParameter': '{####}',
                 'usernameParameter': None
             },
             'response': {
                 'smsMessage': None,
                 'emailMessage': None,
                 'emailSubject': None
             }
         }
         custom_message = CustomMessage(event=event,
                                        context="",
                                        dynamodb=dynamodb)
         response = custom_message.main()
         self.assertRegex(
             response['response']['smsMessage'],
             'ALISです。\n' + event['userName'] + 'さんの認証コードは {####} です。.*')
         self.assertRegex(response['response']['emailMessage'],
                          '.*ALISをご利用いただきありがとうございます。.*')
         self.assertEqual(response['response']['emailSubject'],
                          '【ALIS】登録のご案内:メールアドレスの確認')
コード例 #3
0
 def test_main_ng_get_verification_code_after_updated_phone_number_with_exists_token(
         self):
     with patch('custom_message.boto3.client') as mock:
         cognito_mock = MagicMock()
         cognito_mock.user_list = MagicMock(return_value=[])
         mock.return_value = cognito_mock
         os.environ['DOMAIN'] = "alis.example.com"
         event = {
             'version': '1',
             'region': 'us-east-1',
             'userPoolId': 'us-east-1_xxxxxxxxx',
             'userName': '******',
             'callerContext': {
                 'awsSdkVersion': 'aws-sdk-js-2.6.4',
                 'clientId': 'abcdefghijklmnopqrstuvwxy'
             },
             'triggerSource': 'CustomMessage_VerifyUserAttribute',
             'request': {
                 'userAttributes': {
                     'sub': '12345678-877a-4925-85e1-137c022e8c33',
                     'email_verified': 'true',
                     'cognito:user_status': 'UNCONFIRMED',
                     'phone_number_verified': 'false',
                     'phone_number': '+819000001234',
                     'email': '*****@*****.**',
                     'custom:private_eth_address': '0xaaaa'
                 },
                 'codeParameter': '{####}',
                 'usernameParameter': None
             },
             'response': {
                 'smsMessage': None,
                 'emailMessage': None,
                 'emailSubject': None
             }
         }
         custom_message = CustomMessage(event=event,
                                        context="",
                                        dynamodb=dynamodb)
         with self.assertRaises(Exception) as e:
             custom_message.main()
         self.assertEqual('Do not allow phone number updates',
                          str(e.exception))
コード例 #4
0
 def test_reset_password(self):
     event = {
         'version': '1',
         'region': 'us-east-1',
         'userPoolId': 'us-east-1_xxxxxxxxx',
         'userName': '******',
         'callerContext': {
             'awsSdkVersion': 'aws-sdk-js-2.6.4',
             'clientId': 'abcdefghijklmnopqrstuvwxy'
         },
         'triggerSource': 'CustomMessage_ForgotPassword',
         'request': {
             'userAttributes': {
                 'sub': '11111111-2222-3333-4444-555555555555',
                 'email_verified': 'true',
                 'cognito:user_status': 'CONFIRMED',
                 'cognito:email_alias': '*****@*****.**',
                 'phone_number_verified': 'true',
                 'cognito:phone_number_alias': '+818012345678',
                 'phone_number': '+818012345678',
                 'email': '*****@*****.**'
             },
             'codeParameter': '{####}',
             'usernameParameter': None
         },
         'response': {
             'smsMessage': None,
             'emailMessage': None,
             'emailSubject': None
         }
     }
     custommessage = CustomMessage(event=event,
                                   context="",
                                   dynamodb=dynamodb)
     response = custommessage.main()
     self.assertEqual(response['response']['emailSubject'],
                      '【ALIS】パスワードの変更:再設定コードの送付')
     self.assertEqual(response['response']['emailMessage'],
                      'resetuserさんのパスワード再設定コードは {####} です')
     self.assertEqual(response['response']['smsMessage'],
                      'resetuserさんのパスワード再設定コードは {####} です。')
コード例 #5
0
 def test_invalid_line_user_attempt_to_register_phone_number(self):
     os.environ['DOMAIN'] = "alis.example.com"
     event = {
         'version': '1',
         'region': 'us-east-1',
         'userPoolId': 'us-east-1_xxxxxxxxx',
         'userName': '******',
         'callerContext': {
             'awsSdkVersion': 'aws-sdk-js-2.179.0',
             'clientId': 'abcdefghijklmnopqrstuvwxy'
         },
         'triggerSource': 'CustomMessage_VerifyUserAttribute',
         'request': {
             'userAttributes': {
                 'sub': '12345678-2157-480a-8f33-e6945ccb856b',
                 'email_verified': 'true',
                 'cognito:user_status': 'CONFIRMED',
                 'cognito:email_alias': '*****@*****.**',
                 'phone_number_verified': 'false',
                 'phone_number': '+818011112222',
                 'email': '*****@*****.**'
             },
             'codeParameter': '{####}',
             'usernameParameter': None
         },
         'response': {
             'smsMessage': None,
             'emailMessage': None,
             'emailSubject': None
         }
     }
     event['request']['userAttributes']['phone_number'] = "+818011112222"
     custommessage = CustomMessage(event=event,
                                   context="",
                                   dynamodb=dynamodb)
     with self.assertRaises(Exception) as e:
         custommessage.main()
     self.assertEqual("external provider's user can not execute",
                      str(e.exception))
コード例 #6
0
 def test_reset_password_ng_with_external_provider_user(self):
     event = {
         'version': '1',
         'region': 'us-east-1',
         'userPoolId': 'us-east-1_xxxxxxxxx',
         'userName': '******',
         'callerContext': {
             'awsSdkVersion': 'aws-sdk-js-2.6.4',
             'clientId': 'abcdefghijklmnopqrstuvwxy'
         },
         'triggerSource': 'CustomMessage_ForgotPassword',
         'request': {
             'userAttributes': {
                 'sub': '11111111-2222-3333-4444-555555555555',
                 'email_verified': 'true',
                 'cognito:user_status': 'CONFIRMED',
                 'cognito:email_alias': '*****@*****.**',
                 'phone_number_verified': 'true',
                 'cognito:phone_number_alias': '+818012345678',
                 'phone_number': '+818012345678',
                 'email': '*****@*****.**'
             },
             'codeParameter': '{####}',
             'usernameParameter': None
         },
         'response': {
             'smsMessage': None,
             'emailMessage': None,
             'emailSubject': None
         }
     }
     custommessage = CustomMessage(event=event,
                                   context="",
                                   dynamodb=dynamodb)
     with self.assertRaises(Exception) as e:
         custommessage.main()
     self.assertEqual("external provider's user can not execute",
                      str(e.exception))
コード例 #7
0
 def test_email_verify(self):
     os.environ['DOMAIN'] = "alis.example.com"
     event = {
         'version': '1',
         'region': 'us-east-1',
         'userPoolId': 'us-east-1_xxxxxxxxx',
         'userName': '******',
         'callerContext': {
             'awsSdkVersion': 'aws-sdk-js-2.6.4',
             'clientId': 'abcdefghijklmnopqrstuvwxy'
         },
         'triggerSource': 'CustomMessage_SignUp',
         'request': {
             'userAttributes': {
                 'sub': '12345678-877a-4925-85e1-137c022e8c33',
                 'email_verified': 'false',
                 'cognito:user_status': 'UNCONFIRMED',
                 'phone_number_verified': 'false',
                 'phone_number': '',
                 'email': '*****@*****.**'
             },
             'codeParameter': '{####}',
             'usernameParameter': None
         },
         'response': {
             'smsMessage': None,
             'emailMessage': None,
             'emailSubject': None
         }
     }
     custommessage = CustomMessage(event=event,
                                   context="",
                                   dynamodb=dynamodb)
     response = custommessage.main()
     self.assertRegex(response['response']['emailMessage'],
                      '.*ALISをご利用いただきありがとうございます。.*')
     self.assertEqual(response['response']['emailSubject'],
                      '【ALIS】登録のご案内:メールアドレスの確認')
コード例 #8
0
def lambda_handler(event, context):
    custommessage = CustomMessage(event=event, context=context, dynamodb=dynamodb)
    return custommessage.main()
コード例 #9
0
 def test_invalid_phone_number(self):
     os.environ['DOMAIN'] = "alis.example.com"
     event = {
         'version': '1',
         'region': 'us-east-1',
         'userPoolId': 'us-east-1_xxxxxxxxx',
         'userName': '******',
         'callerContext': {
             'awsSdkVersion': 'aws-sdk-js-2.179.0',
             'clientId': 'abcdefghijklmnopqrstuvwxy'
         },
         'triggerSource': 'CustomMessage_VerifyUserAttribute',
         'request': {
             'userAttributes': {
                 'sub': '12345678-2157-480a-8f33-e6945ccb856b',
                 'email_verified': 'true',
                 'cognito:user_status': 'CONFIRMED',
                 'cognito:email_alias': '*****@*****.**',
                 'phone_number_verified': 'false',
                 'phone_number': '',
                 'email': '*****@*****.**'
             },
             'codeParameter': '{####}',
             'usernameParameter': None
         },
         'response': {
             'smsMessage': None,
             'emailMessage': None,
             'emailSubject': None
         }
     }
     # 桁が足りない
     event['request']['userAttributes']['phone_number'] = "+810801234567"
     custommessage = CustomMessage(event=event,
                                   context="",
                                   dynamodb=dynamodb)
     response = custommessage.main()
     self.assertEqual(response['statusCode'], 400)
     # 桁が多い
     event['request']['userAttributes']['phone_number'] = "+81080123456789"
     custommessage = CustomMessage(event=event,
                                   context="",
                                   dynamodb=dynamodb)
     response = custommessage.main()
     self.assertEqual(response['statusCode'], 400)
     # 日本の番号ではない
     event['request']['userAttributes']['phone_number'] = "+4408012345678"
     custommessage = CustomMessage(event=event,
                                   context="",
                                   dynamodb=dynamodb)
     response = custommessage.main()
     self.assertEqual(response['statusCode'], 400)
     # 090,080,070,060以外で始まる番号
     event['request']['userAttributes']['phone_number'] = "+8105012345678"
     custommessage = CustomMessage(event=event,
                                   context="",
                                   dynamodb=dynamodb)
     response = custommessage.main()
     self.assertEqual(response['statusCode'], 400)