def test_validation_required_params(self):
        required_params = ['name', 'redirect_urls']

        for param in required_params:
            params = {
                'pathParameters': {
                    'client_id': '123456789'
                },
                'body': {
                    'name': 'あ' * 80,
                    'description': 'A' * 180,
                    'redirect_urls': ['http://example.com/1']
                },
                'requestContext': {
                    'authorizer': {
                        'claims': {
                            'cognito:username': '******',
                            'phone_number_verified': 'true',
                            'email_verified': 'true'
                        }
                    }
                }
            }

            del params['body'][param]
            params['body'] = json.dumps(params['body'])

            response = MeApplicationUpdate(params, {}).main()
            self.assertEqual(response['statusCode'], 400)
    def test_validation_redirect_urls_invalid_type(self):
        base_url = 'http://example.com/'
        invalid_types = [
            'hogefugapiyo',  # URLの形式がおかしいパターン
            base_url + 'A' * (201 - len(base_url))  # URLが200文字以上になるパターン
        ]

        for invalid_type in invalid_types:
            params = {
                'pathParameters': {
                    'client_id': '123456789'
                },
                'body': {
                    'name': 'あ' * 80,
                    'description': 'A' * 180,
                    'redirect_urls': [invalid_type]
                },
                'requestContext': {
                    'authorizer': {
                        'claims': {
                            'cognito:username': '******',
                            'phone_number_verified': 'true',
                            'email_verified': 'true'
                        }
                    }
                }
            }

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

            response = MeApplicationUpdate(params, {}).main()
            self.assertEqual(response['statusCode'], 400)
    def test_validation_client_id_invalid_type(self):
        params = {
            'pathParameters': {
                'client_id': 'AAA'
            },
            'body': {
                'name':
                'あ' * 80,
                'description':
                'A' * 180,
                'redirect_urls': [
                    'http://example.com/1', 'http://example.com/2',
                    'http://example.com/3', 'http://example.com/4',
                    'http://example.com/5'
                ]
            },
            'requestContext': {
                'authorizer': {
                    'claims': {
                        'cognito:username': '******',
                        'phone_number_verified': 'true',
                        'email_verified': 'true'
                    }
                }
            }
        }

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

        response = MeApplicationUpdate(params, {}).main()
        self.assertEqual(response['statusCode'], 400)
Exemple #4
0
    def test_main_with_exception(self):
        params = {
            'pathParameters': {
                'client_id': '123456789'
            },
            'body': {
                'name': 'あ' * 80,
                'description': 'A' * 180,
                'redirect_urls': ['http://example.com/1', 'http://example.com/2',
                                  'http://example.com/3', 'http://example.com/4', 'http://example.com/5']
            },
            'requestContext': {
                'authorizer': {
                    'claims': {
                        'cognito:username': '******',
                        'phone_number_verified': 'true',
                        'email_verified': 'true'
                    }
                }
            }
        }

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

        responses.add(responses.POST,
                      settings.AUTHLETE_CLIENT_ENDPOINT + '/update/' + params['pathParameters']['client_id'],
                      json={"developer": "user01"}, status=200)
        # AuthleteUtilで呼ばれるAPI callをmockする
        responses.add(responses.GET,
                      settings.AUTHLETE_CLIENT_ENDPOINT + '/get/' + params['pathParameters']['client_id'],
                      json={'developer': "user01"}, status=200)

        response = MeApplicationUpdate(params, {}).main()
        self.assertEqual(response['statusCode'], 500)
    def test_main_ng_authlete_api_response_400(self):
        params = {
            'pathParameters': {
                'client_id': '123456789'
            },
            'body': {
                'name': 'あ' * 80,
                'description': 'A' * 180,
                'redirect_urls': ['http://example.com/1']
            },
            'requestContext': {
                'authorizer': {
                    'claims': {
                        'cognito:username': '******',
                        'phone_number_verified': 'true',
                        'email_verified': 'true'
                    }
                }
            }
        }

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

        # 400 が返却されるように mock 化
        responses.add(responses.POST,
                      settings.AUTHLETE_CLIENT_ENDPOINT + '/update/' +
                      params['pathParameters']['client_id'],
                      json={
                          "resultCode": "A031233",
                          "resultMessage": "error_message"
                      },
                      status=400)
        # AuthleteUtilで呼ばれるAPI callをmockする
        responses.add(responses.GET,
                      settings.AUTHLETE_CLIENT_ENDPOINT + '/get/' +
                      params['pathParameters']['client_id'],
                      json={'developer': "user01"},
                      status=200)
        # アプリケーション情報取得で呼ばれるAPI callをmockする
        responses.add(responses.GET,
                      settings.AUTHLETE_CLIENT_ENDPOINT + '/get/' +
                      params['pathParameters']['client_id'],
                      json={'developer': "user01"},
                      status=200)

        response = MeApplicationUpdate(params, {}).main()

        self.assertEqual(response['statusCode'], 400)
        self.assertEqual(json.loads(response['body']), {
            "message":
            "Invalid parameter: Please check the input parameters"
        })
Exemple #6
0
def lambda_handler(event, context):
    me_applications_update = MeApplicationUpdate(event=event, context=context)
    return me_applications_update.main()