64 lines
1.4 KiB
Python
64 lines
1.4 KiB
Python
from ..sqlite import _SQLiteBackend
|
|
|
|
|
|
iri_base = 'http://example.com/test_record_'
|
|
|
|
hostile_policies = [
|
|
"x') or 1=1 --",
|
|
"O'Neal",
|
|
'a"b',
|
|
'p;drop table thing',
|
|
]
|
|
|
|
|
|
test_records = [
|
|
{
|
|
'pid': f'abc:person_p_{i}',
|
|
'name': f'Person P{i}',
|
|
'annotations': {
|
|
'policy': policy,
|
|
},
|
|
}
|
|
for i, policy in enumerate(hostile_policies)
|
|
]
|
|
|
|
|
|
test_records.extend(
|
|
[
|
|
{
|
|
'pid': f'abc:person_n_{i}',
|
|
'name': f'Person N{i}',
|
|
}
|
|
for i in range(3)
|
|
]
|
|
)
|
|
|
|
|
|
def _add_test_records(sqlite_backend: _SQLiteBackend):
|
|
for index, json_object in enumerate(test_records):
|
|
sqlite_backend.add_record(
|
|
iri=f'{iri_base}{index}',
|
|
class_name='Person',
|
|
json_object=json_object,
|
|
)
|
|
|
|
|
|
def test_sqlite_hostile_policy_annotation(tmp_path):
|
|
sqlite_backend = _SQLiteBackend(
|
|
db_path=tmp_path / 'test.db',
|
|
)
|
|
|
|
_add_test_records(sqlite_backend)
|
|
|
|
records = sqlite_backend.get_all_records(
|
|
policy_annotation_tag='policy',
|
|
active_policies=set(hostile_policies),
|
|
)
|
|
assert len(records) == len(test_records)
|
|
return
|
|
for iri in (f'{iri_base}{i}' for i in range(len(test_records))):
|
|
record = sqlite_backend.get_record_by_iri(
|
|
iri=iri,
|
|
policy_annotation_tag='policy',
|
|
active_policies=set(hostile_policies),
|
|
)
|