public ValidateOptionsResult Validate(string name, MicrosoftIdentityOptions options)
        {
            if (string.IsNullOrEmpty(options.ClientId))
            {
                return(ValidateOptionsResult.Fail(string.Format(CultureInfo.InvariantCulture, IDWebErrorMessage.ConfigurationOptionRequired, nameof(options.ClientId))));
            }

            if (string.IsNullOrEmpty(options.Instance))
            {
                return(ValidateOptionsResult.Fail(string.Format(CultureInfo.InvariantCulture, IDWebErrorMessage.ConfigurationOptionRequired, nameof(options.Instance))));
            }

            if (options.IsB2C)
            {
                if (string.IsNullOrEmpty(options.Domain))
                {
                    return(ValidateOptionsResult.Fail(string.Format(CultureInfo.InvariantCulture, IDWebErrorMessage.ConfigurationOptionRequired, nameof(options.Domain))));
                }
            }
            else
            {
                if (string.IsNullOrEmpty(options.TenantId))
                {
                    return(ValidateOptionsResult.Fail(string.Format(CultureInfo.InvariantCulture, IDWebErrorMessage.ConfigurationOptionRequired, nameof(options.TenantId))));
                }
            }

            return(ValidateOptionsResult.Success);
        }
    /// <inheritdoc />
    public ValidateOptionsResult Validate(string name, UnattendedSettings options)
    {
        if (options.InstallUnattended)
        {
            var setValues = 0;
            if (!string.IsNullOrEmpty(options.UnattendedUserName))
            {
                setValues++;
            }

            if (!string.IsNullOrEmpty(options.UnattendedUserEmail))
            {
                setValues++;
            }

            if (!string.IsNullOrEmpty(options.UnattendedUserPassword))
            {
                setValues++;
            }

            if (setValues > 0 && setValues < 3)
            {
                return(ValidateOptionsResult.Fail(
                           $"Configuration entry {Constants.Configuration.ConfigUnattended} contains invalid values.\nIf any of the {nameof(options.UnattendedUserName)}, {nameof(options.UnattendedUserEmail)}, {nameof(options.UnattendedUserPassword)} are set, all of them are required."));
            }
        }

        return(ValidateOptionsResult.Success);
    }
        public ValidateOptionsResult Validate(string name, MicrosoftIdentityOptions options)
        {
            if (string.IsNullOrEmpty(options.ClientId))
            {
                return(ValidateOptionsResult.Fail($"The '{nameof(options.ClientId)}' option must be provided."));
            }

            if (string.IsNullOrEmpty(options.Instance))
            {
                return(ValidateOptionsResult.Fail($"The '{nameof(options.Instance)}' option must be provided."));
            }

            if (options.IsB2C)
            {
                if (string.IsNullOrEmpty(options.Domain))
                {
                    return(ValidateOptionsResult.Fail($"The '{nameof(options.Domain)}' option must be provided."));
                }
            }
            else
            {
                if (string.IsNullOrEmpty(options.TenantId))
                {
                    return(ValidateOptionsResult.Fail($"The '{nameof(options.TenantId)}' option must be provided."));
                }
            }

            return(ValidateOptionsResult.Success);
        }
        public ValidateOptionsResult Validate(IFido2Configuration configuration, bool isDevEnvironment)
        {
            // Validate Fido2Url
            if (configuration.IsEnabled && !OwnIdCoreConfigurationValidator.IsUriValid(
                    nameof(configuration.PasswordlessPageUrl),
                    configuration.PasswordlessPageUrl, isDevEnvironment, out var error))
            {
                return(ValidateOptionsResult.Fail(error));
            }

            // Validate Origin
            if (configuration.IsEnabled && !OwnIdCoreConfigurationValidator.IsUriValid(
                    nameof(configuration.Origin),
                    configuration.Origin, isDevEnvironment, out var errorOrigin))
            {
                return(ValidateOptionsResult.Fail(errorOrigin));
            }

            // Validate RelyingPartyId
            if (configuration.IsEnabled && string.IsNullOrEmpty(configuration.RelyingPartyId))
            {
                return(ValidateOptionsResult.Fail($"{nameof(configuration.RelyingPartyId)} is required"));
            }

            // Validate UserName
            if (configuration.IsEnabled && string.IsNullOrEmpty(configuration.UserName))
            {
                return(ValidateOptionsResult.Fail($"{nameof(configuration.UserName)} is required"));
            }

            return(ValidateOptionsResult.Success);
        }
        public void ValidateRequiredMicrosoftIdentityOptions(
            string clientId,
            string instance,
            string tenantid,
            string signUpSignInPolicyId,
            string domain,
            string optionsName,
            MissingParam missingParam = MissingParam.None)
        {
            _microsoftIdentityOptions = new MicrosoftIdentityOptions
            {
                ClientId = clientId,
                Instance = instance,
                TenantId = tenantid,
            };

            if (optionsName == AzureAdB2C)
            {
                _microsoftIdentityOptions.SignUpSignInPolicyId = signUpSignInPolicyId;
                _microsoftIdentityOptions.Domain = domain;
            }

            MicrosoftIdentityOptionsValidation microsoftIdentityOptionsValidation = new MicrosoftIdentityOptionsValidation();
            ValidateOptionsResult result = microsoftIdentityOptionsValidation.Validate(optionsName, _microsoftIdentityOptions);

            CheckReturnValueAgainstExpectedMissingParam(missingParam, result);
        }
