Skip to content

Commit

Permalink
format file for linter
Browse files Browse the repository at this point in the history
  • Loading branch information
pmpetit committed Nov 25, 2024
1 parent 836c1de commit 7236d35
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
9 changes: 3 additions & 6 deletions dblinter/rules/T012/TableWithSensibleColumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def table_with_sensible_column(
anon = db.query(CHECK_EXTENSION)[0][0]
if anon == 0:
LOGGER.info(
"TableWithSensibleColumn is enabled, but anon extension not found. in db %s. see https://postgresql-anonymizer.readthedocs.io to install", db.database
"TableWithSensibleColumn is enabled, but anon extension not found. in db %s. see https://postgresql-anonymizer.readthedocs.io to install",
db.database,
)
return
SENSITIVE_COLS = f"""with coltable as (SELECT column_name,
Expand All @@ -36,11 +37,7 @@ def table_with_sensible_column(
sensitive_cols = db.query(SENSITIVE_COLS)
if sensitive_cols:
for elt in sensitive_cols:
message_args = (
uri,
elt[0],
elt[1]
)
message_args = (uri, elt[0], elt[1])
sarif_document.add_check(
self.get_ruleid_from_function_name(), message_args, uri, context
)
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from testcontainers.core.waiting_utils import wait_container_is_ready
from testcontainers.postgres import PostgresContainer

#PG_IMAGE = "registry.gitlab.com/dalibo/postgresql_anonymizer:latest"
# PG_IMAGE = "registry.gitlab.com/dalibo/postgresql_anonymizer:latest"
PG_IMAGE = "postgres:14"
PG_PORT = 5432
PG_USER = "postgres"
Expand All @@ -13,6 +13,7 @@
PG_DRIVER = "psycopg2"
LOGLEVEL = "WARNING"


@wait_container_is_ready()
@pytest.fixture(name="postgres_instance_args", scope="session")
def get_pg_instance():
Expand Down
14 changes: 8 additions & 6 deletions tests/rules/T012/test_TableWithSensibleColumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dblinter.function_library import FunctionLibrary
from dblinter.sarif_document import SarifDocument


def test_table_with_sensitive_column(postgres_instance_args) -> None:
args = postgres_instance_args
db = DatabaseConnection(args)
Expand All @@ -16,11 +17,11 @@ def test_table_with_sensitive_column(postgres_instance_args) -> None:
fixes=[
"Install extension anon, and create some masking rules on.",
],
message="{0} have column {1} (category {2}) that can be consider has sensitive. It should be masked for non data-operator users."
message="{0} have column {1} (category {2}) that can be consider has sensitive. It should be masked for non data-operator users.",
)
function_library = FunctionLibrary()
db.query('select anon.init()')
db.query('CREATE TABLE test (id integer, creditcard text)')
db.query("select anon.init()")
db.query("CREATE TABLE test (id integer, creditcard text)")
sarif_document = SarifDocument()
function_library.get_function_by_function_name("table_with_sensible_column")(
function_library, db, [], context, ("public", "test"), sarif_document
Expand All @@ -34,6 +35,7 @@ def test_table_with_sensitive_column(postgres_instance_args) -> None:
== "postgres.public.test have column id (category account_id) that can be consider has sensitive. It should be masked for non data-operator users."
)


def test_table_without_sensitive_column(postgres_instance_args) -> None:
args = postgres_instance_args
db = DatabaseConnection(args)
Expand All @@ -47,11 +49,11 @@ def test_table_without_sensitive_column(postgres_instance_args) -> None:
fixes=[
"Install extension anon, and create some masking rules on.",
],
message="{0} have column {1} (category {2}) that can be consider has sensitive. It should be masked for non data-operator users."
message="{0} have column {1} (category {2}) that can be consider has sensitive. It should be masked for non data-operator users.",
)
function_library = FunctionLibrary()
db.query('select anon.init()')
db.query('CREATE TABLE test (test_id integer, description text)')
db.query("select anon.init()")
db.query("CREATE TABLE test (test_id integer, description text)")
sarif_document = SarifDocument()
function_library.get_function_by_function_name("table_with_sensible_column")(
function_library, db, [], context, ("public", "test"), sarif_document
Expand Down

0 comments on commit 7236d35

Please sign in to comment.