Skip to content

Commit

Permalink
give root grant, split up test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Jan 16, 2019
1 parent f4084f0 commit 1596174
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
3 changes: 3 additions & 0 deletions core/dbt/adapters/base/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ def close(cls, connection):
# On windows, sometimes connection handles don't have a close() attr.
if hasattr(connection.handle, 'close'):
connection.handle.close()
else:
logger.debug('On {}: No close available on handle'
.format(connection.name))

connection.state = 'closed'

Expand Down
15 changes: 4 additions & 11 deletions test/integration/010_permission_tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ class TestPermissions(DBTIntegrationTest):

def setUp(self):
DBTIntegrationTest.setUp(self)

self.run_sql_file("test/integration/010_permission_tests/seed.sql")

def tearDown(self):
self.run_sql_file("test/integration/010_permission_tests/tearDown.sql")

DBTIntegrationTest.tearDown(self)

@property
def schema(self):
return "permission_tests_010"
Expand All @@ -22,9 +16,8 @@ def models(self):
return "test/integration/010_permission_tests/models"

@attr(type='postgres')
def test_create_schema_permissions(self):
def test_no_create_schema_permissions(self):
# the noaccess user does not have permissions to create a schema -- this should fail

failed = False
self.run_sql('drop schema if exists "{}" cascade'.format(self.unique_schema()))
try:
Expand All @@ -34,10 +27,10 @@ def test_create_schema_permissions(self):

self.assertTrue(failed)

self.run_sql_file("test/integration/010_permission_tests/seed.sql")

@attr(type='postgres')
def test_create_schema_permissions(self):
# now it should work!
self.run_sql('grant create on database dbt to noaccess'.format(self.unique_schema()))
self.run_sql('grant create on database {} to noaccess'.format(self.default_database))
self.run_sql('grant usage, create on schema "{}" to noaccess'.format(self.unique_schema()))
self.run_sql('grant select on all tables in schema "{}" to noaccess'.format(self.unique_schema()))

Expand Down
1 change: 1 addition & 0 deletions test/integration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ def run_sql(self, query, fetch='None', kwargs=None, connection_name=None):

conn = self.adapter.acquire_connection(connection_name)
with conn.handle.cursor() as cursor:
logger.debug('test connection "{}" executing: {}'.format(connection_name, sql))
try:
cursor.execute(sql)
conn.handle.commit()
Expand Down
2 changes: 1 addition & 1 deletion test/setup_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fi
createdb dbt
psql -c "CREATE ROLE root WITH PASSWORD 'password';"
psql -c "ALTER ROLE root WITH LOGIN;"
psql -c "GRANT CREATE, CONNECT ON DATABASE dbt TO root;"
psql -c "GRANT CREATE, CONNECT ON DATABASE dbt TO root WITH GRANT OPTION;"

psql -c "CREATE ROLE noaccess WITH PASSWORD 'password' NOSUPERUSER;"
psql -c "ALTER ROLE noaccess WITH LOGIN;"
Expand Down

0 comments on commit 1596174

Please sign in to comment.