Esempio n. 6
0
        public ValidateOptionsResult Validate(string name, ObservedVoiceChannelOptions options)
        {
            IList <string> validationFailures = new List <string>();

            if (string.IsNullOrEmpty(options.MutedEmoji))
            {
                validationFailures.Add($"{nameof(options.MutedEmoji)} is required.");
            }

            if (string.IsNullOrEmpty(options.UnMutedEmoji))
            {
                validationFailures.Add($"{nameof(options.UnMutedEmoji)} is required.");
            }

            if (validationFailures.Any())
            {
                string validationFailureErrorMessage = string.Join(Environment.NewLine, validationFailures);

                _logger.LogError(validationFailureErrorMessage);

                return(ValidateOptionsResult.Fail(validationFailures));
            }

            return(ValidateOptionsResult.Success);
        }
        public ValidateOptionsResult Validate(string name, CloudConfiguration options)
        {
            if (options == null)
            {
                return(ValidateOptionsResult.Fail($"Object {nameof(options)} may not be null"));
            }

            if (string.IsNullOrEmpty(options.EventHubSenderConnectionString))
            {
                return(ValidateOptionsResult.Fail(
                           $"Missing configuration setting for {CloudConfiguration.SectionName}:{nameof(options.EventHubSenderConnectionString)}"));
            }
            if (string.IsNullOrEmpty(options.EventHubListenerConnectionString))
            {
                return(ValidateOptionsResult.Fail(
                           $"Missing configuration setting for {CloudConfiguration.SectionName}:{nameof(options.EventHubListenerConnectionString)}"));
            }
            if (string.IsNullOrEmpty(options.StorageConnectionString))
            {
                return(ValidateOptionsResult.Fail(
                           $"Missing configuration setting for {CloudConfiguration.SectionName}:{nameof(options.StorageConnectionString)}"));
            }
            if (string.IsNullOrEmpty(options.RedisCacheConnectionString))
            {
                return(ValidateOptionsResult.Fail(
                           $"Missing configuration setting for {CloudConfiguration.SectionName}:{nameof(options.RedisCacheConnectionString)}"));
            }

            return(ValidateOptionsResult.Success);
        }
        public ValidateOptionsResult Validate(string name, SmtpConfiguration options)
        {
            if (options == null)
            {
                return(ValidateOptionsResult.Fail("The Smtp configuration must be defined."));
            }

            if (options.Host.IsNullOrEmpty())
            {
                return(ValidateOptionsResult.Fail("The Host must be defined."));
            }

            if (options.Port < 0)
            {
                return(ValidateOptionsResult.Fail("The Port must be defined and great than 0."));
            }

            //if (options.UseSsl)
            //{
            //    return ValidateOptionsResult.Fail("The UseSsl must be defined.");
            //}

            if (options.UserName.IsNullOrEmpty())
            {
                return(ValidateOptionsResult.Fail("The UserName must be defined."));
            }

            if (options.Password.IsNullOrEmpty())
            {
                return(ValidateOptionsResult.Fail("The Password must be defined."));
            }

            return(ValidateOptionsResult.Success);
        }
