Skip to content

Commit

Permalink
test: add unittest for the CORS regex.
Browse files Browse the repository at this point in the history
  • Loading branch information
frederik-encord committed Dec 20, 2024
1 parent 9f3177e commit a820ab4
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/test_cors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import re

import pytest

from encord_agents.core.constants import ENCORD_DOMAIN_REGEX


@pytest.fixture
def legal_origins() -> list[str]:
return [
# Example development previews
"https://cord-ai-development--eb393d03-pccc0hqn.web.app",
"https://cord-ai-development--40816cb1-dij7k5yt.web.app",
"https://cord-ai-development--a3353fa9-0wf42o8h.web.app",
# Main deployment,
"https://app.encord.com",
"https://dev.encord.com",
"https://staging.encord.com",
# US Deployments,
"https://staging.us.encord.com",
"https://dev.us.encord.com",
"https://app.us.encord.com",
]


@pytest.fixture
def illegal_origins() -> list[str]:
return [
"https://google.com",
"https://test.encord.com",
"https://us.app.encord.com",
"https://app.encord.com.something-else.com",
"https://dev.encord.com.something-else.com",
"https://staging.encord.com.something-else.com",
]


@pytest.fixture
def compiled_regex() -> re.Pattern[str]:
return re.compile(ENCORD_DOMAIN_REGEX)


def test_legal_domains_against_CORS_regex(legal_origins: list[str], compiled_regex: re.Pattern[str]) -> None:
for origin in legal_origins:
assert compiled_regex.fullmatch(origin), f"Origin should have been allowed: `{origin}`"


def test_illegal_domains_against_CORS_regex(illegal_origins: list[str], compiled_regex: re.Pattern[str]) -> None:
for origin in illegal_origins:
assert not compiled_regex.fullmatch(origin), f"Origin should _not_ have been allowed: `{origin}`"

0 comments on commit a820ab4

Please sign in to comment.