This fixture provides a function to create an account service principal via 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:
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 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.
make_run_as
fixtureThis fixture provides a function to create an account service principal via
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:
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.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:
See also
acc
,ws
,make_random
,env_or_skip
,log_account_link
.