예제 #1
0
파일: root.py 프로젝트: gingerkaan/serveros
    def __init__(self, path, *args, **kwargs):
        super(RootResource, self).__init__(path, *args, **kwargs)

        if config.EnableSACLs:
            self.useSacls = True

        self.contentFilters = []

        if (
            config.EnableResponseCache and
            config.Memcached.Pools.Default.ClientEnabled
        ):
            self.responseCache = MemcacheResponseCache(self.fp)

            # These class attributes need to be setup with our memcache\
            # notifier
            DirectoryPrincipalResource.cacheNotifierFactory = (
                MemcacheChangeNotifier
            )
        else:
            self.responseCache = DisabledCache()

        if config.ResponseCompression:
            from txweb2.filter import gzip
            self.contentFilters.append((gzip.gzipfilter, True))
예제 #2
0
    def setUp(self):
        super(MemcacheResponseCacheTests, self).setUp()

        memcacheStub = InMemoryMemcacheProtocol()
        self.rc = MemcacheResponseCache(None, cachePool=memcacheStub)
        self.tokens = {}

        self.tokens['/calendars/__uids__/cdaboo/'] = 'uriToken0'
        self.tokens['/calendars/__uids__/cdaboo/calendars/'] = 'childToken0'
        self.tokens['/principals/__uids__/cdaboo/'] = 'principalToken0'
        self.tokens['/principals/__uids__/dreid/'] = 'principalTokenX'

        def _getToken(uri, cachePoolHandle=None):
            return succeed(self.tokens.get(uri))

        self.rc._tokenForURI = _getToken

        self.expected_response = (200, Headers({}), "Foo")

        expected_key = hashlib.md5(':'.join([
            str(t) for t in (
                'PROPFIND',
                '/principals/__uids__/cdaboo/',
                '/calendars/__uids__/cdaboo/',
                '1',
                hash('foobar'),
            )
        ])).hexdigest()

        memcacheStub._cache[expected_key] = (
            0,  # flags
            cPickle.dumps(
                ('principalToken0', StubDirectoryRecord('cdaboo').cacheToken(),
                 'uriToken0', {
                     '/calendars/__uids__/cdaboo/calendars/': 'childToken0'
                 }, (self.expected_response[0],
                     dict(list(self.expected_response[1].getAllRawHeaders())),
                     self.expected_response[2]))))

        self.memcacheStub = memcacheStub
예제 #3
0
    def setUp(self):
        super(MemcacheResponseCacheTests, self).setUp()

        memcacheStub = InMemoryMemcacheProtocol()
        self.rc = MemcacheResponseCache(None, cachePool=memcacheStub)
        self.tokens = {}

        self.tokens['/calendars/__uids__/cdaboo/'] = 'uriToken0'
        self.tokens['/calendars/__uids__/cdaboo/calendars/'] = 'childToken0'
        self.tokens['/principals/__uids__/cdaboo/'] = 'principalToken0'
        self.tokens['/principals/__uids__/dreid/'] = 'principalTokenX'

        def _getToken(uri, cachePoolHandle=None):
            return succeed(self.tokens.get(uri))

        self.rc._tokenForURI = _getToken

        self.expected_response = (200, Headers({}), "Foo")

        expected_key = hashlib.md5(':'.join([str(t) for t in (
            'PROPFIND',
            '/principals/__uids__/cdaboo/',
            '/calendars/__uids__/cdaboo/',
            '1',
            hash('foobar'),
        )])).hexdigest()

        memcacheStub._cache[expected_key] = (
            0, #flags
            cPickle.dumps((
                'principalToken0',
                StubDirectoryRecord('cdaboo').cacheToken(),
                'uriToken0',
                {'/calendars/__uids__/cdaboo/calendars/': 'childToken0'},
                (
                    self.expected_response[0],
                    dict(list(self.expected_response[1].getAllRawHeaders())),
                    self.expected_response[2]
                )
            ))
        )

        self.memcacheStub = memcacheStub
