Esempio n. 1
0
    def test_payment(self):
        self.account: Account = Account(
            customer=self.customer,
            number=ACCOUNT__NUMBER,
            owner=ACCOUNT__OWNER,
            IBAN=ACCOUNT__IBAN,
            swift=ACCOUNT__SWIFT,
        )
        self.account.save()
        self.payment: Payment = Payment(
            account=self.account,
            value=PAYMENT__VALUE,
        )
        self.payment.save()
        payment_date = self.payment.date

        self.payment._anonymize_obj(
            base_encryption_key=self.base_encryption_key)

        anon_payment: Payment = Payment.objects.get(pk=self.payment.pk)

        assert_not_equal(anon_payment.value, PAYMENT__VALUE)
        self.assertAnonymizedDataExists(anon_payment, 'value')
        assert_not_equal(anon_payment.date, payment_date)
        self.assertAnonymizedDataExists(anon_payment, 'date')
Esempio n. 2
0
    def test_dict_str(self):
        json_dict = {
            'breed': 'labrador',
            'owner': {
                'name': 'Bob',
                'other_pets': [{
                    'name': 'Fishy'
                }]
            },
            'age': 5,
            'height': 9.5,
            'is_brown': True,
            'none_field': None
        }

        out = json.loads(
            self.field.get_encrypted_value(json.dumps(json_dict),
                                           self.encryption_key))

        assert_not_equal(out, json_dict)

        out_decrypt = json.loads(
            self.field.get_decrypted_value(json.dumps(out),
                                           self.encryption_key))

        assert_dict_equal(json_dict, out_decrypt)
Esempio n. 3
0
    def test_email(self):
        self.email: Email = Email(customer=self.customer,
                                  email=CUSTOMER__EMAIL)
        self.email.save()
        self.email._anonymize_obj(base_encryption_key=self.base_encryption_key)
        anon_email: Email = Email.objects.get(pk=self.email.pk)

        assert_not_equal(anon_email.email, CUSTOMER__EMAIL)
Esempio n. 4
0
 def test_facebook_purpose_should_anonymize_customer_with_facebook_id(self):
     customer = Customer.objects.get(pk=self.customer.pk)
     legal_reason = LegalReason.objects.create_consent(
         FACEBOOK_SLUG, customer)
     legal_reason.save()
     legal_reason.expire()
     customer.refresh_from_db()
     assert_not_equal(customer.first_name, CUSTOMER__FIRST_NAME)
Esempio n. 5
0
    def test_czech_personal_id_smart_field_anonymizer_1954_change(self):
        personal_id = "540101/0021"

        out = self.field.get_encrypted_value(personal_id, self.encryption_key)
        assert_not_equal(personal_id, out)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)
        assert_equal(personal_id, out_decrypt)
Esempio n. 6
0
    def test_czech_personal_id_smart_field_anonymizer_no_slash(self):
        personal_id = "7401040020"

        out = self.field.get_encrypted_value(personal_id, self.encryption_key)
        assert_not_equal(personal_id, out)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)
        assert_equal(personal_id, out_decrypt)
Esempio n. 7
0
    def test_czech_id_card_field_anonymizer(self):
        id_card = "297065518"

        out = self.field.get_encrypted_value(id_card, self.encryption_key)
        assert_not_equal(id_card, out)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)
        assert_equal(id_card, out_decrypt)
Esempio n. 8
0
    def test_czech_iban_field(self):
        out = self.field.get_encrypted_value(self.text_iban,
                                             self.encryption_key)
        assert_not_equal(out, self.text_iban)

        out_decrypted = self.field.get_decrypted_value(out,
                                                       self.encryption_key)
        assert_equal(out_decrypted, self.text_iban)
Esempio n. 9
0
    def test_zero_zero_area_code_phone_number(self):
        phone_number = '+420608104120'
        out = self.field.get_encrypted_value(phone_number, self.encryption_key)

        assert_not_equal(phone_number, out)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)

        assert_equal(phone_number, out_decrypt)
Esempio n. 10
0
    def test_basic_phone_number(self):
        phone_number = '608104120'
        out = self.field.get_encrypted_value(phone_number, self.encryption_key)

        assert_not_equal(phone_number, out)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)

        assert_equal(phone_number, out_decrypt)
Esempio n. 11
0
    def test_brute_force(self):
        account = CzechIBAN.parse(self.text_iban)
        key = 314

        account.brute_force_next(key)
        assert_not_equal(self.text_iban, str(account))

        account.brute_force_prev(key)
        assert_equal(self.text_iban, str(account))
