Beispiel #1
0
    def test_main_sign_up_with_email_check_exception(self):
        with patch('login_line_authorize_request.UserUtil') as user_mock:
            event = {
                'body': {
                    'code': 'testcode',
                }
            }

            event['body'] = json.dumps(event['body'])
            user_mock.exists_user.return_value = False
            user_mock.create_external_provider_user.side_effect = ClientError(
                {'Error': {
                    'Code': 'UsernameExistsException'
                }}, 'operation_name')
            user_mock.force_non_verified_phone.return_value = None
            user_mock.add_user_profile.return_value = None
            user_mock.add_external_provider_user_info.return_value = None
            user_mock.has_user_id.return_value = False

            response = LoginLineAuthorizeRequest(event=event,
                                                 context="",
                                                 dynamodb=dynamodb).main()
            self.assertEqual(response['statusCode'], 400)
            self.assertEqual(json.loads(response['body']),
                             {'message': 'EmailExistsException'})
Beispiel #2
0
    def test_main_login_with_exception(self):
        with patch('login_line_authorize_request.UserUtil') as user_mock, \
             patch('login_line_authorize_request.CryptoUtil') as crypto_mock:
            event = {
                'body': {
                    'code': 'testcode',
                }
            }

            event['body'] = json.dumps(event['body'])

            user_mock.exists_user.return_value = True
            crypto_mock.decrypt_password.return_value = 'password'
            user_mock.external_provider_login.side_effect = ClientError(
                {'Error': {
                    'Code': 'xxxxxx'
                }}, 'operation_name')
            user_mock.has_user_id.return_value = False

            response = LoginLineAuthorizeRequest(event=event,
                                                 context="",
                                                 dynamodb=dynamodb).main()
            self.assertEqual(response['statusCode'], 500)
            self.assertEqual(json.loads(response['body']),
                             {'message': 'Internal server error'})
Beispiel #3
0
    def test_main_login_ok_has_user_id(self):
        with patch('login_line_authorize_request.UserUtil') as user_mock,\
             patch('login_line_authorize_request.CryptoUtil') as crypto_mock:
            event = {
                'body': {
                    'code': 'testcode',
                }
            }

            event['body'] = json.dumps(event['body'])

            user_mock.exists_user.return_value = True
            crypto_mock.decrypt_password.return_value = 'password'
            user_mock.external_provider_login.return_value = {
                'AuthenticationResult': {
                    'AccessToken': 'aaaaa',
                    'IdToken': 'bbbbb',
                    'RefreshToken': 'ccccc'
                }
            }
            user_mock.has_user_id.return_value = True

            response = LoginLineAuthorizeRequest(event=event,
                                                 context="",
                                                 dynamodb=dynamodb).main()
            self.assertEqual(response['statusCode'], 200)
            self.assertEqual(
                json.loads(response['body']), {
                    'access_token': 'aaaaa',
                    'id_token': 'bbbbb',
                    'refresh_token': 'ccccc',
                    'last_auth_user': '******',
                    'has_user_id': True,
                    'status': 'login'
                })
Beispiel #4
0
    def test_line_400_api_error(self):
        event = {
            'body': {
                'code': 'testcode',
            }
        }

        event['body'] = json.dumps(event['body'])

        response = LoginLineAuthorizeRequest(event=event,
                                             context="",
                                             dynamodb=dynamodb).main()
        self.assertEqual(response['statusCode'], 400)
Beispiel #5
0
    def test_main_login_with_non_register_exception(self):
        with patch('login_line_authorize_request.UserUtil') as user_mock:
            event = {
                'body': {
                    'code': 'testcode',
                }
            }

            event['body'] = json.dumps(event['body'])

            user_mock.exists_user.return_value = False

            response = LoginLineAuthorizeRequest(event=event,
                                                 context="",
                                                 dynamodb=dynamodb).main()
            self.assertEqual(response['statusCode'], 400)
            self.assertEqual(json.loads(response['body']),
                             {'message': 'NotRegistered'})
    def test_main_sign_up_ok(self):
        with patch('login_line_authorize_request.UserUtil') as user_mock, \
             patch('login_line_authorize_request.CryptoUtil') as crypto_mock:
            event = {
                'body': {
                    'code': 'testcode',
                }
            }

            event['body'] = json.dumps(event['body'])

            user_mock.exists_user.return_value = False
            user_mock.force_non_verified_phone.return_value = None
            user_mock.wallet_initialization.return_value = None
            crypto_mock.encrypt_password.return_value = '&yjgFwFeOpd0{0=&y566'
            user_mock.add_external_provider_user_info.return_value = None
            user_mock.create_external_provider_user.return_value = {
                'AuthenticationResult': {
                    'AccessToken': 'aaaaa',
                    'IdToken': 'bbbbb',
                    'RefreshToken': 'ccccc'
                }
            }

            response = LoginLineAuthorizeRequest(event=event,
                                                 context="",
                                                 dynamodb=dynamodb).main()
            self.assertEqual(response['statusCode'], 200)
            self.assertEqual(
                json.loads(response['body']), {
                    'access_token': 'aaaaa',
                    'id_token': 'bbbbb',
                    'refresh_token': 'ccccc',
                    'last_auth_user': '******',
                    'has_user_id': False,
                    'status': 'sign_up'
                })
def lambda_handler(event, context):
    login_line_authorize_request = LoginLineAuthorizeRequest(event=event, context=context, dynamodb=dynamodb, cognito=cognito)
    return login_line_authorize_request.main()