Skip to content

Commit 3ab8c3b

Browse files
authored
[Internal] Fix tests/integration/test_dbutils.py::test_secrets (#884)
## What changes are proposed in this pull request? `tests/integration/test_dbutils.py::test_secrets` currently assumes that the principal running the test has access to all key vaults in our test workspace. This isn't necessarily the case. To alleviate this, rather than listing all secrets across all scopes, we just check that our scope is included in the list of secret scopes, and only list the secrets from our scope. ## How is this tested? Integration tests will automatically run on this PR.
1 parent b64ef18 commit 3ab8c3b

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

tests/integration/test_dbutils.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,21 @@ def test_secrets(w, random):
192192

193193
from databricks.sdk.runtime import dbutils
194194

195+
all_scopes = dbutils.secrets.listScopes()
196+
assert random_scope in [scope.getName() for scope in all_scopes]
197+
195198
all_secrets = {}
196-
for secret_scope in dbutils.secrets.listScopes():
197-
scope = secret_scope.name
198-
for secret_metadata in dbutils.secrets.list(scope):
199-
key = secret_metadata.key
200-
try:
201-
all_secrets[f'{scope}.{key}'] = dbutils.secrets.get(scope, key)
202-
except DatabricksError as e:
203-
if e.error_code == 'BAD_REQUEST':
204-
pytest.skip('dbconnect is not enabled on this workspace')
205-
raise e
199+
for secret_metadata in dbutils.secrets.list(random_scope):
200+
key = secret_metadata.key
201+
try:
202+
all_secrets[key] = dbutils.secrets.get(random_scope, key)
203+
except DatabricksError as e:
204+
if e.error_code == 'BAD_REQUEST':
205+
pytest.skip('dbconnect is not enabled on this workspace')
206+
raise e
206207

207208
logger.info(f'After loading secret: {random_value}')
208209
logging.getLogger('databricks.sdk').info(f'After loading secret: {random_value}')
209210

210-
assert all_secrets[f'{random_scope}.{key_for_string}'] == random_value
211-
assert all_secrets[f'{random_scope}.{key_for_bytes}'] == random_value
211+
assert all_secrets[key_for_string] == random_value
212+
assert all_secrets[key_for_bytes] == random_value

0 commit comments

Comments
 (0)