Esempio n. 9
0
        public static bool TryValidateOptions(Type optionsType, object options, ValidationContext validationContext, ICollection <ValidationResult> results)
        {
            RequiredAttribute requiredAttribute = new();
            ValidationResult  requiredResult    = requiredAttribute.GetValidationResult(options, validationContext);

            if (requiredResult == ValidationResult.Success)
            {
                Type       validateOptionsType = typeof(IValidateOptions <>).MakeGenericType(optionsType);
                MethodInfo validateMethod      = validateOptionsType.GetMethod(nameof(IValidateOptions <object> .Validate));

                bool hasFailedResults = false;
                IEnumerable <object> validateOptionsImpls = validationContext.GetServices(validateOptionsType);
                foreach (object validateOptionsImpl in validateOptionsImpls)
                {
                    ValidateOptionsResult validateResult = (ValidateOptionsResult)validateMethod.Invoke(validateOptionsImpl, new object[] { null, options });
                    if (validateResult.Failed)
                    {
                        foreach (string failure in validateResult.Failures)
                        {
                            results.Add(new ValidationResult(failure));
                            hasFailedResults = true;
                        }
                    }
                }

                return(hasFailedResults);
            }
            else
            {
                results.Add(requiredResult);
                return(false);
            }
        }
        public ValidateOptionsResult Validate(string name, ExternalServicesConfig options)
        {
            switch (name)
            {
            case ExternalServicesConfig.WeatherApi:
                var result = ValidateWeatherApiConfig(_weatherConfig.EnableWeatherForecast, options);
                if (result.Failed)
                {
                    return(result);
                }
                break;

            case ExternalServicesConfig.ProductsApi:
                if (string.IsNullOrEmpty(options.Url))
                {
                    return(ValidateOptionsResult.Fail("A URL for the product API is required."));
                }
                if (options.MinsToCache < 1)
                {
                    return(ValidateOptionsResult.Fail("The products caching must be at least 1 minute."));
                }
                break;

            default:
                return(ValidateOptionsResult.Skip);
            }

            return(ValidateOptionsResult.Success);
        }
