Esempio n. 1
0
        public void ChangeCORSRules()
        {
            Constants.ServiceType serviceType = GetRandomServiceType();

            try
            {
                PSCorsRule[] corsRules = CORSRuleUtil.GetRandomValidCORSRules(random.Next(1, 5));
                Test.Assert(CommandAgent.SetAzureStorageCORSRules(serviceType, corsRules),
                            "Set cors rule to {0} service should succeed", serviceType);

                Test.Assert(CommandAgent.GetAzureStorageCORSRules(serviceType),
                            "Get CORS rule of {0} service should succeed.", serviceType);

                PSCorsRule[] newCorsRules = GetCORSRules();

                CORSRuleUtil.ValidateCORSRules(corsRules, newCorsRules);

                foreach (var corsRule in newCorsRules)
                {
                    switch (random.Next(0, 5))
                    {
                    case 0:
                        corsRule.AllowedHeaders = CORSRuleUtil.GetRandomHeaders();
                        break;

                    case 1:
                        corsRule.AllowedMethods = CORSRuleUtil.GetRandomMethods();
                        break;

                    case 2:
                        corsRule.AllowedOrigins = CORSRuleUtil.GetRandomOrigins();
                        break;

                    case 3:
                        corsRule.ExposedHeaders = CORSRuleUtil.GetRandomHeaders();
                        break;

                    case 4:
                        corsRule.MaxAgeInSeconds = random.Next(1, 1000);
                        break;
                    }
                }

                Test.Assert(CommandAgent.SetAzureStorageCORSRules(serviceType, newCorsRules),
                            "Set cors rule to {0} service should succeed", serviceType);

                Test.Assert(CommandAgent.GetAzureStorageCORSRules(serviceType),
                            "Set cors rule of {0} service should succeed", serviceType);

                PSCorsRule[] actualCORSRules = GetCORSRules();

                CORSRuleUtil.ValidateCORSRules(newCorsRules, actualCORSRules);
            }
            finally
            {
                ClearCorsRules(serviceType);
            }
        }
Esempio n. 2
0
        private void ValidateCORSRuleSetGet(PSCorsRule[] corsRules)
        {
            Constants.ServiceType serviceType = GetRandomServiceType();

            try
            {
                Test.Assert(CommandAgent.SetAzureStorageCORSRules(serviceType, corsRules), "Set cors rule  to {0} service should succeed", serviceType);

                Test.Assert(CommandAgent.GetAzureStorageCORSRules(serviceType), "Get CORS rules of {0} service should succeed", serviceType);

                CORSRuleUtil.ValidateCORSRules(corsRules, GetCORSRules());
            }
            finally
            {
                ClearCorsRules(serviceType);
            }
        }
Esempio n. 3
0
        private void OverwriteCORSRules(Action <Constants.ServiceType> setCORSRules, Constants.ServiceType serviceType)
        {
            try
            {
                setCORSRules(serviceType);

                PSCorsRule[] newCorsRules = CORSRuleUtil.GetRandomValidCORSRules(random.Next(1, 5));

                Test.Assert(CommandAgent.SetAzureStorageCORSRules(serviceType, newCorsRules),
                            "Set cors rule to blob service should succeed");

                Test.Assert(CommandAgent.GetAzureStorageCORSRules(serviceType),
                            "Get cors rules of blob service should succeed.");

                PSCorsRule[] acturalRules = GetCORSRules();

                CORSRuleUtil.ValidateCORSRules(newCorsRules, acturalRules);
            }
            finally
            {
                ClearCorsRules(serviceType);
            }
        }