Esempio n. 12
0
 def post_response(url, referer, resp, exception):
     tested_urls.append(url)
     assert_true(exception is None, msg='Received exception %s, url %s' % (force_text(exception), url))
     if resp.status_code != 200:
         failed_urls.append(url)
         self.logger.warning('Response code for url %s from referer %s should be 200 but code is %s, user %s' %
                             (url, referer, resp.status_code, self.logged_user.user))
     assert_not_equal(resp.status_code, 500, msg='Response code for url %s from referer %s is 500, user %s' %
                      (url, referer, self.logged_user.user))
Esempio n. 13
0
    def test_normal(self):
        email = '1:[email protected]'
        out = self.field.get_encrypted_value(email, self.encryption_key)

        assert_not_equal(out, email)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)

        assert_equal(out_decrypt, email)
Esempio n. 14
0
    def test_decimal_field_negative(self):
        decimal = Decimal('-3.14159265358979')
        out = self.field.get_encrypted_value(decimal, self.encryption_key)

        assert_not_equal(out, decimal)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)

        assert_equal(out_decrypt, decimal)
Esempio n. 15
0
    def test_only_superuser_may_edit_user(self):
        user = self.get_user_obj()
        resp = self.get('%s%s/' % (self.USER_UI_URL, user.pk))
        assert_http_forbidden(resp)

        CHANGED_USERNAME = '******'
        self.post('%s%s/' % (self.USER_UI_URL, user.pk), data={'edit-is-user-username': CHANGED_USERNAME})
        assert_http_forbidden(resp)
        assert_not_equal(User.objects.get(pk=user.pk).username, CHANGED_USERNAME)
Esempio n. 16
0
    def test_char_field(self):
        name = 'John CENA'
        out = self.field.get_encrypted_value(name, self.encryption_key)

        assert_not_equal(out, name)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)

        assert_equal(out_decrypt, name)
Esempio n. 17
0
    def test_str_value(self):
        text = 'John CENA'
        out = self.field.anonymize_json_value(text, self.encryption_key)

        assert_not_equal(out, text)
        out_decrypt = self.field.anonymize_json_value(out, self.encryption_key,
                                                      False)

        assert_equal(out_decrypt, text)
Esempio n. 18
0
    def test_date_field(self):
        date = timezone.now()
        out = self.field.get_encrypted_value(date, self.encryption_key)

        assert_not_equal(out, date)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)

        assert_equal(out_decrypt, date)
Esempio n. 19
0
    def test_ip_addr_v_6_field(self):
        ip = '::1'
        out = self.field.get_encrypted_value(ip, self.encryption_key)

        assert_not_equal(out, ip)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)

        assert_equal(out_decrypt, ip)
Esempio n. 20
0
 def test_translate_iban(self):
     """
     Test function `gdpr.encryption.translate_iban` by using an example IBAN for every country using IBAN system.
     """
     for IBAN in IBANS:
         encrypted = translate_iban(self.encryption_key, IBAN)
         assert_not_equal(encrypted, IBAN, "The encrypted IBAN is equal to the original IBAN.")
         assert_equal(translate_iban(self.encryption_key, encrypted, False), IBAN,
                      "The decrypted IBAN is not equal to the original IBAN.")
Esempio n. 21
0
    def test_anonymization_field_matrix(self):
        self.customer._anonymize_obj(fields=('first_name', ))
        anon_customer: Customer = Customer.objects.get(pk=self.customer.pk)

        assert_not_equal(anon_customer.first_name, CUSTOMER__FIRST_NAME)
        self.assertAnonymizedDataExists(anon_customer, 'first_name')

        assert_equal(anon_customer.last_name, CUSTOMER__LAST_NAME)
        self.assertAnonymizedDataNotExists(anon_customer, 'last_name')
Esempio n. 22
0
    def test_only_superuser_may_edit_user(self):
        user = self.get_user_obj()
        resp = self.get('%s%s/' % (self.USER_UI_URL, user.pk))
        assert_http_not_found(resp)

        CHANGED_USERNAME = '******'
        self.post('%s%s/' % (self.USER_UI_URL, user.pk), data={'detail-is-user-username': CHANGED_USERNAME})
        assert_http_not_found(resp)
        assert_not_equal(User.objects.get(pk=user.pk).username, CHANGED_USERNAME)
