Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
Added CORS headers
Browse files Browse the repository at this point in the history
  • Loading branch information
irgalamarr committed Dec 17, 2023
1 parent eb6daf3 commit d9b1905
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ coverage==6.3.2

# Utilities
httpie==3.2.1

# Security
Flask-Talisman
flask-talisman
Flask-Cors
2 changes: 2 additions & 0 deletions service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
from flask import Flask
from flask_talisman import Talisman
from flask_cors import CORS
from service import config
from service.common import log_handlers

Expand All @@ -15,6 +16,7 @@
app.config.from_object(config)

talisman = Talisman(app)
CORS(app)

# Import the routes After the Flask app is created
# pylint: disable=wrong-import-position, cyclic-import, wrong-import-order
Expand Down
7 changes: 7 additions & 0 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,10 @@ def test_security_headers(self):
}
for key, value in headers.items():
self.assertEqual(response.headers.get(key), value)

def test_cors_security(self):
"""It should return a CORS header"""
response = self.client.get('/', environ_overrides=HTTPS_ENVIRON)
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Check for the CORS header
self.assertEqual(response.headers.get('Access-Control-Allow-Origin'), '*')

0 comments on commit d9b1905

Please sign in to comment.