Esempio n. 11
0
        public ValidateOptionsResult Validate(string name, CosmosDbConfiguration options)
        {
            if (string.IsNullOrEmpty(options.ConnectionString))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.ConnectionString)} configuration parameter for the Azure Cosmos DB is required"));
            }

            if (string.IsNullOrEmpty(options.CarContainerName))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.CarContainerName)} configuration parameter for the Azure Cosmos DB is required"));
            }

            if (string.IsNullOrEmpty(options.EnquiryContainerName))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.EnquiryContainerName)} configuration parameter for the Azure Cosmos DB is required"));
            }

            if (string.IsNullOrEmpty(options.DatabaseName))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.DatabaseName)} configuration parameter for the Azure Cosmos DB is required"));
            }

            if (string.IsNullOrEmpty(options.PartitionKeyPath))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.PartitionKeyPath)} configuration parameter for the Azure Cosmos DB is required"));
            }

            return(ValidateOptionsResult.Success);
        }
        public ValidateOptionsResult Validate(string name, SlackOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.VerificationToken))
            {
                return(ValidateOptionsResult.Fail("Slack VerificationToken is missing"));
            }

            // Validate oauth
            if (options.OAuth != null)
            {
                var oauth = options.OAuth;

                if (string.IsNullOrWhiteSpace(oauth.ClientId))
                {
                    return(ValidateOptionsResult.Fail("Slack ClientId is missing"));
                }

                if (string.IsNullOrWhiteSpace(oauth.ClientSecret))
                {
                    return(ValidateOptionsResult.Fail("Slack ClientSecret is missing"));
                }

                if (string.IsNullOrWhiteSpace(oauth.RedirectUri))
                {
                    return(ValidateOptionsResult.Fail("Slack RedirectUri is missing"));
                }
            }

            return(ValidateOptionsResult.Success);
        }
 public ValidateOptionsResult Validate(string name, FinastraConfiguration options)
 {
     if (string.IsNullOrEmpty(options.ApiConfiguration.BaseUrl))
     {
         return(ValidateOptionsResult.Fail("BaseUrl empty"));
     }
     if (string.IsNullOrEmpty(options.Oauth2Configuration.TokenEndpoint))
     {
         return(ValidateOptionsResult.Fail("TokenEndpoint empty"));
     }
     if (string.IsNullOrEmpty(options.Oauth2Configuration.B2B.ClientId))
     {
         return(ValidateOptionsResult.Fail("ClientId empty"));
     }
     if (string.IsNullOrEmpty(options.Oauth2Configuration.B2B.PrivateKey))
     {
         return(ValidateOptionsResult.Fail("PrivateKey empty"));
     }
     if (string.IsNullOrEmpty(options.Oauth2Configuration.B2B.JwkKeyId))
     {
         return(ValidateOptionsResult.Fail("JwkKeyId empty"));
     }
     //etc...
     return(ValidateOptionsResult.Success);
 }
        public ValidateOptionsResult Validate(
            string name,
            UnmonitoredButValidatedSettings settings
            )
        {
            var sectionName = typeof(UnmonitoredButValidatedSettings).GetCustomAttribute <SettingsSectionNameAttribute>()?.SectionName
                              ?? throw new ArgumentNullException(nameof(SettingsSectionNameAttribute));

            if (settings is null)
            {
                return(ValidateOptionsResult.Fail($"Configuration object is null for section '{sectionName}'."));
            }

            var failureMessages = new List <string>();

            if (string.IsNullOrWhiteSpace(settings.OptionA))
            {
                failureMessages.Add($"{sectionName}.{nameof(settings.OptionA)} is required.");
            }

            if (string.IsNullOrWhiteSpace(settings.OptionB))
            {
                failureMessages.Add($"{sectionName}.{nameof(settings.OptionB)} is required.");
            }

            if (string.IsNullOrWhiteSpace(settings.OptionC))
            {
                failureMessages.Add($"{sectionName}.{nameof(settings.OptionC)} is required.");
            }

            return(failureMessages.Any()
                ? ValidateOptionsResult.Fail(failureMessages)
                : ValidateOptionsResult.Success);
        }
 private static void ThrowValidateException <TOptions>(
     ValidateOptionsResult result,
     string sectionName)
     where TOptions : class, new()
 {
     throw new OptionsValidationException(result.FailureMessage, (typeof(TOptions), sectionName));
 }
        public ValidateOptionsResult Validate(string name, BotOptions options)
        {
            IList <string> validationFailures = new List <string>();

            if (string.IsNullOrEmpty(options.Token))
            {
                validationFailures.Add($"{nameof(options.Token)} is required.");
            }

            if (options.MessageCacheSize == 0)
            {
                validationFailures.Add($"{nameof(options.MessageCacheSize)} must be greater than 0.");
            }

            if (validationFailures.Any())
            {
                string validationFailureErrorMessage = string.Join(Environment.NewLine, validationFailures);

                _logger.LogError(validationFailureErrorMessage);

                return(ValidateOptionsResult.Fail(validationFailures));
            }

            return(ValidateOptionsResult.Success);
        }
Esempio n. 17
0
        public ValidateOptionsResult Validate(string name, TOptions options)
        {
            if (Name != null && name != Name)
            {
                return(ValidateOptionsResult.Skip);
            }

            var validationResults = new List <ValidationResult>();

            if (_recursiveDataAnnotationValidator.TryValidateObjectRecursive(
                    options,
                    new ValidationContext(options, serviceProvider: null, items: null),
                    validationResults
                    ))
            {
                return(ValidateOptionsResult.Success);
            }

            var errors = validationResults
                         .Select(r =>
                                 $"Validation failed for members: '{string.Join(",", r.MemberNames)}' with the error: '{r.ErrorMessage}'."
                                 )
                         .ToList();

            return(ValidateOptionsResult.Fail(errors));
        }
