Skip to content

Commit cbbf5de

Browse files
authored
fix: Reuse HMAC key as we have a limit of 5 (#3037)
* fix: Reuse HMAC key as we have a limit of 5
1 parent 3a76887 commit cbbf5de

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

storage/cloud-client/hmac_samples_test.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import os
2222

2323
from google.cloud import storage
24+
import google.api_core.exceptions
2425
import pytest
2526

2627
import storage_activate_hmac_key
@@ -36,11 +37,13 @@
3637
STORAGE_CLIENT = storage.Client(project=PROJECT_ID)
3738

3839

39-
@pytest.fixture
40+
@pytest.fixture(scope="module")
4041
def new_hmac_key():
4142
"""
4243
Fixture to create a new HMAC key, and to guarantee all keys are deleted at
43-
the end of each test.
44+
the end of the module.
45+
46+
NOTE: Due to the module scope, test order in this file is significant
4447
"""
4548
hmac_key, secret = STORAGE_CLIENT.create_hmac_key(
4649
service_account_email=SERVICE_ACCOUNT_EMAIL, project_id=PROJECT_ID
@@ -100,7 +103,13 @@ def test_deactivate_key(capsys, new_hmac_key):
100103

101104

102105
def test_delete_key(capsys, new_hmac_key):
103-
new_hmac_key.state = "INACTIVE"
104-
new_hmac_key.update()
106+
# Due to reuse of the HMAC key for each test function, the previous
107+
# test has deactivated the key already.
108+
try:
109+
new_hmac_key.state = "INACTIVE"
110+
new_hmac_key.update()
111+
except google.api_core.exceptions.BadRequest:
112+
pass
113+
105114
storage_delete_hmac_key.delete_key(new_hmac_key.access_id, PROJECT_ID)
106115
assert "The key is deleted" in capsys.readouterr().out

0 commit comments

Comments
 (0)