mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-24 08:50:24 +00:00
Add test for memcached key sanitation
This commit is contained in:
parent
f173861b53
commit
eb36ae399e
1 changed files with 35 additions and 1 deletions
|
|
@ -1,5 +1,10 @@
|
|||
from django.conf import settings
|
||||
from hashlib import md5
|
||||
from imagekit.cachefiles import ImageCacheFile
|
||||
from nose.tools import raises
|
||||
from imagekit.cachefiles.backends import Simple
|
||||
from nose.tools import raises, eq_
|
||||
import random
|
||||
import string
|
||||
from .imagegenerators import TestSpec
|
||||
from .utils import (assert_file_is_truthy, assert_file_is_falsy,
|
||||
DummyAsyncCacheFileBackend, get_unique_image_file)
|
||||
|
|
@ -41,3 +46,32 @@ def test_no_source_error():
|
|||
spec = TestSpec(source=None)
|
||||
file = ImageCacheFile(spec)
|
||||
file.generate()
|
||||
|
||||
|
||||
def test_memcached_cache_key():
|
||||
"""
|
||||
Ensure the default cachefile backend is sanitizing its cache key for
|
||||
memcached by default.
|
||||
|
||||
"""
|
||||
|
||||
class MockFile(object):
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
backend = Simple()
|
||||
extra_char_count = len('state-') + len(settings.IMAGEKIT_CACHE_PREFIX)
|
||||
|
||||
length = 199 - extra_char_count
|
||||
filename = '1' * length
|
||||
file = MockFile(filename)
|
||||
eq_(backend.get_key(file), '%s%s-state' %
|
||||
(settings.IMAGEKIT_CACHE_PREFIX, file.name))
|
||||
|
||||
length = 200 - extra_char_count
|
||||
filename = '1' * length
|
||||
file = MockFile(filename)
|
||||
eq_(backend.get_key(file), '%s%s:%s' % (
|
||||
settings.IMAGEKIT_CACHE_PREFIX,
|
||||
'1' * (200 - len(':') - 32 - len(settings.IMAGEKIT_CACHE_PREFIX)),
|
||||
md5('%s%s-state' % (settings.IMAGEKIT_CACHE_PREFIX, filename)).hexdigest()))
|
||||
|
|
|
|||
Loading…
Reference in a new issue