-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### `make_run_as` fixture This fixture provides a function to create an account service principal via [`acc` fixture](#acc-fixture) and assign it to a workspace. The service principal is removed after the test is complete. The service principal is created with a random display name and assigned to the workspace with the default permissions. Use the `account_groups` argument to assign the service principal to account groups, which have the required permissions to perform a specific action. Example: ```python def test_run_as_lower_privilege_user(make_run_as, ws): run_as = make_run_as(account_groups=['account.group.name']) through_query = next(run_as.sql_fetch_all("SELECT CURRENT_USER() AS my_name")) me = ws.current_user.me() assert me.user_name != through_query.my_name ``` Returned object has the following properties: * `ws`: Workspace client that is authenticated as the ephemeral service principal. * `sql_backend`: SQL backend that is authenticated as the ephemeral service principal. * `sql_exec`: Function to execute a SQL statement on behalf of the ephemeral service principal. * `sql_fetch_all`: Function to fetch all rows from a SQL statement on behalf of the ephemeral service principal. * `display_name`: Display name of the ephemeral service principal. * `application_id`: Application ID of the ephemeral service principal. * if you want to have other fixtures available in the context of the ephemeral service principal, you can override the [`ws` fixture](#ws-fixture) on the file level, which would make all workspace fixtures provided by this plugin to run as lower privilege ephemeral service principal. You cannot combine it with the account-admin-level principal you're using to create the ephemeral principal. Example: ```python from pytest import fixture @fixture def ws(make_run_as): run_as = make_run_as(account_groups=['account.group.used.for.all.tests.in.this.file']) return run_as.ws def test_creating_notebook_on_behalf_of_ephemeral_principal(make_notebook): notebook = make_notebook() assert notebook.exists() ``` See also [`acc`](#acc-fixture), [`ws`](#ws-fixture), [`make_random`](#make_random-fixture), [`env_or_skip`](#env_or_skip-fixture), [`log_account_link`](#log_account_link-fixture).
- Loading branch information
Showing
11 changed files
with
342 additions
and
35 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
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,12 @@ | ||
from pytest import fixture | ||
|
||
|
||
@fixture | ||
def ws(make_run_as): | ||
run_as = make_run_as(account_groups=['role.labs.lsql.write']) | ||
return run_as.ws | ||
|
||
|
||
def test_creating_notebook_on_behalf_of_ephemeral_principal(make_notebook): | ||
notebook = make_notebook() | ||
assert notebook.exists() |
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