protected override ICollection <ApiSecret> GetCollection(ProtectResource api)
 {
     if (api.Secrets == null)
     {
         api.Secrets = new List <ApiSecret>();
     }
     return(api.Secrets);
 }
 protected override ICollection <ApiClaim> GetCollection(ProtectResource api)
 {
     if (api.ApiClaims == null)
     {
         api.ApiClaims = new List <ApiClaim>();
     }
     return(api.ApiClaims);
 }
 protected override ICollection <ApiLocalizedResource> GetCollection(ProtectResource api)
 {
     if (api.Resources == null)
     {
         api.Resources = new List <ApiLocalizedResource>();
     }
     return(api.Resources);
 }
 public ApiPropertyValidator(ProtectResource api)
 {
     RuleFor(m => m.Key).NotEmpty().WithMessage("The api property key is required.");
     RuleFor(m => m.Key).MaximumLength(250).WithMessage("The api property key cannot exceed 250 chars.");
     RuleFor(m => m.Key).IsUnique(api.Properties).WithMessage("The api property key must be unique.");
     RuleFor(m => m.Value).NotEmpty().WithMessage("The api property value is required.");
     RuleFor(m => m.Value).MaximumLength(2000).WithMessage("The api property value cannot exceed 2000 chars.");
 }
 protected override ICollection <ApiProperty> GetCollection(ProtectResource api)
 {
     if (api.Properties == null)
     {
         api.Properties = new List <ApiProperty>();
     }
     return(api.Properties);
 }
示例#6
0
 public ApiScopeValidator(ProtectResource api)
 {
     RuleFor(m => m.DisplayName).NotEmpty().WithMessage("The api scope display name is required.");
     RuleFor(m => m.DisplayName).MaximumLength(200).WithMessage("The api scope display name cannot exceed 200 chars.");
     RuleFor(m => m.Description).MaximumLength(2000).WithMessage("The api scope description cannot exceed 2000 chars.");
     RuleFor(m => m.Scope).NotEmpty().WithMessage("The scope is required.");
     RuleForEach(m => m.ApiScopeClaims)
     .Where(m => m.Type != null)
     .SetValidator(m => new ApiScopeClaimValidator(m));
 }
示例#7
0
        public async Task DeleteAsync_should_remove_entity_id_from_parent()
        {
            using var store = new RavenDbTestDriverWrapper().GetDocumentStore();

            var entity = new TEntity
            {
                Id    = Guid.NewGuid().ToString(),
                ApiId = "test"
            };
            var api = new ProtectResource
            {
                Id = "test",
            };
            var collection = GetCollection(api);

            collection.Add(new TEntity
            {
                Id = $"{typeof(TEntity).Name.ToLowerInvariant()}/{entity.Id}"
            });

            using var s1 = store.OpenAsyncSession();
            await s1.StoreAsync(api, $"{nameof(ProtectResource).ToLowerInvariant()}/{api.Id}");

            await s1.StoreAsync(entity, $"{typeof(TEntity).Name.ToLowerInvariant()}/{entity.Id}");

            await s1.SaveChangesAsync();

            var loggerMock = new Mock <ILogger <AdminStore <TEntity> > >();

            using var session = store.OpenAsyncSession();

            var sut = CreateSut(session, loggerMock.Object);


            await sut.DeleteAsync(entity.Id);

            using var s2 = store.OpenAsyncSession();
            var updated = await s2.LoadAsync <ProtectResource>($"{nameof(ProtectResource).ToLowerInvariant()}/test");

            var updatedCollection = GetCollection(updated);

            Assert.DoesNotContain(updatedCollection, i => i.Id == $"{typeof(TEntity).Name.ToLowerInvariant()}/{entity.Id}");
        }
示例#8
0
 public ApiClaimValidator(ProtectResource api, IStringLocalizer localizer)
 {
     RuleFor(m => m.Type).NotEmpty().WithMessage(localizer["The claim type is required."]);
     RuleFor(m => m.Type).MaximumLength(250).WithMessage(localizer["The claim type cannot exceed 2000 chars."]);
     RuleFor(m => m.Type).IsUnique(api.ApiClaims).WithMessage(localizer["The claim type must be unique."]);
 }
示例#9
0
 protected abstract ICollection <TEntity> GetCollection(ProtectResource api);
 public ApiSecretValidator(ProtectResource api, IStringLocalizer localizer)
 {
     RuleFor(m => m.Type).NotEmpty().WithMessage(localizer["The secret type is required."]);
     RuleFor(m => m.Value).NotEmpty().WithMessage(localizer["The secret value is required."]);
 }
示例#11
0
 public ApiSecretValidator(ProtectResource api)
 {
     RuleFor(m => m.Type).NotEmpty().WithMessage("The secret type is required.");
     RuleFor(m => m.Value).NotEmpty().WithMessage("The secret value is required.");
 }