예제 #4
0
class MemcacheResponseCacheTests(BaseCacheTestMixin, TestCase):
    def setUp(self):
        super(MemcacheResponseCacheTests, self).setUp()

        memcacheStub = InMemoryMemcacheProtocol()
        self.rc = MemcacheResponseCache(None, cachePool=memcacheStub)
        self.tokens = {}

        self.tokens['/calendars/__uids__/cdaboo/'] = 'uriToken0'
        self.tokens['/calendars/__uids__/cdaboo/calendars/'] = 'childToken0'
        self.tokens['/principals/__uids__/cdaboo/'] = 'principalToken0'
        self.tokens['/principals/__uids__/dreid/'] = 'principalTokenX'

        def _getToken(uri, cachePoolHandle=None):
            return succeed(self.tokens.get(uri))

        self.rc._tokenForURI = _getToken

        self.expected_response = (200, Headers({}), "Foo")

        expected_key = hashlib.md5(':'.join([
            str(t) for t in (
                'PROPFIND',
                '/principals/__uids__/cdaboo/',
                '/calendars/__uids__/cdaboo/',
                '1',
                hash('foobar'),
            )
        ])).hexdigest()

        memcacheStub._cache[expected_key] = (
            0,  # flags
            cPickle.dumps(
                ('principalToken0', StubDirectoryRecord('cdaboo').cacheToken(),
                 'uriToken0', {
                     '/calendars/__uids__/cdaboo/calendars/': 'childToken0'
                 }, (self.expected_response[0],
                     dict(list(self.expected_response[1].getAllRawHeaders())),
                     self.expected_response[2]))))

        self.memcacheStub = memcacheStub

    def tearDown(self):
        for call in self.memcacheStub._timeouts.itervalues():
            call.cancel()

    def test_givenURIsForKeys(self):
        expected_response = (200, Headers({}), "Foobarbaz")

        _key = (
            'PROPFIND',
            '/principals/__uids__/cdaboo/',
            '/calendars/users/cdaboo/',
            '1',
            hash('foobar'),
        )

        expected_key = hashlib.md5(':'.join([str(t)
                                             for t in _key])).hexdigest()

        self.memcacheStub._cache[expected_key] = (
            0,  # flags
            cPickle.dumps(
                ('principalToken0', StubDirectoryRecord('cdaboo').cacheToken(),
                 'uriToken0', {
                     '/calendars/__uids__/cdaboo/calendars/': 'childToken0'
                 }, (expected_response[0],
                     dict(list(expected_response[1].getAllRawHeaders())),
                     expected_response[2]))))

        d = self.rc.getResponseForRequest(
            StubRequest('PROPFIND', '/calendars/users/cdaboo/',
                        '/principals/__uids__/cdaboo/'))

        d.addCallback(self.assertResponse, expected_response)
        return d
예제 #5
0
class MemcacheResponseCacheTests(BaseCacheTestMixin, TestCase):
    def setUp(self):
        super(MemcacheResponseCacheTests, self).setUp()

        memcacheStub = InMemoryMemcacheProtocol()
        self.rc = MemcacheResponseCache(None, cachePool=memcacheStub)
        self.tokens = {}

        self.tokens['/calendars/__uids__/cdaboo/'] = 'uriToken0'
        self.tokens['/calendars/__uids__/cdaboo/calendars/'] = 'childToken0'
        self.tokens['/principals/__uids__/cdaboo/'] = 'principalToken0'
        self.tokens['/principals/__uids__/dreid/'] = 'principalTokenX'

        def _getToken(uri, cachePoolHandle=None):
            return succeed(self.tokens.get(uri))

        self.rc._tokenForURI = _getToken

        self.expected_response = (200, Headers({}), "Foo")

        expected_key = hashlib.md5(':'.join([str(t) for t in (
                'PROPFIND',
                '/principals/__uids__/cdaboo/',
                '/calendars/__uids__/cdaboo/',
                '1',
                hash('foobar'),
                )])).hexdigest()

        memcacheStub._cache[expected_key] = (
            0, #flags
            cPickle.dumps((
            'principalToken0',
            StubDirectoryRecord('cdaboo').cacheToken(),
            'uriToken0',
            {'/calendars/__uids__/cdaboo/calendars/': 'childToken0'},
            (self.expected_response[0],
             dict(list(self.expected_response[1].getAllRawHeaders())),
             self.expected_response[2]))))

        self.memcacheStub = memcacheStub


    def tearDown(self):
        for call in self.memcacheStub._timeouts.itervalues():
            call.cancel()


    def test_givenURIsForKeys(self):
        expected_response = (200, Headers({}), "Foobarbaz")

        _key = (
                'PROPFIND',
                '/principals/__uids__/cdaboo/',
                '/calendars/users/cdaboo/',
                '1',
                hash('foobar'),
                )

        expected_key = hashlib.md5(':'.join([str(t) for t in _key])).hexdigest()

        self.memcacheStub._cache[expected_key] = (
            0, #flags
            cPickle.dumps((
                    'principalToken0',
                    StubDirectoryRecord('cdaboo').cacheToken(),
                    'uriToken0',
                    {'/calendars/__uids__/cdaboo/calendars/': 'childToken0'},
                    (expected_response[0],
                     dict(list(expected_response[1].getAllRawHeaders())),
                     expected_response[2]))))

        d = self.rc.getResponseForRequest(
            StubRequest('PROPFIND',
                        '/calendars/users/cdaboo/',
                        '/principals/__uids__/cdaboo/'))

        d.addCallback(self.assertResponse, expected_response)
        return d