/// <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); }
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); } }
/// <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); }
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); } }
private static CORSRule ConstructDummyCorsRule() { var rule = new CORSRule(); rule.AddAllowedOrigin("Original " + Guid.NewGuid()); rule.AddAllowedMethod("GET"); rule.AddAllowedHeader("HTTP"); rule.AddExposeHeader("HTTP"); return rule; }