-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add PACKAGES POLICY resource * Cleanup * debug * debug * build * weird priv issues * dont permit role switching in spi install * no roles * Resolvers, sproc fixes --------- Co-authored-by: TJ Murphy <[email protected]>
- Loading branch information
Showing
30 changed files
with
704 additions
and
170 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,4 +162,5 @@ cython_debug/ | |
.python-version | ||
.DS_Store | ||
.vscode/ | ||
.packages/ | ||
.packages/ | ||
.build/ |
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,18 @@ | ||
{ | ||
"name": "EXAMPLE_POLICY", | ||
"language": "PYTHON", | ||
"allowlist": [ | ||
"numpy", | ||
"pandas" | ||
], | ||
"blocklist": [ | ||
"os", | ||
"sys" | ||
], | ||
"additional_creation_blocklist": [ | ||
"exec", | ||
"eval" | ||
], | ||
"comment": "This is an example packages policy.", | ||
"owner": "SYSADMIN" | ||
} |
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,6 @@ | ||
CREATE OR REPLACE PACKAGES POLICY example_policy | ||
LANGUAGE PYTHON | ||
ALLOWLIST = ('numpy', 'pandas') | ||
BLOCKLIST = ('os', 'sys') | ||
ADDITIONAL_CREATION_BLOCKLIST = ('exec', 'eval') | ||
COMMENT = 'This is an example packages policy.' |
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,70 @@ | ||
import pytest | ||
|
||
from titan import Blueprint, User, Role, RoleGrant, data_provider | ||
from titan.blueprint import MissingPrivilegeException | ||
from tests.helpers import get_json_fixtures | ||
|
||
JSON_FIXTURES = list(get_json_fixtures()) | ||
|
||
|
||
@pytest.fixture( | ||
params=JSON_FIXTURES, | ||
ids=[resource_cls.__name__ for resource_cls, _ in JSON_FIXTURES], | ||
scope="function", | ||
) | ||
def resource(request): | ||
resource_cls, data = request.param | ||
yield resource_cls, data | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def user(suffix, cursor, marked_for_cleanup): | ||
user = User(name=f"TEST_USER_{suffix}".upper(), owner="ACCOUNTADMIN") | ||
cursor.execute(user.create_sql()) | ||
marked_for_cleanup.append(user) | ||
return user | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def role(suffix, cursor, marked_for_cleanup): | ||
role = Role(name=f"TEST_ROLE_{suffix}".upper(), owner="ACCOUNTADMIN") | ||
cursor.execute(role.create_sql()) | ||
marked_for_cleanup.append(role) | ||
return role | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def noprivs_role(cursor, test_db, marked_for_cleanup): | ||
role = Role(name="NOPRIVS") | ||
cursor.execute(role.create_sql(if_not_exists=True)) | ||
cursor.execute(f"GRANT ROLE NOPRIVS TO USER {cursor.connection.user}") | ||
cursor.execute(f"GRANT USAGE ON DATABASE {test_db} TO ROLE NOPRIVS") | ||
cursor.execute(f"GRANT USAGE ON SCHEMA {test_db}.PUBLIC TO ROLE NOPRIVS") | ||
marked_for_cleanup.append(role) | ||
return role.name | ||
|
||
|
||
@pytest.mark.requires_snowflake | ||
def test_plan(cursor, user, role): | ||
session = cursor.connection | ||
bp = Blueprint(name="test") | ||
role_grant = RoleGrant(role=role, to_user=user) | ||
bp.add(role_grant) | ||
changes = bp.plan(session) | ||
assert len(changes) == 1 | ||
bp.apply(session, changes) | ||
role_grant_remote = data_provider.fetch_role_grant(session, role_grant.fqn) | ||
assert role_grant_remote | ||
|
||
|
||
# noprivs_role is causing issues and breaking other integration tests | ||
# @pytest.mark.requires_snowflake | ||
# def test_privilege_scanning(resource, noprivs_role, cursor, marked_for_cleanup): | ||
# resource_cls, data = resource | ||
# cursor.execute(f"USE ROLE {noprivs_role}") | ||
# bp = Blueprint(name="test", allow_role_switching=False) | ||
# res = resource_cls(**data) | ||
# bp.add(res) | ||
# marked_for_cleanup.append(res) | ||
# with pytest.raises(MissingPrivilegeException): | ||
# bp.apply(cursor.connection) |
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
import pytest | ||
|
||
from titan import __version__ | ||
|
||
|
||
@pytest.mark.requires_snowflake | ||
def test_install(suffix, cursor): | ||
install = open("scripts/install", "r").read() | ||
install = install.replace(__version__, f"{__version__}-dev") | ||
cursor.execute("USE ROLE SYSADMIN") | ||
cursor.execute(f"CREATE DATABASE TITAN_SPI_TEST_{suffix}") | ||
cursor.execute(f"CREATE STAGE TITAN_SPI_TEST_{suffix}.PUBLIC.TITAN_AWS URL = 's3://titan-snowflake/';") | ||
cursor.execute(install) |
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,47 @@ | ||
from titan.logical_grant import And, LogicalGrant, Or | ||
|
||
|
||
def test_logical_grant_init(): | ||
lg = LogicalGrant("urn", "priv") | ||
assert lg.urn == "urn" | ||
assert lg.priv == "priv" | ||
|
||
|
||
def test_logical_grant_repr(): | ||
lg = LogicalGrant("urn", "priv") | ||
assert repr(lg) == "LogicalGrant(urn, priv)" | ||
|
||
|
||
def test_logical_grant_eq(): | ||
lg1 = LogicalGrant("urn", "priv") | ||
lg2 = LogicalGrant("urn", "priv") | ||
assert lg1 == lg2 | ||
|
||
|
||
def test_logical_grant_hash(): | ||
lg = LogicalGrant("urn", "priv") | ||
assert hash(lg) == hash(("urn", "priv")) | ||
|
||
|
||
def test_logical_grant_or(): | ||
lg1 = LogicalGrant("urn1", "priv1") | ||
lg2 = LogicalGrant("urn2", "priv2") | ||
lg3 = LogicalGrant("urn3", "priv3") | ||
result = lg1 | lg2 | ||
assert isinstance(result, Or) | ||
assert result.args == (lg1, lg2) | ||
result = result | lg3 | ||
assert isinstance(result, Or) | ||
assert result.args == (lg1, lg2, lg3) | ||
|
||
|
||
def test_logical_grant_and(): | ||
lg1 = LogicalGrant("urn1", "priv1") | ||
lg2 = LogicalGrant("urn2", "priv2") | ||
lg3 = LogicalGrant("urn3", "priv3") | ||
result = lg1 & lg2 | ||
assert isinstance(result, And) | ||
assert result.args == (lg1, lg2) | ||
result = result & lg3 | ||
assert isinstance(result, And) | ||
assert result.args == (lg1, lg2, lg3) |
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 |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
"Warehouse", | ||
] | ||
|
||
__version__ = "0.1.1" | ||
__version__ = "0.1.2" | ||
|
||
LOGO = r""" | ||
__ _ __ | ||
|
Oops, something went wrong.