Esempio n. 4
0
        public void GetServiceProperties_AllService_AllProperties()
        {
            //prepare the service properties to set and get
            PSCorsRule[] corsRules = CORSRuleUtil.GetRandomValidCORSRules(random.Next(1, 5));

            Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties serviceProperties = new Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties();
            serviceProperties.Clean();
            serviceProperties.Cors = new CorsProperties();

            foreach (var rule in corsRules)
            {
                CorsRule corsRule = new CorsRule()
                {
                    AllowedHeaders  = rule.AllowedHeaders,
                    AllowedOrigins  = rule.AllowedOrigins,
                    ExposedHeaders  = rule.ExposedHeaders,
                    MaxAgeInSeconds = rule.MaxAgeInSeconds,
                };
                SetAllowedMethods(corsRule, rule.AllowedMethods);
                serviceProperties.Cors.CorsRules.Add(corsRule);
            }
            serviceProperties.HourMetrics = new MetricsProperties("1.0");
            serviceProperties.HourMetrics.MetricsLevel    = MetricsLevel.ServiceAndApi;
            serviceProperties.HourMetrics.RetentionDays   = 1;
            serviceProperties.MinuteMetrics               = new MetricsProperties("1.0");
            serviceProperties.MinuteMetrics.MetricsLevel  = MetricsLevel.Service;
            serviceProperties.MinuteMetrics.RetentionDays = 3;

            serviceProperties.Logging = new LoggingProperties("1.0");
            serviceProperties.Logging.LoggingOperations = LoggingOperations.All;
            serviceProperties.Logging.RetentionDays     = 5;


            foreach (string servicetype in ValidServiceType)
            {
                Constants.ServiceType service = Constants.ServiceType.Blob;
                Enum.TryParse <Constants.ServiceType>(servicetype, true, out service);
                if (service == Constants.ServiceType.Blob) //only Blob support default service version
                {
                    serviceProperties.DefaultServiceVersion = "2017-04-17";

                    serviceProperties.DeleteRetentionPolicy               = new DeleteRetentionPolicy();
                    serviceProperties.DeleteRetentionPolicy.Enabled       = true;
                    serviceProperties.DeleteRetentionPolicy.RetentionDays = 10;
                }

                //Set Service Properties with XSCL API
                ServiceCORSRule.SetSerivceProperties(service, serviceProperties);

                //Get Service Properties with PowerShell
                PSSeriviceProperties properties = GetServicePropertiesFromPSH(service);

                //Validate Cors, metric, logging
                CORSRuleUtil.ValidateCORSRules(corsRules, properties.Cors);

                if (service != Constants.ServiceType.File) // File service don't support logging
                {
                    ExpectEqual(serviceProperties.Logging.Version, properties.Logging.Version, "Logging version");
                    ExpectEqual(serviceProperties.Logging.LoggingOperations.ToString(), properties.Logging.LoggingOperations.ToString(), "Logging Operations");
                    ExpectEqual(serviceProperties.Logging.RetentionDays.Value, properties.Logging.RetentionDays.Value, "Logging RetentionDays");
                }

                ExpectEqual(serviceProperties.HourMetrics.Version, properties.HourMetrics.Version, "HourMetrics Version");
                ExpectEqual(serviceProperties.HourMetrics.MetricsLevel.ToString(), properties.HourMetrics.MetricsLevel.ToString(), "HourMetrics MetricsLevel");
                ExpectEqual(serviceProperties.HourMetrics.RetentionDays.Value, properties.HourMetrics.RetentionDays.Value, "HourMetrics RetentionDays");

                ExpectEqual(serviceProperties.MinuteMetrics.Version, properties.MinuteMetrics.Version, "MinuteMetrics Version");
                ExpectEqual(serviceProperties.MinuteMetrics.MetricsLevel.ToString(), properties.MinuteMetrics.MetricsLevel.ToString(), "MinuteMetrics MetricsLevel");
                ExpectEqual(serviceProperties.MinuteMetrics.RetentionDays.Value, properties.MinuteMetrics.RetentionDays.Value, "MinuteMetrics RetentionDays");


                if (service == Constants.ServiceType.Blob)
                {
                    ExpectEqual(serviceProperties.DefaultServiceVersion, properties.DefaultServiceVersion, "DefaultServiceVersion");

                    ExpectEqual(serviceProperties.DeleteRetentionPolicy.Enabled.ToString(), properties.DeleteRetentionPolicy.Enabled.ToString(), "DeleteRetentionPolicy Enabled");
                    ExpectEqual(serviceProperties.DeleteRetentionPolicy.RetentionDays.Value, properties.DeleteRetentionPolicy.RetentionDays.Value, "DeleteRetentionPolicy RetentionDays");

                    serviceProperties.DeleteRetentionPolicy = null;
                    serviceProperties.DefaultServiceVersion = null;
                }
            }
        }