示例#1
0
def test_readonly_sensitive_cache_data_is_encrypted(settings):
    "readonly fields marked as `encrypted` are stored in the cache with encryption"
    settings.registry.register('AWX_ENCRYPTED',
                               field_class=fields.CharField,
                               category=_('System'),
                               category_slug='system',
                               read_only=True,
                               encrypted=True)

    def rot13(obj, attribute):
        assert obj.pk is None
        return codecs.encode(getattr(obj, attribute), 'rot_13')

    native_cache = LocMemCache(str(uuid4()), {})
    cache = EncryptedCacheProxy(native_cache,
                                settings.registry,
                                encrypter=rot13,
                                decrypter=rot13)
    cache.set('AWX_ENCRYPTED', 'SECRET!')
    assert cache.get('AWX_ENCRYPTED') == 'SECRET!'
    assert native_cache.get('AWX_ENCRYPTED') == 'FRPERG!'