-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unittest for the CORS regex.
- Loading branch information
1 parent
9f3177e
commit a820ab4
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`" |