-
Notifications
You must be signed in to change notification settings - Fork 9
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 (#460)
- Loading branch information
Showing
10 changed files
with
74 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "pybotx" | ||
version = "0.64.0" | ||
version = "0.65.0" | ||
description = "A python library for interacting with eXpress BotX API" | ||
authors = [ | ||
"Sidnev Nikolay <[email protected]>", | ||
|
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