def get_validated_tenant(self): """ returns a validated tenant object from cache or from coordinator """ token_cache = TokenCache() tenant_cache = TenantCache() #check if the token is in the cache token = token_cache.get_token(self.tenant_id) if token: #validate token if not token.validate_token(self.message_token): raise errors.MessageAuthenticationError( 'Message not authenticated, check your tenant id ' 'and or message token for validity') #get the tenant object from cache tenant = tenant_cache.get_tenant(self.tenant_id) #if tenant is not in cache, ask the coordinator if not tenant: tenant = self._get_tenant_from_coordinator() token_cache.set_token(self.tenant_id, tenant.token) tenant_cache.set_tenant(tenant) else: self._validate_token_with_coordinator() #get tenant from coordinator tenant = self._get_tenant_from_coordinator() token_cache.set_token(self.tenant_id, tenant.token) tenant_cache.set_tenant(tenant) return tenant
def test_set_token_calls_cache_set(self): with patch.object( NativeProxy, 'cache_exists', self.cache_false ), patch.object(NativeProxy, 'cache_set', self.cache_set): token_cache = TokenCache() token_cache.set_token(self.tenant_id, self.token) self.cache_set.assert_called_once_with( self.tenant_id, jsonutils.dumps(self.token.format()), DEFAULT_EXPIRES, CACHE_TOKEN)
def test_set_token_calls_cache_set(self): with patch.object(NativeProxy, 'cache_exists', self.cache_false), patch.object( NativeProxy, 'cache_set', self.cache_set): token_cache = TokenCache() token_cache.set_token(self.tenant_id, self.token) self.cache_set.assert_called_once_with( self.tenant_id, jsonutils.dumps(self.token.format()), DEFAULT_EXPIRES, CACHE_TOKEN)