-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: invalid issuer error during incoming request verification if the…
… bot host contains url parts other than the domain
- Loading branch information
Alexander Maximenyuk
committed
Mar 25, 2024
1 parent
e6d0795
commit 426acd0
Showing
10 changed files
with
101 additions
and
69 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
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
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
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
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 |
---|---|---|
@@ -1,13 +1,31 @@ | ||
from dataclasses import dataclass | ||
from functools import cached_property | ||
from urllib.parse import urlparse | ||
from uuid import UUID | ||
|
||
from pydantic import AnyHttpUrl, BaseModel | ||
|
||
|
||
@dataclass | ||
class BotAccount: | ||
id: UUID | ||
host: str | ||
|
||
|
||
@dataclass | ||
class BotAccountWithSecret(BotAccount): | ||
class BotAccountWithSecret(BaseModel): | ||
id: UUID | ||
cts_url: AnyHttpUrl | ||
secret_key: str | ||
|
||
class Config: | ||
allow_mutation = False | ||
keep_untouched = (cached_property,) | ||
|
||
@cached_property | ||
def host(self) -> str: | ||
hostname = urlparse(self.cts_url).hostname | ||
|
||
if hostname is None: | ||
raise ValueError("Could not parse host from cts_url.") | ||
|
||
return hostname |
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
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
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
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,20 @@ | ||
from uuid import UUID | ||
|
||
import pytest | ||
|
||
from pybotx import BotAccountWithSecret | ||
|
||
|
||
def test__bot_account__could_not_parse_host(bot_id: UUID, cts_url: str) -> None: | ||
# - Arrange - | ||
bot_account = BotAccountWithSecret( | ||
id=bot_id, | ||
cts_url=cts_url, | ||
secret_key="secret_key", | ||
) | ||
bot_account.Config.allow_mutation = True | ||
bot_account.cts_url = "cts_url" # type: ignore | ||
|
||
# - Assert - | ||
with pytest.raises(ValueError): | ||
bot_account.host |
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