Exemplo n.º 1
0
class Option(models.Model):
    question = models.ForeignKey(to=SubQuestion, on_delete=models.CASCADE)
    option = fields.EncryptedTextField()
    created_by = models.ForeignKey(to=User,
                                   on_delete=models.CASCADE,
                                   null=True)
    created_at = models.DateTimeField(auto_now=True, null=True)
Exemplo n.º 2
0
    def test_no_hkdf(self, settings):
        """Can set FERNET_USE_HKDF=False to avoid HKDF."""
        settings.FERNET_USE_HKDF = False
        k1 = Fernet.generate_key()
        settings.FERNET_KEYS = [k1]
        f = fields.EncryptedTextField()
        fernet = Fernet(k1)

        assert fernet.decrypt(f.fernet.encrypt(b'foo')) == b'foo'
Exemplo n.º 3
0
    def test_key_rotation(self, settings):
        """Can supply multiple `keys` for key rotation."""
        settings.FERNET_KEYS = ['key1', 'key2']
        f = fields.EncryptedTextField()

        enc1 = Fernet(f.fernet_keys[0]).encrypt(b'enc1')
        enc2 = Fernet(f.fernet_keys[1]).encrypt(b'enc2')

        assert f.fernet.decrypt(enc1) == b'enc1'
        assert f.fernet.decrypt(enc2) == b'enc2'
Exemplo n.º 4
0
class SubQuestion(models.Model):
    question = fields.EncryptedTextField(_("question"))
    question_id = models.ForeignKey(to=Question, on_delete=models.CASCADE)
    marks = models.IntegerField()
    is_mcq_question = models.BooleanField(default=False)
    created_by = models.ForeignKey(to=User,
                                   on_delete=models.CASCADE,
                                   null=True)
    created_at = models.DateTimeField(auto_now=True, null=True)

    def __str__(self):
        return self.question
Exemplo n.º 5
0
class Question(models.Model):
    question = fields.EncryptedTextField(_("question"), null=True, blank=True)
    has_images = models.BooleanField(default=False)
    marks = models.IntegerField()
    topic = models.ForeignKey(to=Topics, on_delete=models.CASCADE)
    course_outcomes = models.ManyToManyField(to=CourseOutcome)
    blooms_category = models.ManyToManyField(to=BloomsCategory)
    has_subquestions = models.BooleanField(default=True)
    question_type = models.ForeignKey(to=QuestionTypes,
                                      on_delete=models.CASCADE,
                                      null=True)
    created_by = models.ForeignKey(to=User,
                                   on_delete=models.CASCADE,
                                   null=True)
    created_at = models.DateTimeField(auto_now=True, null=True)

    def __str__(self):
        return self.question
Exemplo n.º 6
0
    def test_fallback_to_secret_key(self, settings):
        """If no FERNET_KEY setting, use SECRET_KEY."""
        f = fields.EncryptedTextField()

        assert f.keys == [settings.SECRET_KEY]
Exemplo n.º 7
0
    def test_key_from_settings(self, settings):
        """If present, use settings.FERNET_KEYS."""
        settings.FERNET_KEYS = ['secret']
        f = fields.EncryptedTextField()

        assert f.keys == settings.FERNET_KEYS
Exemplo n.º 8
0
class SlackWorkspaceEmojiWatcher(VersionedModel):
    """
    Class to stores the data associated with a particular team.
    """

    # ---- Inner classes -------------------------------------------------

    class Meta(object):
        verbose_name = 'Slack Workspace Emoji Watcher'

    # ---- Properties ----------------------------------------------------

    team_id = d_d_models.CharField(
        default='T',
        max_length=TEAM_ID_MAX_LEN,
        null=False,
        unique=True,
        validators=[
            d_c_validators.RegexValidator(
                TEAM_ID_RE,
                message=gettext('Must be of the format (e.g.) T123ABC...')),
        ],
        verbose_name=gettext('Team ID'),
    )

    team_id.short_description = gettext('Slack Team ID (e.g., T123ABC...)')

    access_token = fernet_fields.EncryptedCharField(
        default='xoxa-',
        max_length=ACCESS_TOKEN_MAX_LEN,
        null=False,
        validators=[
            d_c_validators.RegexValidator(
                ACCESS_TOKEN_RE,
                message=gettext(
                    'Must be of the format (e.g.) xoxa-1f2e3d-4c5b6a...')),
        ],
        verbose_name=gettext('Access Token'),
    )

    access_token.short_description = gettext(
        'Slack OAuth access token (e.g., xoxa-1f2e3d-4c5b6a...)')

    channel_id = d_d_models.CharField(
        default='C',
        max_length=CHANNEL_ID_MAX_LEN,
        null=False,
        validators=[
            d_c_validators.RegexValidator(
                CHANNEL_ID_RE,
                message=gettext('Must be of the format (e.g.) C123ABC...')),
        ],
        verbose_name=gettext('Channel ID'),
    )

    channel_id.short_description = gettext(
        'Slack Channel ID (e.g., C123ABC...)')

    icon_emoji = d_d_models.CharField(
        default=ICON_EMOJI_DEFAULT,
        max_length=ICON_EMOJI_MAX_LEN,
        null=False,
        validators=[
            d_c_validators.RegexValidator(
                ICON_EMOJI_RE,
                message=gettext(
                    'Must be of the format (e.g.) :emoji_name:...')),
        ],
        verbose_name=gettext('Icon Emoji'),
    )

    icon_emoji.short_description = gettext('Icon Emoji (e.g., {}...)').format(
        ICON_EMOJI_DEFAULT)

    notes = fernet_fields.EncryptedTextField(
        blank=True,
        default='',
    )

    notes.short_description = gettext('Your Notes (not transmitted)').format(
        ICON_EMOJI_DEFAULT)