def test_fetch_expired_consented_attributes(self):
     id = "test"
     consented_attributes = ['a', 'b', 'c']
     consent = Consent(consented_attributes, 2,
                       datetime.now() - timedelta(weeks=14))
     assert consent.has_expired(self.max_month)
     self.consent_db.save_consent(id, consent)
     assert not self.cm.fetch_consented_attributes(id)
Beispiel #2
0
    def get_consent(self, id: str) -> Consent:
        hashed_id = hash_id(id, self.salt)
        result = self.consent_table.find_one(consent_id=hashed_id)
        if not result:
            return None

        consent = Consent(json.loads(result['attributes']), result['months_valid'],
                          datetime.strptime(result['timestamp'], ConsentDatasetDB.TIME_PATTERN))
        if consent.has_expired(self.max_month):
            self.remove_consent(id)
            return None
        return consent
Beispiel #3
0
    def get_consent(self, id: str) -> Consent:
        hashed_id = hash_id(id, self.salt)
        result = self.consent_table.find_one(consent_id=hashed_id)
        if not result:
            return None

        consent = Consent(
            json.loads(result['attributes']), result['months_valid'],
            datetime.strptime(result['timestamp'],
                              ConsentDatasetDB.TIME_PATTERN))
        if consent.has_expired(self.max_month):
            self.remove_consent(id)
            return None
        return consent
Beispiel #4
0
 def test_if_policy_has_not_yet_expired(self, mock_datetime, start_time,
                                        current_time, months_valid,
                                        consent_database):
     consent = Consent(self.attributes, months_valid, timestamp=start_time)
     mock_datetime.now.return_value = current_time
     consent_database.save_consent(self.consent_id, consent)
     assert consent_database.get_consent(self.consent_id)
Beispiel #5
0
    def test_store_db_in_file(self, tmpdir):
        consent_id = 'id1'
        consent = Consent(['attr1'], months_valid=1)
        tmp_file = os.path.join(str(tmpdir), 'db')
        db_url = 'sqlite:///' + tmp_file
        consent_db = ConsentDatasetDB('salt', 1, db_url)
        consent_db.save_consent(consent_id, consent)
        assert consent_db.get_consent(consent_id) == consent

        # make sure it was persisted to file
        consent_db = ConsentDatasetDB('salt', 1, db_url)
        assert consent_db.get_consent(consent_id) == consent
Beispiel #6
0
def save_consent():
    state = request.args['state']
    redirect_uri = session['redirect_endpoint']
    month = request.args['month']
    attributes = request.args['attributes'].split(",")

    if state != session['state']:
        abort(403)
    ok = request.args['consent_status']

    if ok == 'Yes' and not set(attributes).issubset(set(session['attr'])):
        abort(400)

    if ok == 'Yes':
        consent = Consent(attributes, int(month))
        current_app.cm.save_consent(session['id'], consent)
        session.clear()
    return redirect(redirect_uri)
Beispiel #7
0
 def test_save_consent_for_all_attributes_by_entering_none(
         self, consent_database):
     consent = Consent(None, 999)
     consent_database.save_consent(self.consent_id, consent)
     assert consent_database.get_consent(self.consent_id) == consent
Beispiel #8
0
 def setup(self):
     self.consent_id = 'id_123'
     self.attributes = ['name', 'email']
     self.consent = Consent(self.attributes, 1)
 def test_save_consent(self):
     id = 'test_id'
     consent = Consent(['foo', 'bar'], 2, datetime.now())
     self.cm.save_consent(id, consent)
     assert self.consent_db.get_consent(id) == consent
 def test_fetch_consented_attributes(self):
     id = "test"
     consented_attributes = ["a", "b", "c"]
     consent = Consent(consented_attributes, 3)
     self.consent_db.save_consent(id, consent)
     assert self.cm.fetch_consented_attributes(id) == consented_attributes
Beispiel #11
0
 def test_consent_has_expired(self, mock_datetime, current_time, month,
                              max_month):
     mock_datetime.now.return_value = current_time
     start_date = datetime.datetime(2015, 1, 1)
     consent = Consent(None, month, timestamp=start_date)
     assert consent.has_expired(max_month)
Beispiel #12
0
 def test_consent_has_expired(self, mock_datetime, current_time, month, max_month):
     mock_datetime.now.return_value = current_time
     start_date = datetime.datetime(2015, 1, 1)
     consent = Consent(None, month, timestamp=start_date)
     assert consent.has_expired(max_month)