Esempio n. 18
0
        /// <summary>
        /// Validates configuration.
        /// </summary>
        public ValidateOptionsResult Validate(string name, KafkaOutboxSenderOptions options)
        {
            if (options is null)
            {
                return(ValidateOptionsResult.Fail("Configuration object is null."));
            }

            if (options.TopicName is null)
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.TopicName)} is not set."));
            }

            if (string.IsNullOrWhiteSpace(options.TopicName))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.TopicName)} cannot be empty or consist of whitespaces."));
            }

            if (options.TopicName.Any(character => char.IsWhiteSpace(character)))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.TopicName)} cannot contain whitespaces."));
            }

            if (options.TopicName.Length > MAX_TOPIC_NAME_LENGTH)
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.TopicName)} name is too long."));
            }

            if (!_topicNameCharacters.IsMatch(options.TopicName))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.TopicName)} may consist of characters 'a' to 'z', 'A' to 'Z', digits, and minus signs."));
            }

            return(ValidateOptionsResult.Success);
        }
Esempio n. 19
0
        public ValidateOptionsResult Validate(string name, AzureAdGraphConfiguration options)
        {
            if (string.IsNullOrEmpty(options.ApiUrl))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.ApiUrl)} configuration parameter for the Azure Ad Graph is required"));
            }

            if (string.IsNullOrEmpty(options.ApiVersion))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.ApiVersion)} configuration parameter for the Azure Ad Graph is required"));
            }

            if (string.IsNullOrEmpty(options.AzureAdB2CTenant))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.AzureAdB2CTenant)} configuration parameter for the Azure Ad Graph is required"));
            }

            if (string.IsNullOrEmpty(options.ClientId))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.ClientId)} configuration parameter for the Azure Ad Graph is required"));
            }

            if (string.IsNullOrEmpty(options.ClientSecret))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.ClientSecret)} configuration parameter for the Azure Ad Graph is required"));
            }

            if (string.IsNullOrEmpty(options.SignUpSignInPolicyId))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.SignUpSignInPolicyId)} configuration parameter for the Azure Ad Graph is required"));
            }

            return(ValidateOptionsResult.Success);
        }
        public ValidateOptionsResult Validate(string name, AppSettings options)
        {
            var hasURL = options.MinerIdServer != null && !string.IsNullOrEmpty(options.MinerIdServer.Url);

            if (!hasURL && string.IsNullOrWhiteSpace(options.WifPrivateKey)
                ||
                hasURL && !string.IsNullOrWhiteSpace(options.WifPrivateKey)
                )
            {
                return(ValidateOptionsResult.Fail(
                           $"Invalid configuration - either  {nameof(AppSettings.MinerIdServer)} or {nameof(AppSettings.WifPrivateKey)} must be specified."));
            }

            // Explicitly trigger validation of nested objects
            if (options.MinerIdServer != null && !string.IsNullOrEmpty(options.MinerIdServer.Url))
            {
                var validationResults = new List <ValidationResult>();
                var validationContext = new ValidationContext(options.MinerIdServer, serviceProvider: null, items: null);
                if (!Validator.TryValidateObject(options.MinerIdServer, validationContext, validationResults, true))
                {
                    return(ValidateOptionsResult.Fail(string.Join(",", validationResults.Select(x => x.ErrorMessage).ToArray())));
                }
            }
            if (!string.IsNullOrEmpty(options.CallbackIPAddresses))
            {
                foreach (var ipString in options.CallbackIPAddressesArray)
                {
                    string error = $"Invalid configuration -  {nameof(AppSettings.CallbackIPAddresses)}: url { ipString } is invalid.";
                    if (String.IsNullOrWhiteSpace(ipString))
                    {
                        return(ValidateOptionsResult.Fail(error));
                    }
                    string[] splitValues = ipString.Split('.');
                    if (splitValues.Length != 4)
                    {
                        return(ValidateOptionsResult.Fail(error));
                    }
                    if (!splitValues.All(r => byte.TryParse(r, out byte tempForParsing)))
                    {
                        ValidateOptionsResult.Fail(error);
                    }
                }
            }
            if (options.Notification == null)
            {
                return(ValidateOptionsResult.Fail(
                           $"Invalid configuration -  {nameof(AppSettings.Notification)} settings must be specified."));
            }
            else
            {
                var validationResults = new List <ValidationResult>();
                var validationContext = new ValidationContext(options.Notification, serviceProvider: null, items: null);
                if (!Validator.TryValidateObject(options.Notification, validationContext, validationResults, true))
                {
                    return(ValidateOptionsResult.Fail(string.Join(",", validationResults.Select(x => x.ErrorMessage).ToArray())));
                }
            }

            return(ValidateOptionsResult.Success);
        }