Esempio n. 23
0
    def test_int_value_overflow(self):
        value = 9
        out = self.field.anonymize_json_value(value, self.encryption_key)

        assert_not_equal(out, value)
        out_decrypt = self.field.anonymize_json_value(out, self.encryption_key,
                                                      False)

        assert_equal(out_decrypt, value)
Esempio n. 24
0
    def test_integer_field_negative(self):
        number = -42
        out = self.field.get_encrypted_value(number, self.encryption_key)

        assert_not_equal(out, number)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)

        assert_equal(out_decrypt, number)
Esempio n. 25
0
    def test_account_number_simple_field(self):
        account_number = '2501277007/2010'
        out = self.field.get_encrypted_value(account_number,
                                             self.encryption_key)

        assert_not_equal(out, account_number)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)

        assert_equal(out_decrypt, account_number)
Esempio n. 26
0
    def test_account_number_simple_field_smart_method(self):
        field = CzechAccountNumberFieldAnonymizer(use_smart_method=True)
        account_number = '2501277007/2010'
        out = field.get_encrypted_value(account_number, self.encryption_key)

        assert_not_equal(out, account_number)

        out_decrypt = field.get_decrypted_value(out, self.encryption_key)

        assert_equal(out_decrypt, account_number)
Esempio n. 27
0
    def test_account_number_with_pre_num_field(self):
        account_number = '19-2000145399/0800'
        out = self.field.get_encrypted_value(account_number,
                                             self.encryption_key)

        assert_not_equal(out, account_number)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)

        assert_equal(out_decrypt, account_number)
Esempio n. 28
0
    def test_account_number_with_pre_num_field_smart_method(self):
        field = CzechAccountNumberFieldAnonymizer(use_smart_method=True)
        account_number = '19-2000145399/0800'
        out = field.get_encrypted_value(account_number, self.encryption_key)

        assert_not_equal(out, account_number)

        out_decrypt = field.get_decrypted_value(out, self.encryption_key)

        assert_equal(out_decrypt, account_number)
Esempio n. 29
0
    def test_encrypt_email_address(self):
        """
        Test function `gdpr.encryption.encrypt_email_address` by using email address from Faker lib.
        """
        cleartext = self.faker.email()

        ciphertext = encrypt_email_address(self.encryption_key, cleartext)
        assert_not_equal(cleartext, ciphertext, "The encrypted email address is equal to the original email address.")

        decrypted = decrypt_email_address(self.encryption_key, ciphertext)
        assert_equal(cleartext, decrypted, "The decrypted email address is not equal to the original email address.")
Esempio n. 30
0
    def test_encrypt_text_full_name(self):
        """
        Test function `gdpr.encryption.encrypt_text` by using human full name from Faker lib.
        """
        cleartext = self.faker.name()

        ciphertext = encrypt_text(self.encryption_key, cleartext)
        assert_not_equal(cleartext, ciphertext, "The encrypted name is equal to the original name.")

        decrypted = decrypt_text(self.encryption_key, ciphertext)
        assert_equal(cleartext, decrypted, "The decrypted name is not equal to the original name.")
Esempio n. 31
0
    def test_char_field_transliteration(self):
        name = 'François'
        fixed_name = 'Francois'
        field = CharFieldAnonymizer(transliterate=True)
        out = field.get_encrypted_value(name, self.encryption_key)

        assert_not_equal(out, name)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)

        assert_equal(out_decrypt, fixed_name)
Esempio n. 32
0
    def test_char_field_transliteration_full_czech(self):
        text = 'Příliš žluťoučký kůň úpěl ďábelské ódy'
        fixed_text = 'Prilis zlutoucky kun upel dabelske ody'
        field = CharFieldAnonymizer(transliterate=True)
        out = field.get_encrypted_value(text, self.encryption_key)

        assert_not_equal(out, text)

        out_decrypt = self.field.get_decrypted_value(out, self.encryption_key)

        assert_equal(out_decrypt, fixed_text)
Esempio n. 33
0
 def post_response(url, referer, resp, exception):
     tested_urls.append(url)
     gt.assert_true(
         exception is None or isinstance(exception, HTMLParseError),
         msg="Received exception %s" % force_text(exception),
     )
     if resp.status_code != 200:
         failed_urls.append(url)
         self.logger.warning(
             "Response code for url %s from referer %s should be 200 but code is %s, user %s"
             % (url, referer, resp.status_code, self.logged_user.user)
         )
     gt.assert_not_equal(
         resp.status_code,
         500,
         msg="Response code for url %s from referer %s is 500, user %s" % (url, referer, self.logged_user.user),
     )