Esempio n. 1
0
    def test_with_security_headers(self):
        original_response = {
            "statusCode": 200,
            "body": json.dumps({'foo': 'bar'})
        }

        new_headers_expectation = Response.SECURITY_HEADERS

        response = Response(original_response)

        assert type(Response(original_response)) == Response
        assert response.with_security_headers() == {
            'body': '{"foo": "bar"}',
            'headers': new_headers_expectation,
            'statusCode': 200
        }
Esempio n. 2
0
    def test_with_security_headers_preexisting_sec(self):
        original_headers = {'Content-Security-Policy': 'nope'}

        original_response = {
            "statusCode": 200,
            "body": json.dumps({'foo': 'bar'}),
            # We're adding to make sure it's not overwritten
            'headers': original_headers
        }

        new_headers_expectation = {}
        new_headers_expectation.update(Response.SECURITY_HEADERS)
        new_headers_expectation['Content-Security-Policy'] = 'nope'

        response = Response(original_response)

        assert type(Response(original_response)) == Response
        assert response.with_security_headers() == {
            'body': '{"foo": "bar"}',
            'headers': new_headers_expectation,
            'statusCode': 200
        }