コード例 #1
0
        /// <summary>
        /// 添加一条CORSRule。
        /// </summary>
        /// <param name="corsRule"></param>
        public void AddCORSRule(CORSRule corsRule)
        {
            if (corsRule == null)
                throw new ArgumentException("corsRule should not be null or empty");

            if (_corsRules.Count >= OssUtils.BucketCorsRuleLimit)
                throw new ArgumentException("One bucket not allow exceed ten item of CORSRules.");

            if (corsRule.AllowedOrigins.Count == 0)
                throw new ArgumentException("corsRule.AllowedOrigins should not be empty");

            if (corsRule.AllowedMethods.Count == 0)
                throw new ArgumentException("corsRule.AllowedMethods should not be empty.");

            _corsRules.Add(corsRule);
        }
コード例 #2
0
 public void EnableBucketCorsAddInvalidSingleRuleTest()
 {
     try
     {
         var sbcRequest = new SetBucketCorsRequest(_bucketName);
         var rule = new CORSRule();
         rule.AddAllowedOrigin("Original " + Guid.NewGuid());
         rule.AddAllowedMethod("GETGET");
         sbcRequest.AddCORSRule(rule);
         _ossClient.SetBucketCors(sbcRequest);
         Assert.Fail("Invalid Cors Rule should not be created successfully");
     }
     catch (ArgumentException)
     {
         Assert.IsTrue(true);
     }
     finally
     {
         _ossClient.DeleteBucketCors(_bucketName);
     }
 }
コード例 #3
0
        /// <summary>
        /// 添加一条CORSRule。
        /// </summary>
        /// <param name="corsRule"></param>
        public void AddCORSRule(CORSRule corsRule)
        {
            if (corsRule == null)
            {
                throw new ArgumentException("corsRule should not be null or empty");
            }

            if (_corsRules.Count >= OssUtils.BucketCorsRuleLimit)
            {
                throw new ArgumentException("One bucket not allow exceed ten item of CORSRules.");
            }

            if (corsRule.AllowedOrigins.Count == 0)
            {
                throw new ArgumentException("corsRule.AllowedOrigins should not be empty");
            }

            if (corsRule.AllowedMethods.Count == 0)
            {
                throw new ArgumentException("corsRule.AllowedMethods should not be empty.");
            }

            _corsRules.Add(corsRule);
        }
コード例 #4
0
 public void EnableBucketCorsEmptyTest()
 {
     var sbcRequest = new SetBucketCorsRequest(_bucketName);
     var newRole = new CORSRule();
     try
     {
         sbcRequest.AddCORSRule(newRole);
         Assert.Fail("Add corsrule without any settings should not pass");
     }
     catch (ArgumentException)
     {
         Assert.IsTrue(true);
     }
 }
コード例 #5
0
 private static CORSRule ConstructDummyCorsRule()
 {
     var rule = new CORSRule();
     rule.AddAllowedOrigin("Original " + Guid.NewGuid());
     rule.AddAllowedMethod("GET");
     rule.AddAllowedHeader("HTTP");
     rule.AddExposeHeader("HTTP");
     return rule;
 }