-
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: async set_auth for realtime in auth event listener (#930)
- Loading branch information
1 parent
948eb60
commit 5e34512
Showing
7 changed files
with
64 additions
and
9 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,38 @@ | ||
import os | ||
from unittest.mock import AsyncMock, MagicMock | ||
|
||
from supabase import create_async_client | ||
|
||
|
||
async def test_updates_the_authorization_header_on_auth_events() -> None: | ||
url = os.environ.get("SUPABASE_TEST_URL") | ||
key = os.environ.get("SUPABASE_TEST_KEY") | ||
|
||
client = await create_async_client(url, key) | ||
|
||
assert client.options.headers.get("apiKey") == key | ||
assert client.options.headers.get("Authorization") == f"Bearer {key}" | ||
|
||
mock_session = MagicMock(access_token="secretuserjwt") | ||
realtime_mock = AsyncMock() | ||
client.realtime = realtime_mock | ||
|
||
client._listen_to_auth_events("SIGNED_IN", mock_session) | ||
|
||
updated_authorization = f"Bearer {mock_session.access_token}" | ||
|
||
assert client.options.headers.get("apiKey") == key | ||
assert client.options.headers.get("Authorization") == updated_authorization | ||
|
||
assert client.postgrest.session.headers.get("apiKey") == key | ||
assert ( | ||
client.postgrest.session.headers.get("Authorization") == updated_authorization | ||
) | ||
|
||
assert client.auth._headers.get("apiKey") == key | ||
assert client.auth._headers.get("Authorization") == updated_authorization | ||
|
||
assert client.storage.session.headers.get("apiKey") == key | ||
assert client.storage.session.headers.get("Authorization") == updated_authorization | ||
|
||
realtime_mock.set_auth.assert_called_once_with(mock_session.access_token) |
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