Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/auth/transport/_aiohttp_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def data(self):

async def raw_content(self):
if self._raw_content is None:
self._raw_content = await self._response.read()
self._raw_content = await self._response.content.read()
return self._raw_content

async def content(self):
Expand Down
7 changes: 5 additions & 2 deletions google/oauth2/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ def __init__(
self.expiry = expiry
self._refresh_token = refresh_token
self._id_token = id_token
self._scopes = scopes
if scopes is not None and isinstance(scopes, set):
self._scopes = list(scopes)
else:
self._scopes = scopes
self._default_scopes = default_scopes
self._granted_scopes = granted_scopes
self._token_uri = token_uri
Expand Down Expand Up @@ -207,7 +210,7 @@ def refresh_token(self):

@property
def scopes(self):
"""Optional[str]: The OAuth 2.0 permission scopes."""
"""Optional[Sequence[str]]: The OAuth 2.0 permission scopes."""
return self._scopes

@property
Expand Down
25 changes: 25 additions & 0 deletions tests/oauth2/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,31 @@ def make_credentials(cls):
enable_reauth_refresh=True,
)

def test_init_with_set_scopes(self):
# Regression test for https://github.com/googleapis/google-auth-library-python/issues/1145
scopes_set = {"a", "b"}
creds = credentials.Credentials(token="token", scopes=scopes_set)

# Verify scopes are converted to a list
assert isinstance(creds.scopes, list)
assert set(creds.scopes) == scopes_set

# Verify internal storage is a list (ensure consistent mutability)
assert isinstance(creds._scopes, list)

# Verify consistency (property returns the same object)
assert creds.scopes is creds.scopes

# Verify modifications persist
creds.scopes.append("c")
assert "c" in creds.scopes
assert len(creds.scopes) == 3

# Verify to_json works
json_output = creds.to_json()
data = json.loads(json_output)
assert set(data["scopes"]) == {"a", "b", "c"}

def test_default_state(self):
credentials = self.make_credentials()
assert not credentials.valid
Expand Down
2 changes: 1 addition & 1 deletion tests/test__oauth2client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test__convert_oauth2_credentials():
assert new_credentials._client_id == old_credentials.client_id
assert new_credentials._client_secret == old_credentials.client_secret
assert new_credentials._token_uri == old_credentials.token_uri
assert new_credentials.scopes == old_credentials.scopes
assert set(new_credentials.scopes) == set(old_credentials.scopes)


def test__convert_service_account_credentials():
Expand Down
4 changes: 2 additions & 2 deletions tests_async/transport/test_aiohttp_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test__is_compressed_not(self):
@pytest.mark.asyncio
async def test_raw_content(self):
mock_response = mock.AsyncMock()
mock_response.read.return_value = mock.sentinel.read
mock_response.content.read.return_value = mock.sentinel.read
combined_response = aiohttp_requests._CombinedResponse(response=mock_response)
raw_content = await combined_response.raw_content()
assert raw_content == mock.sentinel.read
Expand All @@ -53,7 +53,7 @@ async def test_raw_content(self):
@pytest.mark.asyncio
async def test_content(self):
mock_response = mock.AsyncMock()
mock_response.read.return_value = mock.sentinel.read
mock_response.content.read.return_value = mock.sentinel.read
combined_response = aiohttp_requests._CombinedResponse(response=mock_response)
content = await combined_response.content()
assert content == mock.sentinel.read
Expand Down