Skip to content

Commit

Permalink
enforce no trailing slashes in config urls
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaskratzel committed Jan 23, 2025
1 parent d372b3d commit e99adda
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/corbado_python_sdk/utils/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def url_validator(url: str) -> str:
if parts.username:
raise ValueError("Assert failed: username needs to be empty")

if parts.path:
raise ValueError("Assert failed: path needs to be empty")

if parts.password:
raise ValueError("Assert failed: password needs to be empty")

Expand Down
9 changes: 5 additions & 4 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_set_frontend_api(self):
project_id="pro-123",
api_secret="corbado1_123",
frontend_api=frontend_api,
backend_api="https://backendapi.cloud.corbado.io/",
backend_api="https://backendapi.cloud.corbado.io",
)
error = False
except ValueError:
Expand All @@ -24,7 +24,7 @@ def test_set_backend_api(self):
for backend_api, valid in self.provide_urls():
try:
config = Config(
project_id="pro-123", api_secret="corbado1_123", backend_api=backend_api, frontend_api="https://test.com/"
project_id="pro-123", api_secret="corbado1_123", backend_api=backend_api, frontend_api="https://test.com"
)
config.backend_api = backend_api
error = False
Expand All @@ -33,8 +33,8 @@ def test_set_backend_api(self):
self.assertEqual(valid, second=not error)

def test_get_backend_api(self):
test_url = "https://backendapi.cloud.corbado.io/"
config = Config(project_id="pro-123", api_secret="corbado1_123", frontend_api="https://test.com/", backend_api=test_url)
test_url = "https://backendapi.cloud.corbado.io"
config = Config(project_id="pro-123", api_secret="corbado1_123", frontend_api="https://test.com", backend_api=test_url)
self.assertTrue(config.backend_api.endswith("/v2"))

def provide_urls(self):
Expand All @@ -44,6 +44,7 @@ def provide_urls(self):
("http://auth.acme.com", False), # Only HTTPS
("https://[email protected]", False), # No user
("https://user:[email protected]", False), # No user no password
("https://auth.acme.com/", False), # No path
("https://auth.acme.com?xxx", False), # No query string
("https://auth.acme.com#xxx", False), # No fragment
("https://auth.acme.com", True),
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_session_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def test_set_cname_expect_issuer_changed(self):
api_secret="corbado1_XXX",
project_id="pro-55",
backend_api="https://backendapi.cloud.corbado.io/",
frontend_api="https://test.com/",
frontend_api="https://test.com",
cname=test_cname,
)

Expand Down

0 comments on commit e99adda

Please sign in to comment.