Skip to content

Commit

Permalink
feat: testing for fgac-pg (#902)
Browse files Browse the repository at this point in the history
* fgac-pg testing

* changes
  • Loading branch information
asthamohta committed Jun 6, 2023
1 parent 19b4237 commit ad1f527
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions tests/system/test_database_api.py
Expand Up @@ -24,6 +24,7 @@
from google.type import expr_pb2
from . import _helpers
from . import _sample_data
from google.cloud.spanner_admin_database_v1 import DatabaseDialect


DBAPI_OPERATION_TIMEOUT = 240 # seconds
Expand Down Expand Up @@ -226,7 +227,6 @@ def test_iam_policy(
not_emulator,
shared_instance,
databases_to_delete,
not_postgres,
):
pool = spanner_v1.BurstyPool(labels={"testcase": "iam_policy"})
temp_db_id = _helpers.unique_id("iam_db", separator="_")
Expand Down Expand Up @@ -407,27 +407,31 @@ def test_update_ddl_w_default_leader_success(


def test_create_role_grant_access_success(
not_emulator,
shared_instance,
databases_to_delete,
not_postgres,
not_emulator, shared_instance, databases_to_delete, database_dialect
):
creator_role_parent = _helpers.unique_id("role_parent", separator="_")
creator_role_orphan = _helpers.unique_id("role_orphan", separator="_")

temp_db_id = _helpers.unique_id("dfl_ldrr_upd_ddl", separator="_")
temp_db = shared_instance.database(temp_db_id)
temp_db = shared_instance.database(temp_db_id, database_dialect=database_dialect)

create_op = temp_db.create()
databases_to_delete.append(temp_db)
create_op.result(DBAPI_OPERATION_TIMEOUT) # raises on failure / timeout.

# Create role and grant select permission on table contacts for parent role.
ddl_statements = _helpers.DDL_STATEMENTS + [
f"CREATE ROLE {creator_role_parent}",
f"CREATE ROLE {creator_role_orphan}",
f"GRANT SELECT ON TABLE contacts TO ROLE {creator_role_parent}",
]
if database_dialect == DatabaseDialect.GOOGLE_STANDARD_SQL:
ddl_statements = _helpers.DDL_STATEMENTS + [
f"CREATE ROLE {creator_role_parent}",
f"CREATE ROLE {creator_role_orphan}",
f"GRANT SELECT ON TABLE contacts TO ROLE {creator_role_parent}",
]
elif database_dialect == DatabaseDialect.POSTGRESQL:
ddl_statements = _helpers.DDL_STATEMENTS + [
f"CREATE ROLE {creator_role_parent}",
f"CREATE ROLE {creator_role_orphan}",
f"GRANT SELECT ON TABLE contacts TO {creator_role_parent}",
]

operation = temp_db.update_ddl(ddl_statements)
operation.result(DBAPI_OPERATION_TIMEOUT) # raises on failure / timeout.

Expand All @@ -445,27 +449,31 @@ def test_create_role_grant_access_success(
with temp_db.snapshot() as snapshot:
snapshot.execute_sql("SELECT * FROM contacts")

ddl_remove_roles = [
f"REVOKE SELECT ON TABLE contacts FROM ROLE {creator_role_parent}",
f"DROP ROLE {creator_role_parent}",
f"DROP ROLE {creator_role_orphan}",
]
if database_dialect == DatabaseDialect.GOOGLE_STANDARD_SQL:
ddl_remove_roles = [
f"REVOKE SELECT ON TABLE contacts FROM ROLE {creator_role_parent}",
f"DROP ROLE {creator_role_parent}",
f"DROP ROLE {creator_role_orphan}",
]
elif database_dialect == DatabaseDialect.POSTGRESQL:
ddl_remove_roles = [
f"REVOKE SELECT ON TABLE contacts FROM {creator_role_parent}",
f"DROP ROLE {creator_role_parent}",
f"DROP ROLE {creator_role_orphan}",
]
# Revoke permission and Delete roles.
operation = temp_db.update_ddl(ddl_remove_roles)
operation.result(DBAPI_OPERATION_TIMEOUT) # raises on failure / timeout.


def test_list_database_role_success(
not_emulator,
shared_instance,
databases_to_delete,
not_postgres,
not_emulator, shared_instance, databases_to_delete, database_dialect
):
creator_role_parent = _helpers.unique_id("role_parent", separator="_")
creator_role_orphan = _helpers.unique_id("role_orphan", separator="_")

temp_db_id = _helpers.unique_id("dfl_ldrr_upd_ddl", separator="_")
temp_db = shared_instance.database(temp_db_id)
temp_db = shared_instance.database(temp_db_id, database_dialect=database_dialect)

create_op = temp_db.create()
databases_to_delete.append(temp_db)
Expand Down

0 comments on commit ad1f527

Please sign in to comment.