From b66cd3555d8d18ec0f81b58a933f5e326cbf9b3b Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 19 Jun 2023 08:52:40 -0500 Subject: [PATCH] Add Cookies Schema (#115) Also add cookies field to PrivacyDeclaration so cookies can be specified with respect to a system's data use. --- CHANGELOG.md | 5 +++++ src/fideslang/_version.py | 2 +- src/fideslang/models.py | 17 ++++++++++++++++- src/fideslang/relationships.py | 2 +- tests/conftest.py | 2 +- tests/fideslang/test_models.py | 4 ++++ tests/fideslang/test_relationships.py | 10 ++++++++-- tests/fideslang/test_validation.py | 7 ++++++- 8 files changed, 42 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ed6dd60..27fd65de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,11 @@ The types of changes are: ## [Unreleased](https://github.com/ethyca/fideslang/compare/1.4.1...main) + +### Changed + +- Add `Cookies` schema and similar property to `PrivacyDeclaration` [#115](https://github.com/ethyca/fideslang/pull/115) + ### Fixed - Fix Fideslang visual explorer on docs site [#123](https://github.com/ethyca/fideslang/pull/123) diff --git a/src/fideslang/_version.py b/src/fideslang/_version.py index a2907cb8..12d61995 100644 --- a/src/fideslang/_version.py +++ b/src/fideslang/_version.py @@ -13,12 +13,12 @@ """Git implementation of _version.py.""" import errno +import functools import os import re import subprocess import sys from typing import Callable, Dict -import functools def get_keywords(): diff --git a/src/fideslang/models.py b/src/fideslang/models.py index 4a1ce075..f806f601 100644 --- a/src/fideslang/models.py +++ b/src/fideslang/models.py @@ -178,6 +178,19 @@ class DataQualifier(FidesModel): _no_self_reference: classmethod = no_self_reference_validator +class Cookies(BaseModel): + """The Cookies resource model""" + + name: str + path: Optional[str] + domain: Optional[str] + + class Config: + """Config for the cookies""" + + orm_mode = True + + class DataSubjectRights(BaseModel): """ The DataSubjectRights resource model. @@ -819,6 +832,9 @@ class PrivacyDeclaration(BaseModel): ingress: Optional[List[FidesKey]] = Field( description="The resources from which data is received. Any `fides_key`s included in this list reference `DataFlow` entries in the `ingress` array of any `System` resources to which this `PrivacyDeclaration` is applied." ) + cookies: Optional[List[Cookies]] = Field( + description="Cookies associated with this data use to deliver services and functionality", + ) @validator("dataset_references") @classmethod @@ -960,7 +976,6 @@ class System(FidesModel): default=DataProtectionImpactAssessment(), description=DataProtectionImpactAssessment.__doc__, ) - _sort_privacy_declarations: classmethod = validator( "privacy_declarations", allow_reuse=True )(sort_list_objects_by_name) diff --git a/src/fideslang/relationships.py b/src/fideslang/relationships.py index f1b241e9..9e18c627 100644 --- a/src/fideslang/relationships.py +++ b/src/fideslang/relationships.py @@ -6,7 +6,7 @@ import inspect from enum import Enum from functools import reduce -from typing import Optional, List, Set +from typing import List, Optional, Set from fideslang.models import BaseModel, FidesKey, Taxonomy from fideslang.utils import get_resource_by_fides_key diff --git a/tests/conftest.py b/tests/conftest.py index d5cb7eb8..e41f992f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,7 @@ """Common fixtures to be used across tests.""" +import os from typing import Any, Dict -import os import pytest import yaml diff --git a/tests/fideslang/test_models.py b/tests/fideslang/test_models.py index cd1579d6..0bb2ec61 100644 --- a/tests/fideslang/test_models.py +++ b/tests/fideslang/test_models.py @@ -75,6 +75,7 @@ def test_system_valid(self) -> None: meta={"some": "meta stuff"}, name="Test System", organization_fides_key=1, + cookies=[{"name": "test_cookie"}], privacy_declarations=[ PrivacyDeclaration( data_categories=[], @@ -84,6 +85,9 @@ def test_system_valid(self) -> None: egress=["test_system_2"], ingress=["test_system_3"], name="declaration-name", + cookies=[ + {"name": "test_cookie", "path": "/", "domain": "example.com"} + ], ) ], registry_id=1, diff --git a/tests/fideslang/test_relationships.py b/tests/fideslang/test_relationships.py index db099b44..4943741c 100644 --- a/tests/fideslang/test_relationships.py +++ b/tests/fideslang/test_relationships.py @@ -35,7 +35,10 @@ def test_find_referenced_fides_keys_2(): name="test_dc", fides_key="test_dc", description="test description", - egress=[DataFlow(fides_key="key_1", type="system", data_categories=None), DataFlow(fides_key="key_2", type="system", data_categories=None)], + egress=[ + DataFlow(fides_key="key_1", type="system", data_categories=None), + DataFlow(fides_key="key_2", type="system", data_categories=None), + ], system_type="test", privacy_declarations=None, ) @@ -66,7 +69,10 @@ def test_get_referenced_missing_keys(): name="test_system", fides_key="test_system", description="test description", - egress=[DataFlow(fides_key="key_3", type="system", data_categories=None), DataFlow(fides_key="key_4", type="system", data_categories=None)], + egress=[ + DataFlow(fides_key="key_3", type="system", data_categories=None), + DataFlow(fides_key="key_4", type="system", data_categories=None), + ], system_type="test", privacy_declarations=None, ) diff --git a/tests/fideslang/test_validation.py b/tests/fideslang/test_validation.py index 012b8b8e..6ddd0a67 100644 --- a/tests/fideslang/test_validation.py +++ b/tests/fideslang/test_validation.py @@ -226,7 +226,12 @@ def test_create_valid_system(): dataset_references=[], ) ], - egress=[DataFlow(fides_key="another_system", type="system", data_categories=None), DataFlow(fides_key="yet_another_system", type="system", data_categories=None)], + egress=[ + DataFlow(fides_key="another_system", type="system", data_categories=None), + DataFlow( + fides_key="yet_another_system", type="system", data_categories=None + ), + ], ) assert True