2023-05-17 15:58:17 +02:00
|
|
|
# Copyright 2021 Collate
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
"""
|
|
|
|
Test Column Name Scanner
|
|
|
|
"""
|
2024-09-06 08:54:23 +02:00
|
|
|
import pytest
|
2023-05-17 15:58:17 +02:00
|
|
|
|
2023-10-04 09:14:03 +02:00
|
|
|
from metadata.pii.models import TagAndConfidence
|
2023-09-04 11:02:57 +02:00
|
|
|
from metadata.pii.scanners.column_name_scanner import ColumnNameScanner
|
2023-05-17 15:58:17 +02:00
|
|
|
|
|
|
|
EXPECTED_SENSITIVE = TagAndConfidence(
|
2023-09-06 11:30:46 +02:00
|
|
|
tag_fqn="PII.Sensitive",
|
2023-05-17 15:58:17 +02:00
|
|
|
confidence=1,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-09-06 08:54:23 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def scanner() -> ColumnNameScanner:
|
|
|
|
"""Return the scanner"""
|
|
|
|
return ColumnNameScanner()
|
2023-05-17 15:58:17 +02:00
|
|
|
|
|
|
|
|
2024-09-06 08:54:23 +02:00
|
|
|
def test_column_names_none(scanner):
|
|
|
|
assert scanner.scan("access_channel") is None
|
|
|
|
assert scanner.scan("status_reason") is None
|
2023-05-17 15:58:17 +02:00
|
|
|
|
2024-09-06 08:54:23 +02:00
|
|
|
# Credit Card
|
|
|
|
assert scanner.scan("credit") is None
|
|
|
|
assert scanner.scan("user_credits") is None
|
2023-05-17 15:58:17 +02:00
|
|
|
|
2024-09-06 08:54:23 +02:00
|
|
|
# Users
|
|
|
|
assert scanner.scan("id") is None
|
|
|
|
assert scanner.scan("user_id") is None
|
2023-05-17 15:58:17 +02:00
|
|
|
|
|
|
|
|
2024-09-06 08:54:23 +02:00
|
|
|
def test_column_names_sensitive(scanner):
|
|
|
|
# Bank
|
|
|
|
assert scanner.scan("bank_account") == EXPECTED_SENSITIVE
|
2023-05-17 15:58:17 +02:00
|
|
|
|
2024-09-06 08:54:23 +02:00
|
|
|
# Credit Card
|
|
|
|
assert scanner.scan("credit_card") == EXPECTED_SENSITIVE
|
|
|
|
assert scanner.scan("credit_card_number") == EXPECTED_SENSITIVE
|
|
|
|
assert scanner.scan("personal_credit_card") == EXPECTED_SENSITIVE
|
|
|
|
|
|
|
|
# Users
|
|
|
|
assert scanner.scan("user_name") == EXPECTED_SENSITIVE
|
|
|
|
assert scanner.scan("user_first_name") == EXPECTED_SENSITIVE
|
|
|
|
assert scanner.scan("user_last_name") == EXPECTED_SENSITIVE
|
|
|
|
assert scanner.scan("client_name") == EXPECTED_SENSITIVE
|
|
|
|
assert scanner.scan("person_first_name") == EXPECTED_SENSITIVE
|
|
|
|
assert scanner.scan("client_last_name") == EXPECTED_SENSITIVE
|
|
|
|
|
|
|
|
assert scanner.scan("email") == EXPECTED_SENSITIVE
|
|
|
|
assert scanner.scan("ssn") == EXPECTED_SENSITIVE
|