Esempio n. 21
0
    public ValidateOptionsResult Validate(string name, GeneralOptions options)
    {
        List <string> failures = new List <string>();

        if (string.IsNullOrWhiteSpace(options.CorrelationIdHeader))
        {
            failures.Add($"{nameof(options.CorrelationIdHeader)} option is not found.");
        }

        if (options.MaxLogFieldLength <= 0)
        {
            failures.Add($"{nameof(options.MaxLogFieldLength)} option is not found.");
        }

        if (options.DefaultPaginationPageSize <= 0)
        {
            failures.Add($"{nameof(options.DefaultPaginationPageSize)} option is not found.");
        }

        if (failures.Count > 0)
        {
            return(ValidateOptionsResult.Fail(failures));
        }
        else
        {
            return(ValidateOptionsResult.Success);
        }
    }
Esempio n. 22
0
        public ValidateOptionsResult Validate(string name, MyConfigOptions options)
        {
            string vor   = null;
            var    rx    = new Regex(@"^[a-zA-Z''-'\s]{1,40}$");
            var    match = rx.Match(options.Key1);

            if (string.IsNullOrEmpty(match.Value))
            {
                vor = $"{options.Key1} doesn't match RegEx \n";
            }

            if (options.Key2 < 0 || options.Key2 > 1000)
            {
                vor = $"{options.Key2} doesn't match Range 0 - 1000 \n";
            }

            if (_config.Key2 != default)
            {
                if (_config.Key3 <= _config.Key2)
                {
                    vor += "Key3 must be > than Key2.";
                }
            }

            if (vor != null)
            {
                return(ValidateOptionsResult.Fail(vor));
            }

            return(ValidateOptionsResult.Success);
        }
Esempio n. 23
0
        public ValidateOptionsResult Validate()
        {
            if (!ProfileModelType.IsClass || ProfileModelType.IsAbstract || ProfileModelType.IsGenericType)
            {
                return(ValidateOptionsResult.Fail(
                           $"Profile model type '{ProfileModelType.FullName}' must be non-abstract, non-generic class"));
            }

            var props = ProfileModelType.GetProperties();

            if (props.Length == 0)
            {
                return(ValidateOptionsResult.Fail(
                           $"Profile model type '{ProfileModelType.FullName}' must contain at least one public property with read/write access"));
            }


            var propertiesCount = 0;

            foreach (var propertyInfo in props)
            {
                if (propertyInfo.DeclaringType != null && (propertyInfo.PropertyType.IsPrimitive ||
                                                           propertyInfo.PropertyType == typeof(string) ||
                                                           propertyInfo.PropertyType == typeof(DateTime)))
                {
                    if (!propertyInfo.CanWrite)
                    {
                        Console.Out.WriteLine($"{propertyInfo.Name} has no setter method and will be skipped");
                    }
                    else
                    {
                        propertiesCount++;
                    }

                    continue;
                }

                if (propertyInfo.GetCustomAttributes <OwnIdFieldAttribute>().Any())
                {
                    return(ValidateOptionsResult.Fail($"{propertyInfo.Name} has unsupported type"));
                }

                Console.Out.WriteLine($"{propertyInfo.Name} has unsupported type and will be skipped");
            }

            if (propertiesCount == 0)
            {
                return(ValidateOptionsResult.Fail(
                           $"Profile model type '{ProfileModelType.FullName}' must have at least one property with setter"));
            }

            if (propertiesCount > 50)
            {
                return(ValidateOptionsResult.Fail(
                           $"Profile model type '{ProfileModelType.FullName}' must contain no more than 50 public properties with read/write access. It contain {propertiesCount}"));
            }

            return(ValidateOptionsResult.Success);
        }
