<commit_before>import uuid

import pytest

from keybar.models.entry import Entry
from keybar.tests.factories.entry import EntryFactory
from keybar.tests.factories.device import DeviceFactory, PRIVATE_KEY
from keybar.tests.factories.user import UserFactory


@pytest.mark.django_db
class TestEntry:

    def setup(self):
        self.device = DeviceFactory.create()

    def test_has_owner(self):
        entry = EntryFactory.create()
        assert entry.owner is not None

    def test_entry_has_uuid_as_primary_key(self):
        entry = EntryFactory.create()

        # raises on invalid uuid
        uuid.UUID(str(entry.pk))

    def test_entry_can_have_tags(self):
        entry = EntryFactory.create()

        # defaults to empty list.
        assert entry.tags is None

        entry.tags = ['tag1', 'tag2']
        entry.save()

        assert Entry.objects.get(pk=entry.pk).tags == ['tag1', 'tag2']

    def test_create_update_decrypt(self):
        user = UserFactory.create()

        entry = Entry.create(self.device.id, 'this is secret', PRIVATE_KEY, owner=user)

        assert entry.salt is not None
        assert entry.decrypt(entry.id, self.device.id, PRIVATE_KEY) == b'this is secret'

        old_salt = entry.salt
        entry.update('this is a new secret', PRIVATE_KEY)
        entry.save()

        # Always generates a new salt. TODO: Make sure this actually makes sense!
        assert entry.salt != old_salt

        assert entry.decrypt(entry.id, self.device.id, PRIVATE_KEY) == b'this is a new secret'
<commit_msg>regenerating the salt actually makes sense<commit_after>import uuid

import pytest

from keybar.models.entry import Entry
from keybar.tests.factories.entry import EntryFactory
from keybar.tests.factories.device import DeviceFactory, PRIVATE_KEY
from keybar.tests.factories.user import UserFactory


@pytest.mark.django_db
class TestEntry:

    def setup(self):
        self.device = DeviceFactory.create()

    def test_has_owner(self):
        entry = EntryFactory.create()
        assert entry.owner is not None

    def test_entry_has_uuid_as_primary_key(self):
        entry = EntryFactory.create()

        # raises on invalid uuid
        uuid.UUID(str(entry.pk))

    def test_entry_can_have_tags(self):
        entry = EntryFactory.create()

        # defaults to empty list.
        assert entry.tags is None

        entry.tags = ['tag1', 'tag2']
        entry.save()

        assert Entry.objects.get(pk=entry.pk).tags == ['tag1', 'tag2']

    def test_create_update_decrypt(self):
        user = UserFactory.create()

        entry = Entry.create(self.device.id, 'this is secret', PRIVATE_KEY, owner=user)

        assert entry.salt is not None
        assert entry.decrypt(entry.id, self.device.id, PRIVATE_KEY) == b'this is secret'

        old_salt = entry.salt
        entry.update('this is a new secret', PRIVATE_KEY)
        entry.save()

        # Always generates a new salt.
        assert entry.salt != old_salt

        assert entry.decrypt(entry.id, self.device.id, PRIVATE_KEY) == b'this is a new secret'

{'fraction_non_alphanumeric': 0.09629147690305791, 'fraction_numerical': 0.002602472348731295, 'mean_word_length': 2.8679245283018866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3296330', 'n_tokens_mistral': 951, 'n_tokens_neox': 910, 'n_words': 242}