public void GetPermissionNameFormCacheKeyOrNull() { var key = PermissionGrantCacheItem.CalculateCacheKey("aaa", "bbb", "ccc"); PermissionGrantCacheItem.GetPermissionNameFormCacheKeyOrNull(key).ShouldBe("aaa"); PermissionGrantCacheItem.GetPermissionNameFormCacheKeyOrNull("aaabbbccc").ShouldBeNull(); }
public async Task Role_Deleted_Distributed_Event_Test() { var role = await RoleRepository.FindByNormalizedNameAsync(LookupNormalizer.NormalizeName("moderator")); var permissionGrantsInRole = await PermissionGrantRepository.GetListAsync("R", role.Name); var caches = permissionGrantsInRole.Select(x => new KeyValuePair <string, PermissionGrantCacheItem>( PermissionGrantCacheItem.CalculateCacheKey(x.Name, x.ProviderName, x.ProviderKey), new PermissionGrantCacheItem(true))).ToList(); await Cache.SetManyAsync(caches); using (var uow = UowManager.Begin()) { await RoleRepository.DeleteAsync(role); await uow.CompleteAsync(); } var permissionGrantCaches = await Cache.GetManyAsync(caches.Select(x => x.Key)); foreach (var cache in permissionGrantCaches) { cache.Value.ShouldBeNull(); } }
public async Task PermissionStore_IsGrantedAsync_Should_Cache_PermissionGrant() { (await _cache.GetAsync(PermissionGrantCacheItem.CalculateCacheKey("MyPermission1", UserPermissionValueProvider.ProviderName, PermissionTestDataBuilder.User1Id.ToString()))).ShouldBeNull(); await _permissionStore.IsGrantedAsync("MyPermission1", UserPermissionValueProvider.ProviderName, PermissionTestDataBuilder.User1Id.ToString()); (await _cache.GetAsync(PermissionGrantCacheItem.CalculateCacheKey("MyPermission1", UserPermissionValueProvider.ProviderName, PermissionTestDataBuilder.User1Id.ToString()))).ShouldNotBeNull(); }
public virtual async Task <PermissionGrant> UpdateProviderKeyAsync(PermissionGrant permissionGrant, string providerKey) { using (CurrentTenant.Change(permissionGrant.TenantId)) { //Invalidating the cache for the old key await Cache.RemoveAsync( PermissionGrantCacheItem.CalculateCacheKey( permissionGrant.Name, permissionGrant.ProviderName, permissionGrant.ProviderKey ) ); } permissionGrant.ProviderKey = providerKey; return(await PermissionGrantRepository.UpdateAsync(permissionGrant)); }
public async Task Cache_Should_Invalidator_WhenPermissionGrantChanged() { // IsGrantedAsync will cache PermissionGrant await _permissionStore.IsGrantedAsync("MyPermission1", UserPermissionValueProvider.ProviderName, PermissionTestDataBuilder.User1Id.ToString()); var permissionGrant = await _permissionGrantRepository.FindAsync("MyPermission1", UserPermissionValueProvider.ProviderName, PermissionTestDataBuilder.User1Id.ToString()); permissionGrant.ShouldNotBeNull(); await _permissionGrantRepository.DeleteAsync(permissionGrant); (await _cache.GetAsync(PermissionGrantCacheItem.CalculateCacheKey("MyPermission1", UserPermissionValueProvider.ProviderName, PermissionTestDataBuilder.User1Id.ToString()))).ShouldBeNull(); }
protected virtual string CalculateCacheKey(string name, string providerName, string providerKey) { return(PermissionGrantCacheItem.CalculateCacheKey(name, providerName, providerKey)); }