Esempio n. 24
0
        public ValidateOptionsResult Validate(string name, OwnIdCoreConfiguration options)
        {
            if (!IsUriValid(nameof(options.CallbackUrl), options.CallbackUrl, options.IsDevEnvironment,
                            out var callBackUrlValidationError))
            {
                return(ValidateOptionsResult.Fail(callBackUrlValidationError));
            }

            if (!IsUriValid(nameof(options.OwnIdApplicationUrl), options.OwnIdApplicationUrl, options.IsDevEnvironment,
                            out var ownIdAppUrlValidationError))
            {
                return(ValidateOptionsResult.Fail(ownIdAppUrlValidationError));
            }

            if (options.JwtSignCredentials == default)
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.JwtSignCredentials)} are required"));
            }

            if (string.IsNullOrWhiteSpace(options.DID) || string.IsNullOrWhiteSpace(options.Name))
            {
                return(ValidateOptionsResult.Fail(
                           $"{nameof(options.DID)} and {nameof(options.Name)} are required"));
            }

            if (options.CacheExpirationTimeout == 0)
            {
                return(ValidateOptionsResult.Fail(
                           $"{nameof(options.CacheExpirationTimeout)} can not be equal to 0"));
            }

            if (options.JwtExpirationTimeout == 0)
            {
                return(ValidateOptionsResult.Fail(
                           $"{nameof(options.JwtExpirationTimeout)} can not be equal to 0"));
            }

            if (string.IsNullOrWhiteSpace(options.TopDomain))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.TopDomain)} is required"));
            }

            // Validate Fido2 configuration
            var fido2Validator        = new Fido2ConfigurationValidator();
            var fido2ValidationResult = fido2Validator.Validate(options.Fido2, options.IsDevEnvironment);

            if (fido2ValidationResult.Failed)
            {
                return(fido2ValidationResult);
            }

            if (!options.Fido2.IsEnabled && options.Fido2FallbackBehavior == Fido2FallbackBehavior.Block)
            {
                return(ValidateOptionsResult.Fail(
                           $"FIDO2 is disabled, but '{nameof(options.Fido2FallbackBehavior)}' is set to '{nameof(Fido2FallbackBehavior.Block)}'"));
            }

            return(options.ProfileConfiguration.Validate());
        }
        public void Returns_Fail_For_Configuration_With_Invalid_AutoFillImageProperties_Collection()
        {
            var                   validator = new ContentSettingsValidator();
            ContentSettings       options   = BuildContentSettings(culture: string.Empty);
            ValidateOptionsResult result    = validator.Validate("settings", options);

            Assert.False(result.Succeeded);
        }
            public ValidateOptionsResult Validate(string name, TOptions options)
            {
                var result = _validator.Validate(options);

                return(result.IsValid
                    ? ValidateOptionsResult.Success
                    : ValidateOptionsResult.Fail(result.Errors.Select(error => error.ErrorMessage)));
            }
 public ValidateOptionsResult Validate(string name, OrderStoreOptions options)
 {
     if (string.IsNullOrEmpty(options.ImportPath))
     {
         return(ValidateOptionsResult.Fail($"Import Path is missing"));
     }
     return(ValidateOptionsResult.Success);
 }
 public ValidateOptionsResult Validate(string name, Options options)
 {
     if (string.IsNullOrEmpty(options.MyImportantProperty))
     {
         return(ValidateOptionsResult.Fail("'MyImportantProperty' is required."));
     }
     return(ValidateOptionsResult.Success);
 }
Esempio n. 29
0
 public ValidateOptionsResult Validate(string name, IdentityClientOption options)
 {
     if (options.GrantType == "password")
     {
         return(ValidateOptionsResult.Success);
     }
     return(ValidateOptionsResult.Fail("验证方式不是password模式"));
 }
        public void Returns_Success_ForValid_Configuration()
        {
            var validator = new GlobalSettingsValidator();
            var options   = new GlobalSettings();
            ValidateOptionsResult result = validator.Validate("settings", options);

            Assert.True(result.Succeeded);
        }