github.com/aliyun/aliyun-oss-go-sdk@v3.0.2+incompatible/oss/type_test.go (about)

     1  package oss
     2  
     3  import (
     4  	"encoding/xml"
     5  	"log"
     6  	"net/url"
     7  	"sort"
     8  	"strings"
     9  
    10  	. "gopkg.in/check.v1"
    11  )
    12  
    13  type OssTypeSuite struct{}
    14  
    15  var _ = Suite(&OssTypeSuite{})
    16  
    17  var (
    18  	goStr     = "go go + go <> go"
    19  	chnStr    = "试问闲情几许"
    20  	goURLStr  = url.QueryEscape(goStr)
    21  	chnURLStr = url.QueryEscape(chnStr)
    22  )
    23  
    24  func (s *OssTypeSuite) TestDecodeDeleteObjectsResult(c *C) {
    25  	var res DeleteObjectVersionsResult
    26  	err := decodeDeleteObjectsResult(&res)
    27  	c.Assert(err, IsNil)
    28  
    29  	res.DeletedObjectsDetail = []DeletedKeyInfo{{Key: ""}}
    30  	err = decodeDeleteObjectsResult(&res)
    31  	c.Assert(err, IsNil)
    32  	c.Assert(res.DeletedObjectsDetail[0].Key, Equals, "")
    33  
    34  	res.DeletedObjectsDetail = []DeletedKeyInfo{{Key: goURLStr}, {Key: chnURLStr}}
    35  	err = decodeDeleteObjectsResult(&res)
    36  	c.Assert(err, IsNil)
    37  	c.Assert(res.DeletedObjectsDetail[0].Key, Equals, goStr)
    38  	c.Assert(res.DeletedObjectsDetail[1].Key, Equals, chnStr)
    39  }
    40  
    41  func (s *OssTypeSuite) TestDecodeListObjectsResult(c *C) {
    42  	var res ListObjectsResult
    43  	err := decodeListObjectsResult(&res)
    44  	c.Assert(err, IsNil)
    45  
    46  	res = ListObjectsResult{}
    47  	err = decodeListObjectsResult(&res)
    48  	c.Assert(err, IsNil)
    49  
    50  	res = ListObjectsResult{Prefix: goURLStr, Marker: goURLStr,
    51  		Delimiter: goURLStr, NextMarker: goURLStr,
    52  		Objects:        []ObjectProperties{{Key: chnURLStr}},
    53  		CommonPrefixes: []string{chnURLStr}}
    54  
    55  	err = decodeListObjectsResult(&res)
    56  	c.Assert(err, IsNil)
    57  
    58  	c.Assert(res.Prefix, Equals, goStr)
    59  	c.Assert(res.Marker, Equals, goStr)
    60  	c.Assert(res.Delimiter, Equals, goStr)
    61  	c.Assert(res.NextMarker, Equals, goStr)
    62  	c.Assert(res.Objects[0].Key, Equals, chnStr)
    63  	c.Assert(res.CommonPrefixes[0], Equals, chnStr)
    64  }
    65  
    66  func (s *OssTypeSuite) TestDecodeListMultipartUploadResult(c *C) {
    67  	res := ListMultipartUploadResult{}
    68  	err := decodeListMultipartUploadResult(&res)
    69  	c.Assert(err, IsNil)
    70  
    71  	res = ListMultipartUploadResult{Prefix: goURLStr, KeyMarker: goURLStr,
    72  		Delimiter: goURLStr, NextKeyMarker: goURLStr,
    73  		Uploads: []UncompletedUpload{{Key: chnURLStr}}}
    74  
    75  	err = decodeListMultipartUploadResult(&res)
    76  	c.Assert(err, IsNil)
    77  
    78  	c.Assert(res.Prefix, Equals, goStr)
    79  	c.Assert(res.KeyMarker, Equals, goStr)
    80  	c.Assert(res.Delimiter, Equals, goStr)
    81  	c.Assert(res.NextKeyMarker, Equals, goStr)
    82  	c.Assert(res.Uploads[0].Key, Equals, chnStr)
    83  }
    84  
    85  func (s *OssTypeSuite) TestSortUploadPart(c *C) {
    86  	parts := []UploadPart{}
    87  
    88  	sort.Sort(UploadParts(parts))
    89  	c.Assert(len(parts), Equals, 0)
    90  
    91  	parts = []UploadPart{
    92  		{PartNumber: 5, ETag: "E5"},
    93  		{PartNumber: 1, ETag: "E1"},
    94  		{PartNumber: 4, ETag: "E4"},
    95  		{PartNumber: 2, ETag: "E2"},
    96  		{PartNumber: 3, ETag: "E3"},
    97  	}
    98  
    99  	sort.Sort(UploadParts(parts))
   100  
   101  	c.Assert(parts[0].PartNumber, Equals, 1)
   102  	c.Assert(parts[0].ETag, Equals, "E1")
   103  	c.Assert(parts[1].PartNumber, Equals, 2)
   104  	c.Assert(parts[1].ETag, Equals, "E2")
   105  	c.Assert(parts[2].PartNumber, Equals, 3)
   106  	c.Assert(parts[2].ETag, Equals, "E3")
   107  	c.Assert(parts[3].PartNumber, Equals, 4)
   108  	c.Assert(parts[3].ETag, Equals, "E4")
   109  	c.Assert(parts[4].PartNumber, Equals, 5)
   110  	c.Assert(parts[4].ETag, Equals, "E5")
   111  }
   112  
   113  func (s *OssTypeSuite) TestValidateLifecleRules(c *C) {
   114  	expiration := LifecycleExpiration{
   115  		Days:              30,
   116  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   117  	}
   118  	rule := LifecycleRule{
   119  		ID:         "ruleID",
   120  		Prefix:     "prefix",
   121  		Status:     "Enabled",
   122  		Expiration: &expiration,
   123  	}
   124  	rules := []LifecycleRule{rule}
   125  	err := verifyLifecycleRules(rules)
   126  	c.Assert(err, IsNil)
   127  
   128  	expiration = LifecycleExpiration{
   129  		Date:              "2015-11-11T00:00:00.000Z",
   130  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   131  	}
   132  	rule = LifecycleRule{
   133  		ID:         "ruleID",
   134  		Prefix:     "prefix",
   135  		Status:     "Enabled",
   136  		Expiration: &expiration,
   137  	}
   138  	rules = []LifecycleRule{rule}
   139  	err = verifyLifecycleRules(rules)
   140  	c.Assert(err, IsNil)
   141  
   142  	expiration = LifecycleExpiration{
   143  		Days:              0,
   144  		CreatedBeforeDate: "",
   145  		Date:              "",
   146  	}
   147  	rule = LifecycleRule{
   148  		ID:         "ruleID",
   149  		Prefix:     "prefix",
   150  		Status:     "Enabled",
   151  		Expiration: &expiration,
   152  	}
   153  	rules = []LifecycleRule{rule}
   154  	err = verifyLifecycleRules(rules)
   155  	c.Assert(err, IsNil)
   156  
   157  	abortMPU := LifecycleAbortMultipartUpload{
   158  		Days:              30,
   159  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   160  	}
   161  	rule = LifecycleRule{
   162  		ID:                   "ruleID",
   163  		Prefix:               "prefix",
   164  		Status:               "Enabled",
   165  		AbortMultipartUpload: &abortMPU,
   166  	}
   167  	rules = []LifecycleRule{rule}
   168  	err = verifyLifecycleRules(rules)
   169  	c.Assert(err, NotNil)
   170  
   171  	abortMPU = LifecycleAbortMultipartUpload{
   172  		Days:              0,
   173  		CreatedBeforeDate: "",
   174  	}
   175  	rule = LifecycleRule{
   176  		ID:                   "ruleID",
   177  		Prefix:               "prefix",
   178  		Status:               "Enabled",
   179  		AbortMultipartUpload: &abortMPU,
   180  	}
   181  	rules = []LifecycleRule{rule}
   182  	err = verifyLifecycleRules(rules)
   183  	c.Assert(err, NotNil)
   184  
   185  	transition := LifecycleTransition{
   186  		Days:              30,
   187  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   188  		StorageClass:      StorageIA,
   189  	}
   190  	rule = LifecycleRule{
   191  		ID:          "ruleID",
   192  		Prefix:      "prefix",
   193  		Status:      "Enabled",
   194  		Transitions: []LifecycleTransition{transition},
   195  	}
   196  	rules = []LifecycleRule{rule}
   197  	err = verifyLifecycleRules(rules)
   198  	c.Assert(err, NotNil)
   199  
   200  	transition = LifecycleTransition{
   201  		Days:              0,
   202  		CreatedBeforeDate: "",
   203  		StorageClass:      StorageIA,
   204  	}
   205  	rule = LifecycleRule{
   206  		ID:          "ruleID",
   207  		Prefix:      "prefix",
   208  		Status:      "Enabled",
   209  		Transitions: []LifecycleTransition{transition},
   210  	}
   211  	rules = []LifecycleRule{rule}
   212  	err = verifyLifecycleRules(rules)
   213  	c.Assert(err, NotNil)
   214  
   215  	transition = LifecycleTransition{
   216  		Days:         30,
   217  		StorageClass: StorageStandard,
   218  	}
   219  	rule = LifecycleRule{
   220  		ID:          "ruleID",
   221  		Prefix:      "prefix",
   222  		Status:      "Enabled",
   223  		Transitions: []LifecycleTransition{transition},
   224  	}
   225  	rules = []LifecycleRule{rule}
   226  	err = verifyLifecycleRules(rules)
   227  	c.Assert(err, IsNil)
   228  
   229  	transition = LifecycleTransition{
   230  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   231  		StorageClass:      StorageStandard,
   232  	}
   233  	rule = LifecycleRule{
   234  		ID:          "ruleID",
   235  		Prefix:      "prefix",
   236  		Status:      "Enabled",
   237  		Transitions: []LifecycleTransition{transition},
   238  	}
   239  	rules = []LifecycleRule{rule}
   240  	err = verifyLifecycleRules(rules)
   241  	c.Assert(err, IsNil)
   242  
   243  	transition1 := LifecycleTransition{
   244  		Days:         30,
   245  		StorageClass: StorageIA,
   246  	}
   247  	transition2 := LifecycleTransition{
   248  		Days:         60,
   249  		StorageClass: StorageArchive,
   250  	}
   251  	transition3 := LifecycleTransition{
   252  		Days:         100,
   253  		StorageClass: StorageArchive,
   254  	}
   255  	rule = LifecycleRule{
   256  		ID:          "ruleID",
   257  		Prefix:      "prefix",
   258  		Status:      "Enabled",
   259  		Transitions: []LifecycleTransition{transition1, transition2, transition3},
   260  	}
   261  	rules = []LifecycleRule{rule}
   262  	err = verifyLifecycleRules(rules)
   263  	c.Assert(err, IsNil)
   264  
   265  	rule = LifecycleRule{
   266  		ID:     "ruleID",
   267  		Prefix: "prefix",
   268  		Status: "Enabled",
   269  	}
   270  	rules = []LifecycleRule{rule}
   271  	err = verifyLifecycleRules(rules)
   272  	c.Assert(err, IsNil)
   273  
   274  	rules = []LifecycleRule{}
   275  	err1 := verifyLifecycleRules(rules)
   276  	c.Assert(err1, NotNil)
   277  
   278  	expiration = LifecycleExpiration{
   279  		Days: 30,
   280  	}
   281  	rule = LifecycleRule{
   282  		ID:         "ruleID",
   283  		Prefix:     "prefix",
   284  		Status:     "Enabled",
   285  		Expiration: &expiration,
   286  	}
   287  	rules = []LifecycleRule{rule}
   288  	err = verifyLifecycleRules(rules)
   289  	c.Assert(err, IsNil)
   290  
   291  	expiration = LifecycleExpiration{
   292  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   293  	}
   294  	rule = LifecycleRule{
   295  		ID:         "ruleID",
   296  		Prefix:     "prefix",
   297  		Status:     "Enabled",
   298  		Expiration: &expiration,
   299  	}
   300  	rules = []LifecycleRule{rule}
   301  	err = verifyLifecycleRules(rules)
   302  	c.Assert(err, IsNil)
   303  
   304  	abortMPU = LifecycleAbortMultipartUpload{
   305  		Days: 30,
   306  	}
   307  	rule = LifecycleRule{
   308  		ID:                   "ruleID",
   309  		Prefix:               "prefix",
   310  		Status:               "Enabled",
   311  		AbortMultipartUpload: &abortMPU,
   312  	}
   313  	rules = []LifecycleRule{rule}
   314  	err = verifyLifecycleRules(rules)
   315  	c.Assert(err, IsNil)
   316  
   317  	abortMPU = LifecycleAbortMultipartUpload{
   318  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   319  	}
   320  	rule = LifecycleRule{
   321  		ID:                   "ruleID",
   322  		Prefix:               "prefix",
   323  		Status:               "Enabled",
   324  		AbortMultipartUpload: &abortMPU,
   325  	}
   326  	rules = []LifecycleRule{rule}
   327  	err = verifyLifecycleRules(rules)
   328  	c.Assert(err, IsNil)
   329  
   330  	expiration = LifecycleExpiration{
   331  		Days: 30,
   332  	}
   333  	abortMPU = LifecycleAbortMultipartUpload{
   334  		Days: 30,
   335  	}
   336  	rule = LifecycleRule{
   337  		ID:                   "ruleID",
   338  		Prefix:               "prefix",
   339  		Status:               "Enabled",
   340  		Expiration:           &expiration,
   341  		AbortMultipartUpload: &abortMPU,
   342  	}
   343  	rules = []LifecycleRule{rule}
   344  	err = verifyLifecycleRules(rules)
   345  	c.Assert(err, IsNil)
   346  
   347  	expiration = LifecycleExpiration{
   348  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   349  	}
   350  	abortMPU = LifecycleAbortMultipartUpload{
   351  		Days: 30,
   352  	}
   353  	transition = LifecycleTransition{
   354  		Days:         30,
   355  		StorageClass: StorageIA,
   356  	}
   357  	rule = LifecycleRule{
   358  		ID:                   "ruleID",
   359  		Prefix:               "prefix",
   360  		Status:               "Enabled",
   361  		Expiration:           &expiration,
   362  		AbortMultipartUpload: &abortMPU,
   363  		Transitions:          []LifecycleTransition{transition},
   364  	}
   365  	rules = []LifecycleRule{rule}
   366  	err = verifyLifecycleRules(rules)
   367  	c.Assert(err, IsNil)
   368  
   369  	expiration = LifecycleExpiration{
   370  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   371  	}
   372  	abortMPU = LifecycleAbortMultipartUpload{
   373  		Days: 30,
   374  	}
   375  	transition1 = LifecycleTransition{
   376  		Days:         30,
   377  		StorageClass: StorageIA,
   378  	}
   379  	transition2 = LifecycleTransition{
   380  		Days:         60,
   381  		StorageClass: StorageArchive,
   382  	}
   383  	rule = LifecycleRule{
   384  		ID:                   "ruleID",
   385  		Prefix:               "prefix",
   386  		Status:               "Enabled",
   387  		Expiration:           &expiration,
   388  		AbortMultipartUpload: &abortMPU,
   389  		Transitions:          []LifecycleTransition{transition1, transition2},
   390  	}
   391  	rules = []LifecycleRule{rule}
   392  	err = verifyLifecycleRules(rules)
   393  	c.Assert(err, IsNil)
   394  }
   395  
   396  // test get meta query statsu result
   397  func (s *OssTypeSuite) TestGetMetaQueryStatusResult(c *C) {
   398  	var res GetMetaQueryStatusResult
   399  	xmlData := []byte(`<?xml version="1.0" encoding="UTF-8"?>
   400  <MetaQueryStatus>
   401    <State>Running</State>
   402    <Phase>FullScanning</Phase>
   403    <CreateTime>2021-08-02T10:49:17.289372919+08:00</CreateTime>
   404    <UpdateTime>2021-08-02T10:49:17.289372919+08:00</UpdateTime>
   405  </MetaQueryStatus>`)
   406  	err := xml.Unmarshal(xmlData, &res)
   407  	c.Assert(err, IsNil)
   408  	c.Assert(res.State, Equals, "Running")
   409  	c.Assert(res.Phase, Equals, "FullScanning")
   410  	c.Assert(res.CreateTime, Equals, "2021-08-02T10:49:17.289372919+08:00")
   411  	c.Assert(res.UpdateTime, Equals, "2021-08-02T10:49:17.289372919+08:00")
   412  }
   413  
   414  // test do meta query request xml
   415  func (s *OssTypeSuite) TestDoMetaQueryRequest(c *C) {
   416  	var res MetaQuery
   417  	xmlData := []byte(`<?xml version="1.0" encoding="UTF-8"?>
   418  <MetaQuery>
   419    <NextToken>MTIzNDU2Nzg6aW1tdGVzdDpleGFtcGxlYnVja2V0OmRhdGFzZXQwMDE6b3NzOi8vZXhhbXBsZWJ1Y2tldC9zYW1wbGVvYmplY3QxLmpwZw==</NextToken>
   420    <MaxResults>5</MaxResults>
   421    <Query>{"Field": "Size","Value": "1048576","Operation": "gt"}</Query>
   422    <Sort>Size</Sort>
   423    <Order>asc</Order>
   424    <Aggregations>
   425      <Aggregation>
   426        <Field>Size</Field>
   427        <Operation>sum</Operation>
   428      </Aggregation>
   429      <Aggregation>
   430        <Field>Size</Field>
   431        <Operation>max</Operation>
   432      </Aggregation>
   433    </Aggregations>
   434  </MetaQuery>`)
   435  	err := xml.Unmarshal(xmlData, &res)
   436  	c.Assert(err, IsNil)
   437  	c.Assert(res.NextToken, Equals, "MTIzNDU2Nzg6aW1tdGVzdDpleGFtcGxlYnVja2V0OmRhdGFzZXQwMDE6b3NzOi8vZXhhbXBsZWJ1Y2tldC9zYW1wbGVvYmplY3QxLmpwZw==")
   438  	c.Assert(res.MaxResults, Equals, int64(5))
   439  	c.Assert(res.Query, Equals, `{"Field": "Size","Value": "1048576","Operation": "gt"}`)
   440  	c.Assert(res.Sort, Equals, "Size")
   441  	c.Assert(res.Order, Equals, "asc")
   442  	c.Assert(res.Aggregations[0].Field, Equals, "Size")
   443  	c.Assert(res.Aggregations[1].Operation, Equals, "max")
   444  }
   445  
   446  // test do meta query result
   447  func (s *OssTypeSuite) TestDoMetaQueryResult(c *C) {
   448  	var res DoMetaQueryResult
   449  	xmlData := []byte(`<?xml version="1.0" encoding="UTF-8"?>
   450  <MetaQuery>
   451    <NextToken>MTIzNDU2Nzg6aW1tdGVzdDpleGFtcGxlYnVja2V0OmRhdGFzZXQwMDE6b3NzOi8vZXhhbXBsZWJ1Y2tldC9zYW1wbGVvYmplY3QxLmpwZw==</NextToken>
   452    <Files>
   453      <File>
   454        <Filename>exampleobject.txt</Filename>
   455        <Size>120</Size>
   456        <FileModifiedTime>2021-06-29T14:50:13.011643661+08:00</FileModifiedTime>
   457        <OSSObjectType>Normal</OSSObjectType>
   458        <OSSStorageClass>Standard</OSSStorageClass>
   459        <ObjectACL>default</ObjectACL>
   460        <ETag>"fba9dede5f27731c9771645a3986****"</ETag>
   461        <OSSCRC64>4858A48BD1466884</OSSCRC64>
   462        <OSSTaggingCount>2</OSSTaggingCount>
   463        <OSSTagging>
   464          <Tagging>
   465            <Key>owner</Key>
   466            <Value>John</Value>
   467          </Tagging>
   468          <Tagging>
   469            <Key>type</Key>
   470            <Value>document</Value>
   471          </Tagging>
   472        </OSSTagging>
   473        <OSSUserMeta>
   474          <UserMeta>
   475            <Key>x-oss-meta-location</Key>
   476            <Value>hangzhou</Value>
   477          </UserMeta>
   478        </OSSUserMeta>
   479      </File>
   480    </Files>
   481  </MetaQuery>`)
   482  	err := xml.Unmarshal(xmlData, &res)
   483  	c.Assert(err, IsNil)
   484  	c.Assert(res.NextToken, Equals, "MTIzNDU2Nzg6aW1tdGVzdDpleGFtcGxlYnVja2V0OmRhdGFzZXQwMDE6b3NzOi8vZXhhbXBsZWJ1Y2tldC9zYW1wbGVvYmplY3QxLmpwZw==")
   485  	c.Assert(res.Files[0].Filename, Equals, "exampleobject.txt")
   486  	c.Assert(res.Files[0].Size, Equals, int64(120))
   487  	c.Assert(res.Files[0].FileModifiedTime, Equals, "2021-06-29T14:50:13.011643661+08:00")
   488  	c.Assert(res.Files[0].OssObjectType, Equals, "Normal")
   489  	c.Assert(res.Files[0].OssCRC64, Equals, "4858A48BD1466884")
   490  	c.Assert(res.Files[0].OssObjectType, Equals, "Normal")
   491  	c.Assert(res.Files[0].OssStorageClass, Equals, "Standard")
   492  	c.Assert(res.Files[0].ObjectACL, Equals, "default")
   493  	c.Assert(res.Files[0].OssTagging[1].Key, Equals, "type")
   494  	c.Assert(res.Files[0].OssTagging[1].Value, Equals, "document")
   495  	c.Assert(res.Files[0].OssUserMeta[0].Value, Equals, "hangzhou")
   496  
   497  	// test aggregations
   498  	xmlData = []byte(`<?xml version="1.0" encoding="UTF-8"?>
   499  <MetaQuery>
   500      <NextToken></NextToken>
   501      <Aggregations>
   502          <Aggregation>
   503              <Field>Size</Field>
   504              <Operation>sum</Operation>
   505              <Value>839794720</Value>
   506          </Aggregation>
   507          <Aggregation>
   508              <Field>Size</Field>
   509              <Operation>group</Operation>
   510              <Groups>
   511                  <Group>
   512                      <Value>518</Value>
   513                      <Count>1</Count>
   514                  </Group>
   515                  <Group>
   516                      <Value>581</Value>
   517                      <Count>1</Count>
   518                  </Group>
   519              </Groups>
   520          </Aggregation>
   521      </Aggregations>
   522  </MetaQuery>
   523  `)
   524  	err = xml.Unmarshal(xmlData, &res)
   525  	c.Assert(err, IsNil)
   526  	c.Assert(res.NextToken, Equals, "")
   527  	c.Assert(res.Aggregations[0].Field, Equals, "Size")
   528  	c.Assert(res.Aggregations[0].Operation, Equals, "sum")
   529  	c.Assert(res.Aggregations[0].Value, Equals, float64(839794720))
   530  	c.Assert(res.Aggregations[1].Operation, Equals, "group")
   531  	c.Assert(res.Aggregations[1].Groups[1].Value, Equals, "581")
   532  	c.Assert(res.Aggregations[1].Groups[1].Count, Equals, int64(1))
   533  }
   534  
   535  // test get bucket stat result
   536  func (s *OssTypeSuite) TestGetBucketStatResult(c *C) {
   537  	var res GetBucketStatResult
   538  	xmlData := []byte(`<?xml version="1.0" encoding="UTF-8"?>
   539  <BucketStat>
   540    <Storage>1600</Storage>
   541    <ObjectCount>230</ObjectCount>
   542    <MultipartUploadCount>40</MultipartUploadCount>
   543    <LiveChannelCount>4</LiveChannelCount>
   544    <LastModifiedTime>1643341269</LastModifiedTime>
   545    <StandardStorage>430</StandardStorage>
   546    <StandardObjectCount>66</StandardObjectCount>
   547    <InfrequentAccessStorage>2359296</InfrequentAccessStorage>
   548    <InfrequentAccessRealStorage>360</InfrequentAccessRealStorage>
   549    <InfrequentAccessObjectCount>54</InfrequentAccessObjectCount>
   550    <ArchiveStorage>2949120</ArchiveStorage>
   551    <ArchiveRealStorage>450</ArchiveRealStorage>
   552    <ArchiveObjectCount>74</ArchiveObjectCount>
   553    <ColdArchiveStorage>2359296</ColdArchiveStorage>
   554    <ColdArchiveRealStorage>360</ColdArchiveRealStorage>
   555    <ColdArchiveObjectCount>36</ColdArchiveObjectCount>
   556  </BucketStat>`)
   557  	err := xml.Unmarshal(xmlData, &res)
   558  	c.Assert(err, IsNil)
   559  	c.Assert(res.Storage, Equals, int64(1600))
   560  	c.Assert(res.ObjectCount, Equals, int64(230))
   561  	c.Assert(res.MultipartUploadCount, Equals, int64(40))
   562  	c.Assert(res.LiveChannelCount, Equals, int64(4))
   563  	c.Assert(res.LastModifiedTime, Equals, int64(1643341269))
   564  	c.Assert(res.StandardStorage, Equals, int64(430))
   565  	c.Assert(res.StandardObjectCount, Equals, int64(66))
   566  	c.Assert(res.InfrequentAccessStorage, Equals, int64(2359296))
   567  	c.Assert(res.InfrequentAccessRealStorage, Equals, int64(360))
   568  	c.Assert(res.InfrequentAccessObjectCount, Equals, int64(54))
   569  	c.Assert(res.ArchiveStorage, Equals, int64(2949120))
   570  	c.Assert(res.ArchiveRealStorage, Equals, int64(450))
   571  	c.Assert(res.ArchiveObjectCount, Equals, int64(74))
   572  	c.Assert(res.ColdArchiveStorage, Equals, int64(2359296))
   573  	c.Assert(res.ColdArchiveRealStorage, Equals, int64(360))
   574  	c.Assert(res.ColdArchiveObjectCount, Equals, int64(36))
   575  }
   576  
   577  // test delete object struct turn to xml string
   578  func (s *OssTypeSuite) TestDeleteObjectToXml(c *C) {
   579  	versionIds := make([]DeleteObject, 0)
   580  	versionIds = append(versionIds, DeleteObject{Key: "\f", VersionId: "1111"})
   581  	dxml := deleteXML{}
   582  	dxml.Objects = versionIds
   583  	dxml.Quiet = false
   584  	str := marshalDeleteObjectToXml(dxml)
   585  	str2 := "<Delete><Quiet>false</Quiet><Object><Key>&#x0C;</Key><VersionId>1111</VersionId></Object></Delete>"
   586  	c.Assert(str, Equals, str2)
   587  
   588  	versionIds = append(versionIds, DeleteObject{Key: "A ' < > \" & ~ ` ! @ # $ % ^ & * ( ) [] {} - _ + = / | \\ ? . , : ; A", VersionId: "2222"})
   589  	dxml.Objects = versionIds
   590  	dxml.Quiet = false
   591  	str = marshalDeleteObjectToXml(dxml)
   592  	str2 = "<Delete><Quiet>false</Quiet><Object><Key>&#x0C;</Key><VersionId>1111</VersionId></Object><Object><Key>A &#39; &lt; &gt; &#34; &amp; ~ ` ! @ # $ % ^ &amp; * ( ) [] {} - _ + = / | \\ ? . , : ; A</Key><VersionId>2222</VersionId></Object></Delete>"
   593  	c.Assert(str, Equals, str2)
   594  
   595  	objects := make([]DeleteObject, 0)
   596  	objects = append(objects, DeleteObject{Key: "\v"})
   597  	dxml.Objects = objects
   598  	dxml.Quiet = true
   599  	str = marshalDeleteObjectToXml(dxml)
   600  	str2 = "<Delete><Quiet>true</Quiet><Object><Key>&#x0B;</Key></Object></Delete>"
   601  	c.Assert(str, Equals, str2)
   602  }
   603  
   604  // test access monitor
   605  func (s *OssTypeSuite) TestAccessMonitor(c *C) {
   606  	var res GetBucketAccessMonitorResult
   607  	xmlData := []byte(`<?xml version="1.0" encoding="UTF-8"?>
   608  <AccessMonitorConfiguration>
   609  <Status>Enabled</Status>
   610  </AccessMonitorConfiguration>
   611  `)
   612  	err := xml.Unmarshal(xmlData, &res)
   613  	c.Assert(err, IsNil)
   614  	c.Assert(res.Status, Equals, "Enabled")
   615  
   616  	// test aggregations
   617  	xmlData = []byte(`<?xml version="1.0" encoding="UTF-8"?>
   618  <AccessMonitorConfiguration>
   619  <Status>Disabled</Status>
   620  </AccessMonitorConfiguration>
   621  `)
   622  	err = xml.Unmarshal(xmlData, &res)
   623  	c.Assert(res.Status, Equals, "Disabled")
   624  
   625  	var req PutBucketAccessMonitor
   626  	req.Status = "Enabled"
   627  	bs, err := xml.Marshal(req)
   628  	c.Assert(err, IsNil)
   629  	c.Assert(string(bs), Equals, `<AccessMonitorConfiguration><Status>Enabled</Status></AccessMonitorConfiguration>`)
   630  
   631  	req.Status = "Disabled"
   632  	bs, err = xml.Marshal(req)
   633  	c.Assert(err, IsNil)
   634  	c.Assert(string(bs), Equals, `<AccessMonitorConfiguration><Status>Disabled</Status></AccessMonitorConfiguration>`)
   635  }
   636  
   637  // test bucket info result with access monitor
   638  func (s *OssTypeSuite) TestBucketInfoWithAccessMonitor(c *C) {
   639  	var res GetBucketInfoResult
   640  	xmlData := []byte(`<?xml version="1.0" encoding="UTF-8"?>
   641  <BucketInfo>
   642    <Bucket>
   643      <AccessMonitor>Enabled</AccessMonitor>
   644      <CreationDate>2013-07-31T10:56:21.000Z</CreationDate>
   645      <ExtranetEndpoint>oss-cn-hangzhou.aliyuncs.com</ExtranetEndpoint>
   646      <IntranetEndpoint>oss-cn-hangzhou-internal.aliyuncs.com</IntranetEndpoint>
   647      <Location>oss-cn-hangzhou</Location>
   648      <StorageClass>Standard</StorageClass>
   649      <TransferAcceleration>Disabled</TransferAcceleration>
   650      <CrossRegionReplication>Disabled</CrossRegionReplication>
   651      <Name>oss-example</Name>
   652      <Owner>
   653        <DisplayName>username</DisplayName>
   654        <ID>27183473914</ID>
   655      </Owner>
   656      <Comment>test</Comment>
   657    </Bucket>
   658  </BucketInfo>
   659  `)
   660  	err := xml.Unmarshal(xmlData, &res)
   661  	c.Assert(err, IsNil)
   662  	c.Assert(res.BucketInfo.AccessMonitor, Equals, "Enabled")
   663  	c.Assert(res.BucketInfo.CreationDate.Format("2006-01-02 15:04:05 +0000 UTC"), Equals, "2013-07-31 10:56:21 +0000 UTC")
   664  	c.Assert(res.BucketInfo.ExtranetEndpoint, Equals, "oss-cn-hangzhou.aliyuncs.com")
   665  	c.Assert(res.BucketInfo.IntranetEndpoint, Equals, "oss-cn-hangzhou-internal.aliyuncs.com")
   666  	c.Assert(res.BucketInfo.Location, Equals, "oss-cn-hangzhou")
   667  	c.Assert(res.BucketInfo.StorageClass, Equals, "Standard")
   668  	c.Assert(res.BucketInfo.TransferAcceleration, Equals, "Disabled")
   669  	c.Assert(res.BucketInfo.CrossRegionReplication, Equals, "Disabled")
   670  	c.Assert(res.BucketInfo.Name, Equals, "oss-example")
   671  	c.Assert(res.BucketInfo.Owner.ID, Equals, "27183473914")
   672  	c.Assert(res.BucketInfo.Owner.DisplayName, Equals, "username")
   673  	xmlData = []byte(`<?xml version="1.0" encoding="UTF-8"?>
   674  <BucketInfo>
   675    <Bucket>
   676      <AccessMonitor>Disabled</AccessMonitor>
   677      <CreationDate>2013-07-31T10:56:21.000Z</CreationDate>
   678      <ExtranetEndpoint>oss-cn-hangzhou.aliyuncs.com</ExtranetEndpoint>
   679      <IntranetEndpoint>oss-cn-hangzhou-internal.aliyuncs.com</IntranetEndpoint>
   680      <Location>oss-cn-hangzhou</Location>
   681      <StorageClass>Standard</StorageClass>
   682      <TransferAcceleration>Disabled</TransferAcceleration>
   683      <CrossRegionReplication>Disabled</CrossRegionReplication>
   684      <Name>oss-example</Name>
   685    </Bucket>
   686  </BucketInfo>
   687  `)
   688  	err = xml.Unmarshal(xmlData, &res)
   689  	c.Assert(err, IsNil)
   690  	c.Assert(res.BucketInfo.AccessMonitor, Equals, "Disabled")
   691  }
   692  
   693  func (s *OssTypeSuite) TestValidateLifeCycleRulesWithAccessTime(c *C) {
   694  	expiration := LifecycleExpiration{
   695  		Days:              30,
   696  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   697  	}
   698  	isTrue := true
   699  	isFalse := false
   700  	rule := LifecycleRule{
   701  		ID:         "ruleID",
   702  		Prefix:     "prefix",
   703  		Status:     "Enabled",
   704  		Expiration: &expiration,
   705  		Transitions: []LifecycleTransition{
   706  			{
   707  				Days:         30,
   708  				StorageClass: StorageIA,
   709  				IsAccessTime: &isFalse,
   710  			},
   711  		},
   712  	}
   713  	rules := []LifecycleRule{rule}
   714  	err := verifyLifecycleRules(rules)
   715  	c.Assert(err, IsNil)
   716  
   717  	rule = LifecycleRule{
   718  		ID:         "ruleID",
   719  		Prefix:     "prefix",
   720  		Status:     "Enabled",
   721  		Expiration: &expiration,
   722  		Transitions: []LifecycleTransition{
   723  			{
   724  				Days:                 30,
   725  				StorageClass:         StorageIA,
   726  				IsAccessTime:         &isTrue,
   727  				ReturnToStdWhenVisit: &isFalse,
   728  			},
   729  		},
   730  	}
   731  	rules = []LifecycleRule{rule}
   732  	err = verifyLifecycleRules(rules)
   733  	c.Assert(err, IsNil)
   734  
   735  	rule = LifecycleRule{
   736  		ID:         "ruleID",
   737  		Prefix:     "prefix",
   738  		Status:     "Enabled",
   739  		Expiration: &expiration,
   740  		Transitions: []LifecycleTransition{
   741  			{
   742  				Days:                 30,
   743  				StorageClass:         StorageIA,
   744  				IsAccessTime:         &isTrue,
   745  				ReturnToStdWhenVisit: &isTrue,
   746  			},
   747  		},
   748  	}
   749  	rules = []LifecycleRule{rule}
   750  	err = verifyLifecycleRules(rules)
   751  	c.Assert(err, IsNil)
   752  
   753  	rule = LifecycleRule{
   754  		ID:         "ruleID",
   755  		Prefix:     "prefix",
   756  		Status:     "Enabled",
   757  		Expiration: &expiration,
   758  		NonVersionTransitions: []LifecycleVersionTransition{
   759  			{
   760  				NoncurrentDays:       10,
   761  				StorageClass:         StorageIA,
   762  				IsAccessTime:         &isTrue,
   763  				ReturnToStdWhenVisit: &isTrue,
   764  			},
   765  		},
   766  	}
   767  	rules = []LifecycleRule{rule}
   768  	err = verifyLifecycleRules(rules)
   769  	c.Assert(err, IsNil)
   770  
   771  	abortMPU := LifecycleAbortMultipartUpload{
   772  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   773  	}
   774  	rule = LifecycleRule{
   775  		ID:                   "ruleID",
   776  		Prefix:               "prefix",
   777  		Status:               "Enabled",
   778  		AbortMultipartUpload: &abortMPU,
   779  		NonVersionTransitions: []LifecycleVersionTransition{
   780  			{
   781  				NoncurrentDays:       10,
   782  				StorageClass:         StorageIA,
   783  				IsAccessTime:         &isTrue,
   784  				ReturnToStdWhenVisit: &isTrue,
   785  			},
   786  		},
   787  	}
   788  	rules = []LifecycleRule{rule}
   789  	err = verifyLifecycleRules(rules)
   790  	c.Assert(err, IsNil)
   791  
   792  	expiration = LifecycleExpiration{
   793  		Days: 30,
   794  	}
   795  	abortMPU = LifecycleAbortMultipartUpload{
   796  		Days: 30,
   797  	}
   798  	rule = LifecycleRule{
   799  		ID:                   "ruleID",
   800  		Prefix:               "prefix",
   801  		Status:               "Enabled",
   802  		Expiration:           &expiration,
   803  		AbortMultipartUpload: &abortMPU,
   804  		NonVersionTransitions: []LifecycleVersionTransition{
   805  			{
   806  				NoncurrentDays:       10,
   807  				StorageClass:         StorageIA,
   808  				IsAccessTime:         &isTrue,
   809  				ReturnToStdWhenVisit: &isFalse,
   810  			},
   811  		},
   812  	}
   813  	rules = []LifecycleRule{rule}
   814  	err = verifyLifecycleRules(rules)
   815  	c.Assert(err, IsNil)
   816  }
   817  
   818  func (s *OssTypeSuite) TestLifeCycleRules(c *C) {
   819  	expiration := LifecycleExpiration{
   820  		Days:              30,
   821  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   822  	}
   823  	isTrue := true
   824  	isFalse := false
   825  	rule := LifecycleRule{
   826  		ID:         "ruleID",
   827  		Prefix:     "prefix",
   828  		Status:     "Enabled",
   829  		Expiration: &expiration,
   830  		Transitions: []LifecycleTransition{
   831  			{
   832  				Days:         30,
   833  				StorageClass: StorageIA,
   834  				IsAccessTime: &isFalse,
   835  			},
   836  		},
   837  	}
   838  	rules := []LifecycleRule{rule}
   839  	err := verifyLifecycleRules(rules)
   840  	c.Assert(err, IsNil)
   841  
   842  	rule = LifecycleRule{
   843  		ID:         "ruleID",
   844  		Prefix:     "prefix",
   845  		Status:     "Enabled",
   846  		Expiration: &expiration,
   847  		Transitions: []LifecycleTransition{
   848  			{
   849  				Days:                 30,
   850  				StorageClass:         StorageIA,
   851  				IsAccessTime:         &isTrue,
   852  				ReturnToStdWhenVisit: &isFalse,
   853  			},
   854  		},
   855  	}
   856  	rules = []LifecycleRule{rule}
   857  	err = verifyLifecycleRules(rules)
   858  	c.Assert(err, IsNil)
   859  
   860  	rule = LifecycleRule{
   861  		ID:         "ruleID",
   862  		Prefix:     "prefix",
   863  		Status:     "Enabled",
   864  		Expiration: &expiration,
   865  		Transitions: []LifecycleTransition{
   866  			{
   867  				Days:                 30,
   868  				StorageClass:         StorageIA,
   869  				IsAccessTime:         &isTrue,
   870  				ReturnToStdWhenVisit: &isTrue,
   871  			},
   872  		},
   873  	}
   874  	rules = []LifecycleRule{rule}
   875  	err = verifyLifecycleRules(rules)
   876  	c.Assert(err, IsNil)
   877  
   878  	rule = LifecycleRule{
   879  		ID:         "ruleID",
   880  		Prefix:     "prefix",
   881  		Status:     "Enabled",
   882  		Expiration: &expiration,
   883  		NonVersionTransitions: []LifecycleVersionTransition{
   884  			{
   885  				NoncurrentDays:       10,
   886  				StorageClass:         StorageIA,
   887  				IsAccessTime:         &isTrue,
   888  				ReturnToStdWhenVisit: &isTrue,
   889  			},
   890  		},
   891  	}
   892  	rules = []LifecycleRule{rule}
   893  	err = verifyLifecycleRules(rules)
   894  	c.Assert(err, IsNil)
   895  
   896  	abortMPU := LifecycleAbortMultipartUpload{
   897  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
   898  	}
   899  	rule = LifecycleRule{
   900  		ID:                   "ruleID",
   901  		Prefix:               "prefix",
   902  		Status:               "Enabled",
   903  		AbortMultipartUpload: &abortMPU,
   904  		NonVersionTransitions: []LifecycleVersionTransition{
   905  			{
   906  				NoncurrentDays:       10,
   907  				StorageClass:         StorageIA,
   908  				IsAccessTime:         &isTrue,
   909  				ReturnToStdWhenVisit: &isTrue,
   910  			},
   911  		},
   912  	}
   913  	rules = []LifecycleRule{rule}
   914  	err = verifyLifecycleRules(rules)
   915  	c.Assert(err, IsNil)
   916  
   917  	expiration = LifecycleExpiration{
   918  		Days: 30,
   919  	}
   920  	abortMPU = LifecycleAbortMultipartUpload{
   921  		Days: 30,
   922  	}
   923  	rule = LifecycleRule{
   924  		ID:                   "ruleID",
   925  		Prefix:               "prefix",
   926  		Status:               "Enabled",
   927  		Expiration:           &expiration,
   928  		AbortMultipartUpload: &abortMPU,
   929  		NonVersionTransitions: []LifecycleVersionTransition{
   930  			{
   931  				NoncurrentDays:       10,
   932  				StorageClass:         StorageIA,
   933  				IsAccessTime:         &isTrue,
   934  				ReturnToStdWhenVisit: &isFalse,
   935  			},
   936  		},
   937  	}
   938  	rules = []LifecycleRule{rule}
   939  	err = verifyLifecycleRules(rules)
   940  	c.Assert(err, IsNil)
   941  }
   942  
   943  func (s *OssTypeSuite) TestGetBucketLifecycleResult(c *C) {
   944  	xmlData := []byte(`<?xml version="1.0" encoding="UTF-8"?>
   945  <LifecycleConfiguration>
   946    <Rule>
   947      <ID>RuleID</ID>
   948      <Prefix>logs</Prefix>
   949      <Status>Enabled</Status>
   950      <Filter>
   951        <Not>
   952          <Prefix>logs1</Prefix>
   953          <Tag><Key>key1</Key><Value>value1</Value></Tag>
   954          </Not>
   955      </Filter>
   956      <Expiration>
   957        <Days>100</Days>
   958      </Expiration>
   959      <Transition>
   960        <Days>30</Days>
   961        <StorageClass>Archive</StorageClass>
   962      </Transition>
   963    </Rule>
   964  </LifecycleConfiguration>
   965  `)
   966  	var res GetBucketLifecycleResult
   967  	err := xml.Unmarshal(xmlData, &res)
   968  	c.Assert(err, IsNil)
   969  	c.Assert(res.Rules[0].ID, Equals, "RuleID")
   970  	c.Assert(res.Rules[0].Filter.Not[0].Prefix, Equals, "logs1")
   971  	c.Assert(res.Rules[0].Filter.Not[0].Tag.Key, Equals, "key1")
   972  	c.Assert(res.Rules[0].Filter.Not[0].Tag.Value, Equals, "value1")
   973  
   974  	xmlData = []byte(`<?xml version="1.0" encoding="UTF-8"?>
   975  <LifecycleConfiguration>
   976    <Rule>
   977      <ID>test2</ID>
   978      <Prefix>logs</Prefix>
   979      <Status>Enabled</Status>
   980      <Filter>
   981        <Not>
   982          <Prefix>logs-demo</Prefix>
   983        </Not>
   984        <Not>
   985          <Prefix>abc/not1/</Prefix>
   986          <Tag>
   987            <Key>notkey1</Key>
   988            <Value>notvalue1</Value>
   989          </Tag>
   990        </Not>
   991        <Not>
   992          <Prefix>abc/not2/</Prefix>
   993          <Tag>
   994            <Key>notkey2</Key>
   995            <Value>notvalue2</Value>
   996          </Tag>
   997        </Not>
   998      </Filter>
   999      <Expiration>
  1000        <Days>100</Days>
  1001      </Expiration>
  1002      <Transition>
  1003        <Days>30</Days>
  1004        <StorageClass>Archive</StorageClass>
  1005      </Transition>
  1006    </Rule>
  1007  </LifecycleConfiguration>
  1008  `)
  1009  	var res1 GetBucketLifecycleResult
  1010  	err = xml.Unmarshal(xmlData, &res1)
  1011  	c.Assert(err, IsNil)
  1012  	c.Assert(res1.Rules[0].ID, Equals, "test2")
  1013  	c.Assert(res1.Rules[0].Filter.Not[0].Prefix, Equals, "logs-demo")
  1014  	c.Assert(res1.Rules[0].Filter.Not[1].Prefix, Equals, "abc/not1/")
  1015  	c.Assert(res1.Rules[0].Filter.Not[1].Tag.Key, Equals, "notkey1")
  1016  	c.Assert(res1.Rules[0].Filter.Not[1].Tag.Value, Equals, "notvalue1")
  1017  	c.Assert(res1.Rules[0].Filter.Not[2].Prefix, Equals, "abc/not2/")
  1018  	c.Assert(res1.Rules[0].Filter.Not[2].Tag.Key, Equals, "notkey2")
  1019  	c.Assert(res1.Rules[0].Filter.Not[2].Tag.Value, Equals, "notvalue2")
  1020  
  1021  	xmlData = []byte(`<?xml version="1.0" encoding="UTF-8"?><LifecycleConfiguration>
  1022    <Rule>
  1023      <ID>r1</ID>
  1024      <Prefix>abc/</Prefix>
  1025      <Filter>
  1026        <ObjectSizeGreaterThan>500</ObjectSizeGreaterThan>
  1027        <ObjectSizeLessThan>64000</ObjectSizeLessThan>
  1028        <Not>
  1029          <Prefix>abc/not1/</Prefix>
  1030          <Tag>
  1031            <Key>notkey1</Key>
  1032            <Value>notvalue1</Value>
  1033          </Tag>
  1034        </Not>
  1035        <Not>
  1036          <Prefix>abc/not2/</Prefix>
  1037          <Tag>
  1038            <Key>notkey2</Key>
  1039            <Value>notvalue2</Value>
  1040          </Tag>
  1041        </Not>
  1042      </Filter>
  1043    </Rule>
  1044    <Rule>
  1045      <ID>r2</ID>
  1046      <Prefix>def/</Prefix>
  1047      <Filter>
  1048        <ObjectSizeGreaterThan>500</ObjectSizeGreaterThan>
  1049        <Not>
  1050          <Prefix>def/not1/</Prefix>
  1051        </Not>
  1052        <Not>
  1053          <Prefix>def/not2/</Prefix>
  1054          <Tag>
  1055            <Key>notkey2</Key>
  1056            <Value>notvalue2</Value>
  1057          </Tag>
  1058        </Not>
  1059      </Filter>
  1060    </Rule>
  1061  </LifecycleConfiguration>
  1062  `)
  1063  
  1064  	var res2 GetBucketLifecycleResult
  1065  	err = xml.Unmarshal(xmlData, &res2)
  1066  	testLogger.Println(res2.Rules[1].Filter)
  1067  	c.Assert(err, IsNil)
  1068  	c.Assert(res2.Rules[0].ID, Equals, "r1")
  1069  	c.Assert(res2.Rules[0].Prefix, Equals, "abc/")
  1070  	c.Assert(*(res2.Rules[0].Filter.ObjectSizeGreaterThan), Equals, int64(500))
  1071  	c.Assert(*(res2.Rules[0].Filter.ObjectSizeLessThan), Equals, int64(64000))
  1072  	c.Assert(res2.Rules[0].Filter.Not[0].Prefix, Equals, "abc/not1/")
  1073  	c.Assert(res2.Rules[0].Filter.Not[0].Tag.Key, Equals, "notkey1")
  1074  	c.Assert(res2.Rules[0].Filter.Not[0].Tag.Value, Equals, "notvalue1")
  1075  
  1076  	c.Assert(res2.Rules[0].Filter.Not[1].Prefix, Equals, "abc/not2/")
  1077  	c.Assert(res2.Rules[0].Filter.Not[1].Tag.Key, Equals, "notkey2")
  1078  	c.Assert(res2.Rules[0].Filter.Not[1].Tag.Value, Equals, "notvalue2")
  1079  
  1080  	c.Assert(res2.Rules[1].ID, Equals, "r2")
  1081  	c.Assert(res2.Rules[1].Prefix, Equals, "def/")
  1082  	c.Assert(*(res2.Rules[1].Filter.ObjectSizeGreaterThan), Equals, int64(500))
  1083  	c.Assert(res2.Rules[1].Filter.ObjectSizeLessThan, IsNil)
  1084  	c.Assert(res2.Rules[1].Filter.Not[0].Prefix, Equals, "def/not1/")
  1085  
  1086  	c.Assert(res2.Rules[1].Filter.Not[1].Prefix, Equals, "def/not2/")
  1087  	c.Assert(res2.Rules[1].Filter.Not[1].Tag.Key, Equals, "notkey2")
  1088  	c.Assert(res2.Rules[1].Filter.Not[1].Tag.Value, Equals, "notvalue2")
  1089  }
  1090  func (s *OssTypeSuite) TestLifecycleConfiguration(c *C) {
  1091  	expiration := LifecycleExpiration{
  1092  		Days:              30,
  1093  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
  1094  	}
  1095  	isTrue := true
  1096  	isFalse := false
  1097  	greater := int64(500)
  1098  	less := int64(645000)
  1099  	filter := LifecycleFilter{
  1100  		ObjectSizeGreaterThan: &greater,
  1101  		ObjectSizeLessThan:    &less,
  1102  	}
  1103  	rule0 := LifecycleRule{
  1104  		ID:         "r0",
  1105  		Prefix:     "prefix0",
  1106  		Status:     "Enabled",
  1107  		Expiration: &expiration,
  1108  	}
  1109  	rule1 := LifecycleRule{
  1110  		ID:         "r1",
  1111  		Prefix:     "prefix1",
  1112  		Status:     "Enabled",
  1113  		Expiration: &expiration,
  1114  		Transitions: []LifecycleTransition{
  1115  			{
  1116  				Days:         30,
  1117  				StorageClass: StorageIA,
  1118  				IsAccessTime: &isFalse,
  1119  			},
  1120  		},
  1121  		Filter: &filter,
  1122  	}
  1123  
  1124  	abortMPU := LifecycleAbortMultipartUpload{
  1125  		Days:              30,
  1126  		CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
  1127  	}
  1128  	rule2 := LifecycleRule{
  1129  		ID:                   "r3",
  1130  		Prefix:               "prefix3",
  1131  		Status:               "Enabled",
  1132  		Expiration:           &expiration,
  1133  		AbortMultipartUpload: &abortMPU,
  1134  		NonVersionTransitions: []LifecycleVersionTransition{
  1135  			{
  1136  				NoncurrentDays:       10,
  1137  				StorageClass:         StorageIA,
  1138  				IsAccessTime:         &isTrue,
  1139  				ReturnToStdWhenVisit: &isFalse,
  1140  			},
  1141  		},
  1142  	}
  1143  	tag := Tag{
  1144  		Key:   "key1",
  1145  		Value: "val1",
  1146  	}
  1147  	filter3 := LifecycleFilter{
  1148  		ObjectSizeGreaterThan: &greater,
  1149  		ObjectSizeLessThan:    &less,
  1150  		Not: []LifecycleFilterNot{
  1151  			{
  1152  				Tag: &tag,
  1153  			},
  1154  		},
  1155  	}
  1156  	rule3 := LifecycleRule{
  1157  		ID:                   "r4",
  1158  		Prefix:               "",
  1159  		Status:               "Enabled",
  1160  		Expiration:           &expiration,
  1161  		AbortMultipartUpload: &abortMPU,
  1162  		NonVersionTransitions: []LifecycleVersionTransition{
  1163  			{
  1164  				NoncurrentDays:       10,
  1165  				StorageClass:         StorageIA,
  1166  				IsAccessTime:         &isTrue,
  1167  				ReturnToStdWhenVisit: &isFalse,
  1168  			},
  1169  		},
  1170  		Filter: &filter3,
  1171  	}
  1172  	rules := []LifecycleRule{rule0, rule1, rule2, rule3}
  1173  	config := LifecycleConfiguration{
  1174  		Rules: rules,
  1175  	}
  1176  	xmlData, err := xml.Marshal(config)
  1177  	testLogger.Println(string(xmlData))
  1178  	c.Assert(err, IsNil)
  1179  	c.Assert(string(xmlData), Equals, "<LifecycleConfiguration><Rule><ID>r0</ID><Prefix>prefix0</Prefix><Status>Enabled</Status><Expiration><Days>30</Days><CreatedBeforeDate>2015-11-11T00:00:00.000Z</CreatedBeforeDate></Expiration></Rule><Rule><ID>r1</ID><Prefix>prefix1</Prefix><Status>Enabled</Status><Expiration><Days>30</Days><CreatedBeforeDate>2015-11-11T00:00:00.000Z</CreatedBeforeDate></Expiration><Transition><Days>30</Days><StorageClass>IA</StorageClass><IsAccessTime>false</IsAccessTime></Transition><Filter><ObjectSizeGreaterThan>500</ObjectSizeGreaterThan><ObjectSizeLessThan>645000</ObjectSizeLessThan></Filter></Rule><Rule><ID>r3</ID><Prefix>prefix3</Prefix><Status>Enabled</Status><Expiration><Days>30</Days><CreatedBeforeDate>2015-11-11T00:00:00.000Z</CreatedBeforeDate></Expiration><AbortMultipartUpload><Days>30</Days><CreatedBeforeDate>2015-11-11T00:00:00.000Z</CreatedBeforeDate></AbortMultipartUpload><NoncurrentVersionTransition><NoncurrentDays>10</NoncurrentDays><StorageClass>IA</StorageClass><IsAccessTime>true</IsAccessTime><ReturnToStdWhenVisit>false</ReturnToStdWhenVisit></NoncurrentVersionTransition></Rule><Rule><ID>r4</ID><Prefix></Prefix><Status>Enabled</Status><Expiration><Days>30</Days><CreatedBeforeDate>2015-11-11T00:00:00.000Z</CreatedBeforeDate></Expiration><AbortMultipartUpload><Days>30</Days><CreatedBeforeDate>2015-11-11T00:00:00.000Z</CreatedBeforeDate></AbortMultipartUpload><NoncurrentVersionTransition><NoncurrentDays>10</NoncurrentDays><StorageClass>IA</StorageClass><IsAccessTime>true</IsAccessTime><ReturnToStdWhenVisit>false</ReturnToStdWhenVisit></NoncurrentVersionTransition><Filter><Not><Prefix></Prefix><Tag><Key>key1</Key><Value>val1</Value></Tag></Not><ObjectSizeGreaterThan>500</ObjectSizeGreaterThan><ObjectSizeLessThan>645000</ObjectSizeLessThan></Filter></Rule></LifecycleConfiguration>")
  1180  
  1181  	filter4 := LifecycleFilter{
  1182  		ObjectSizeGreaterThan: &greater,
  1183  		ObjectSizeLessThan:    &less,
  1184  		Not: []LifecycleFilterNot{
  1185  			{},
  1186  		},
  1187  	}
  1188  	rule4 := LifecycleRule{
  1189  		ID:         "r5",
  1190  		Prefix:     "",
  1191  		Status:     "Enabled",
  1192  		Expiration: &expiration,
  1193  		Filter:     &filter4,
  1194  	}
  1195  	rules4 := []LifecycleRule{rule4}
  1196  	config4 := LifecycleConfiguration{
  1197  		Rules: rules4,
  1198  	}
  1199  	xmlData4, err := xml.Marshal(config4)
  1200  	testLogger.Println(string(xmlData4))
  1201  	c.Assert(err, IsNil)
  1202  	c.Assert(string(xmlData4), Equals, "<LifecycleConfiguration><Rule><ID>r5</ID><Prefix></Prefix><Status>Enabled</Status><Expiration><Days>30</Days><CreatedBeforeDate>2015-11-11T00:00:00.000Z</CreatedBeforeDate></Expiration><Filter><Not><Prefix></Prefix></Not><ObjectSizeGreaterThan>500</ObjectSizeGreaterThan><ObjectSizeLessThan>645000</ObjectSizeLessThan></Filter></Rule></LifecycleConfiguration>")
  1203  }
  1204  
  1205  // Test Bucket Resource Group
  1206  func (s *OssTypeSuite) TestBucketResourceGroup(c *C) {
  1207  	var res GetBucketResourceGroupResult
  1208  	xmlData := []byte(`<?xml version="1.0" encoding="UTF-8"?>
  1209  <BucketResourceGroupConfiguration>
  1210    <ResourceGroupId>rg-xxxxxx</ResourceGroupId>
  1211  </BucketResourceGroupConfiguration>`)
  1212  	err := xml.Unmarshal(xmlData, &res)
  1213  	c.Assert(err, IsNil)
  1214  	c.Assert(res.ResourceGroupId, Equals, "rg-xxxxxx")
  1215  
  1216  	xmlData = []byte(`<?xml version="1.0" encoding="UTF-8"?>
  1217  <BucketResourceGroupConfiguration>
  1218    <ResourceGroupId></ResourceGroupId>
  1219  </BucketResourceGroupConfiguration>`)
  1220  	err = xml.Unmarshal(xmlData, &res)
  1221  	c.Assert(err, IsNil)
  1222  	c.Assert(res.ResourceGroupId, Equals, "")
  1223  
  1224  	resource := PutBucketResourceGroup{
  1225  		ResourceGroupId: "rg-xxxxxx",
  1226  	}
  1227  
  1228  	bs, err := xml.Marshal(resource)
  1229  	c.Assert(err, IsNil)
  1230  
  1231  	c.Assert(string(bs), Equals, "<BucketResourceGroupConfiguration><ResourceGroupId>rg-xxxxxx</ResourceGroupId></BucketResourceGroupConfiguration>")
  1232  
  1233  	resource = PutBucketResourceGroup{
  1234  		ResourceGroupId: "",
  1235  	}
  1236  
  1237  	bs, err = xml.Marshal(resource)
  1238  	c.Assert(err, IsNil)
  1239  
  1240  	c.Assert(string(bs), Equals, "<BucketResourceGroupConfiguration><ResourceGroupId></ResourceGroupId></BucketResourceGroupConfiguration>")
  1241  }
  1242  
  1243  func (s *OssTypeSuite) TestListBucketCnameResult(c *C) {
  1244  	xmlData := []byte(`<?xml version="1.0" encoding="UTF-8"?>
  1245  <ListCnameResult>
  1246    <Bucket>targetbucket</Bucket>
  1247    <Owner>testowner</Owner>
  1248    <Cname>
  1249      <Domain>example.com</Domain>
  1250      <LastModified>2021-09-15T02:35:07.000Z</LastModified>
  1251      <Status>Enabled</Status>
  1252      <Certificate>
  1253        <Type>CAS</Type>
  1254        <CertId>493****-cn-hangzhou</CertId>
  1255        <Status>Enabled</Status>
  1256        <CreationDate>Wed, 15 Sep 2021 02:35:06 GMT</CreationDate>
  1257        <Fingerprint>DE:01:CF:EC:7C:A7:98:CB:D8:6E:FB:1D:97:EB:A9:64:1D:4E:**:**</Fingerprint>
  1258        <ValidStartDate>Tue, 12 Apr 2021 10:14:51 GMT</ValidStartDate>
  1259        <ValidEndDate>Mon, 4 May 2048 10:14:51 GMT</ValidEndDate>
  1260      </Certificate>
  1261    </Cname>
  1262    <Cname>
  1263      <Domain>example.org</Domain>
  1264      <LastModified>2021-09-15T02:34:58.000Z</LastModified>
  1265      <Status>Enabled</Status>
  1266    </Cname>
  1267    <Cname>
  1268      <Domain>example.edu</Domain>
  1269      <LastModified>2021-09-15T02:50:34.000Z</LastModified>
  1270      <Status>Enabled</Status>
  1271    </Cname>
  1272  </ListCnameResult>`)
  1273  	var res ListBucketCnameResult
  1274  	err := xml.Unmarshal(xmlData, &res)
  1275  	c.Assert(err, IsNil)
  1276  	c.Assert(res.Bucket, Equals, "targetbucket")
  1277  	c.Assert(res.Owner, Equals, "testowner")
  1278  	c.Assert(res.Cname[0].Domain, Equals, "example.com")
  1279  	c.Assert(res.Cname[0].LastModified, Equals, "2021-09-15T02:35:07.000Z")
  1280  	c.Assert(res.Cname[0].Status, Equals, "Enabled")
  1281  	c.Assert(res.Cname[0].Certificate.Type, Equals, "CAS")
  1282  	c.Assert(res.Cname[0].Certificate.CreationDate, Equals, "Wed, 15 Sep 2021 02:35:06 GMT")
  1283  	c.Assert(res.Cname[0].Certificate.ValidEndDate, Equals, "Mon, 4 May 2048 10:14:51 GMT")
  1284  	c.Assert(res.Cname[1].LastModified, Equals, "2021-09-15T02:34:58.000Z")
  1285  	c.Assert(res.Cname[1].Domain, Equals, "example.org")
  1286  
  1287  	c.Assert(res.Cname[2].Domain, Equals, "example.edu")
  1288  	c.Assert(res.Cname[2].LastModified, Equals, "2021-09-15T02:50:34.000Z")
  1289  
  1290  }
  1291  
  1292  func (s *OssTypeSuite) TestPutBucketCname(c *C) {
  1293  	var putCnameConfig PutBucketCname
  1294  	putCnameConfig.Cname = "www.aliyun.com"
  1295  
  1296  	bs, err := xml.Marshal(putCnameConfig)
  1297  	c.Assert(err, IsNil)
  1298  	c.Assert(string(bs), Equals, "<BucketCnameConfiguration><Cname><Domain>www.aliyun.com</Domain></Cname></BucketCnameConfiguration>")
  1299  	certificate := "-----BEGIN CERTIFICATE----- MIIDhDCCAmwCCQCFs8ixARsyrDANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMC **** -----END CERTIFICATE-----"
  1300  	privateKey := "-----BEGIN CERTIFICATE----- MIIDhDCCAmwCCQCFs8ixARsyrDANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMC **** -----END CERTIFICATE-----"
  1301  	var CertificateConfig CertificateConfiguration
  1302  	CertificateConfig.CertId = "493****-cn-hangzhou"
  1303  	CertificateConfig.Certificate = certificate
  1304  	CertificateConfig.PrivateKey = privateKey
  1305  	CertificateConfig.Force = true
  1306  	putCnameConfig.CertificateConfiguration = &CertificateConfig
  1307  
  1308  	bs, err = xml.Marshal(putCnameConfig)
  1309  	c.Assert(err, IsNil)
  1310  
  1311  	testLogger.Println(string(bs))
  1312  	c.Assert(string(bs), Equals, "<BucketCnameConfiguration><Cname><Domain>www.aliyun.com</Domain><CertificateConfiguration><CertId>493****-cn-hangzhou</CertId><Certificate>-----BEGIN CERTIFICATE----- MIIDhDCCAmwCCQCFs8ixARsyrDANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMC **** -----END CERTIFICATE-----</Certificate><PrivateKey>-----BEGIN CERTIFICATE----- MIIDhDCCAmwCCQCFs8ixARsyrDANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMC **** -----END CERTIFICATE-----</PrivateKey><Force>true</Force></CertificateConfiguration></Cname></BucketCnameConfiguration>")
  1313  
  1314  	var config CertificateConfiguration
  1315  	config.DeleteCertificate = true
  1316  	putCnameConfig2 := PutBucketCname{
  1317  		Cname:                    "www.aliyun.com",
  1318  		CertificateConfiguration: &config,
  1319  	}
  1320  
  1321  	bs, err = xml.Marshal(putCnameConfig2)
  1322  	c.Assert(err, IsNil)
  1323  	c.Assert(string(bs), Equals, "<BucketCnameConfiguration><Cname><Domain>www.aliyun.com</Domain><CertificateConfiguration><DeleteCertificate>true</DeleteCertificate></CertificateConfiguration></Cname></BucketCnameConfiguration>")
  1324  }
  1325  
  1326  // Test Bucket Style
  1327  func (s *OssTypeSuite) TestBucketStyle(c *C) {
  1328  	var res GetBucketStyleResult
  1329  	xmlData := []byte(`<?xml version="1.0" encoding="UTF-8"?>
  1330  <Style>
  1331   <Name>imageStyle</Name>
  1332   <Content>image/resize,p_50</Content>
  1333   <CreateTime>Wed, 20 May 2020 12:07:15 GMT</CreateTime>
  1334   <LastModifyTime>Wed, 21 May 2020 12:07:15 GMT</LastModifyTime>
  1335  </Style>`)
  1336  	err := xml.Unmarshal(xmlData, &res)
  1337  	c.Assert(err, IsNil)
  1338  	c.Assert(res.Name, Equals, "imageStyle")
  1339  	c.Assert(res.Content, Equals, "image/resize,p_50")
  1340  	c.Assert(res.CreateTime, Equals, "Wed, 20 May 2020 12:07:15 GMT")
  1341  	c.Assert(res.LastModifyTime, Equals, "Wed, 21 May 2020 12:07:15 GMT")
  1342  
  1343  	var list GetBucketListStyleResult
  1344  	xmlData = []byte(`<?xml version="1.0" encoding="UTF-8"?>
  1345  <StyleList>
  1346   <Style>
  1347   <Name>imageStyle</Name>
  1348   <Content>image/resize,p_50</Content>
  1349   <CreateTime>Wed, 20 May 2020 12:07:15 GMT</CreateTime>
  1350   <LastModifyTime>Wed, 21 May 2020 12:07:15 GMT</LastModifyTime>
  1351   </Style>
  1352   <Style>
  1353   <Name>imageStyle1</Name>
  1354   <Content>image/resize,w_200</Content>
  1355   <CreateTime>Wed, 20 May 2020 12:08:04 GMT</CreateTime>
  1356   <LastModifyTime>Wed, 21 May 2020 12:08:04 GMT</LastModifyTime>
  1357   </Style>
  1358   <Style>
  1359   <Name>imageStyle3</Name>
  1360   <Content>image/resize,w_300</Content>
  1361   <CreateTime>Fri, 12 Mar 2021 06:19:13 GMT</CreateTime>
  1362   <LastModifyTime>Fri, 13 Mar 2021 06:27:21 GMT</LastModifyTime>
  1363   </Style>
  1364  </StyleList>`)
  1365  	err = xml.Unmarshal(xmlData, &list)
  1366  	c.Assert(err, IsNil)
  1367  	c.Assert(list.Style[0].Name, Equals, "imageStyle")
  1368  	c.Assert(list.Style[0].Content, Equals, "image/resize,p_50")
  1369  	c.Assert(list.Style[0].CreateTime, Equals, "Wed, 20 May 2020 12:07:15 GMT")
  1370  	c.Assert(list.Style[0].LastModifyTime, Equals, "Wed, 21 May 2020 12:07:15 GMT")
  1371  
  1372  	c.Assert(err, IsNil)
  1373  	c.Assert(list.Style[1].Name, Equals, "imageStyle1")
  1374  	c.Assert(list.Style[2].Content, Equals, "image/resize,w_300")
  1375  	c.Assert(list.Style[1].CreateTime, Equals, "Wed, 20 May 2020 12:08:04 GMT")
  1376  	c.Assert(list.Style[2].LastModifyTime, Equals, "Fri, 13 Mar 2021 06:27:21 GMT")
  1377  }
  1378  
  1379  func (s *OssTypeSuite) TestBucketReplication(c *C) {
  1380  	// case 1:test PutBucketReplication
  1381  	enabled := "enabled"
  1382  	prefix1 := "prefix_1"
  1383  	prefix2 := "prefix_2"
  1384  	keyId := "c4d49f85-ee30-426b-a5ed-95e9139d"
  1385  	prefixSet := ReplicationRulePrefix{[]*string{&prefix1, &prefix2}}
  1386  	reqReplication := PutBucketReplication{
  1387  		Rule: []ReplicationRule{
  1388  			{
  1389  				RTC:       &enabled,
  1390  				PrefixSet: &prefixSet,
  1391  				Action:    "all",
  1392  				Destination: &ReplicationRuleDestination{
  1393  					Bucket:       "srcBucket",
  1394  					Location:     "oss-cn-hangzhou",
  1395  					TransferType: "oss_acc",
  1396  				},
  1397  				HistoricalObjectReplication: "disabled",
  1398  			},
  1399  		},
  1400  	}
  1401  	xmlData, err := xml.Marshal(reqReplication)
  1402  	c.Assert(err, IsNil)
  1403  	c.Assert(string(xmlData), Equals, "<ReplicationConfiguration><Rule><RTC><Status>enabled</Status></RTC><PrefixSet><Prefix>prefix_1</Prefix><Prefix>prefix_2</Prefix></PrefixSet><Action>all</Action><Destination><Bucket>srcBucket</Bucket><Location>oss-cn-hangzhou</Location><TransferType>oss_acc</TransferType></Destination><HistoricalObjectReplication>disabled</HistoricalObjectReplication></Rule></ReplicationConfiguration>")
  1404  
  1405  	prefixSet = ReplicationRulePrefix{[]*string{&prefix1, &prefix2}}
  1406  	reqReplication = PutBucketReplication{
  1407  		Rule: []ReplicationRule{
  1408  			{
  1409  				RTC:       &enabled,
  1410  				PrefixSet: &prefixSet,
  1411  				Action:    "all",
  1412  				Destination: &ReplicationRuleDestination{
  1413  					Bucket:       "srcBucket",
  1414  					Location:     "oss-cn-hangzhou",
  1415  					TransferType: "oss_acc",
  1416  				},
  1417  				HistoricalObjectReplication: "disabled",
  1418  				SyncRole:                    "aliyunramrole",
  1419  				SourceSelectionCriteria:     &enabled,
  1420  				EncryptionConfiguration:     &keyId,
  1421  			},
  1422  		},
  1423  	}
  1424  	xmlData, err = xml.Marshal(reqReplication)
  1425  	testLogger.Println(string(xmlData))
  1426  	c.Assert(err, IsNil)
  1427  	c.Assert(string(xmlData), Equals, "<ReplicationConfiguration><Rule><RTC><Status>enabled</Status></RTC><PrefixSet><Prefix>prefix_1</Prefix><Prefix>prefix_2</Prefix></PrefixSet><Action>all</Action><Destination><Bucket>srcBucket</Bucket><Location>oss-cn-hangzhou</Location><TransferType>oss_acc</TransferType></Destination><HistoricalObjectReplication>disabled</HistoricalObjectReplication><SyncRole>aliyunramrole</SyncRole><SourceSelectionCriteria><SseKmsEncryptedObjects><Status>enabled</Status></SseKmsEncryptedObjects></SourceSelectionCriteria><EncryptionConfiguration><ReplicaKmsKeyID>c4d49f85-ee30-426b-a5ed-95e9139d</ReplicaKmsKeyID></EncryptionConfiguration></Rule></ReplicationConfiguration>")
  1428  
  1429  	reqReplication = PutBucketReplication{
  1430  		Rule: []ReplicationRule{
  1431  			{},
  1432  		},
  1433  	}
  1434  
  1435  	xmlData, err = xml.Marshal(reqReplication)
  1436  	testLogger.Println(string(xmlData))
  1437  	c.Assert(err, IsNil)
  1438  	c.Assert(string(xmlData), Equals, "<ReplicationConfiguration><Rule></Rule></ReplicationConfiguration>")
  1439  
  1440  	reqReplication = PutBucketReplication{
  1441  		Rule: []ReplicationRule{},
  1442  	}
  1443  
  1444  	xmlData, err = xml.Marshal(reqReplication)
  1445  	c.Assert(err, IsNil)
  1446  	c.Assert(string(xmlData), Equals, "<ReplicationConfiguration></ReplicationConfiguration>")
  1447  
  1448  	reqReplication = PutBucketReplication{}
  1449  
  1450  	xmlData, err = xml.Marshal(reqReplication)
  1451  	c.Assert(err, IsNil)
  1452  	c.Assert(string(xmlData), Equals, "<ReplicationConfiguration></ReplicationConfiguration>")
  1453  
  1454  	// case 2: test GetBucketReplicationResult
  1455  	xmlData = []byte(`<?xml version="1.0" encoding="UTF-8"?>
  1456  <ReplicationConfiguration>
  1457    <Rule>
  1458      <ID>test_replication_1</ID>
  1459      <PrefixSet>
  1460        <Prefix>source1</Prefix>
  1461        <Prefix>video</Prefix>
  1462      </PrefixSet>
  1463      <Action>PUT</Action>
  1464      <Destination>
  1465        <Bucket>destbucket</Bucket>
  1466        <Location>oss-cn-beijing</Location>
  1467        <TransferType>oss_acc</TransferType>
  1468      </Destination>
  1469      <Status>doing</Status>
  1470      <HistoricalObjectReplication>enabled</HistoricalObjectReplication>
  1471      <SyncRole>aliyunramrole</SyncRole>
  1472      <RTC>
  1473        <Status>enabled</Status>
  1474      </RTC>
  1475  	<SourceSelectionCriteria>
  1476           <SseKmsEncryptedObjects>
  1477             <Status>Enabled</Status>
  1478           </SseKmsEncryptedObjects>
  1479        </SourceSelectionCriteria>
  1480        <EncryptionConfiguration>
  1481             <ReplicaKmsKeyID>c4d49f85-ee30-426b-a5ed-95e9139d****</ReplicaKmsKeyID>
  1482        </EncryptionConfiguration>
  1483    </Rule>
  1484  </ReplicationConfiguration>`)
  1485  	var reqResult GetBucketReplicationResult
  1486  	err = xml.Unmarshal(xmlData, &reqResult)
  1487  	c.Assert(err, IsNil)
  1488  	rule := reqResult.Rule[0]
  1489  	c.Assert(rule.ID, Equals, "test_replication_1")
  1490  	c.Assert(*rule.PrefixSet.Prefix[0], Equals, "source1")
  1491  	c.Assert(*rule.PrefixSet.Prefix[1], Equals, "video")
  1492  	c.Assert(rule.Action, Equals, "PUT")
  1493  	c.Assert(rule.Destination.Bucket, Equals, "destbucket")
  1494  	c.Assert(rule.Destination.Location, Equals, "oss-cn-beijing")
  1495  	c.Assert(rule.Destination.TransferType, Equals, "oss_acc")
  1496  
  1497  	c.Assert(rule.Status, Equals, "doing")
  1498  	c.Assert(rule.HistoricalObjectReplication, Equals, "enabled")
  1499  	c.Assert(rule.SyncRole, Equals, "aliyunramrole")
  1500  	c.Assert(*rule.RTC, Equals, "enabled")
  1501  
  1502  	c.Assert(*rule.SourceSelectionCriteria, Equals, "Enabled")
  1503  	c.Assert(*rule.EncryptionConfiguration, Equals, "c4d49f85-ee30-426b-a5ed-95e9139d****")
  1504  }
  1505  
  1506  func (s *OssTypeSuite) TestBucketRtc(c *C) {
  1507  	enabled := "enabled"
  1508  	id := "300c8809-fe50-4966-bbfa-******"
  1509  	reqRtc := PutBucketRTC{
  1510  		RTC: &enabled,
  1511  		ID:  id,
  1512  	}
  1513  
  1514  	xmlData, err := xml.Marshal(reqRtc)
  1515  	c.Assert(err, IsNil)
  1516  	c.Assert(string(xmlData), Equals, "<ReplicationRule><RTC><Status>enabled</Status></RTC><ID>300c8809-fe50-4966-bbfa-******</ID></ReplicationRule>")
  1517  
  1518  	reqRtc = PutBucketRTC{}
  1519  	xmlData, err = xml.Marshal(reqRtc)
  1520  	c.Assert(err, IsNil)
  1521  	c.Assert(string(xmlData), Equals, "<ReplicationRule></ReplicationRule>")
  1522  }
  1523  
  1524  func (s *OssTypeSuite) TestGetBucketReplicationLocationResult(c *C) {
  1525  	xmlData := `<?xml version="1.0" encoding="UTF-8"?>
  1526  <ReplicationLocation>
  1527    <Location>oss-ap-northeast-1</Location>
  1528    <Location>oss-ap-northeast-2</Location>
  1529    <Location>oss-ap-south-1</Location>
  1530    <Location>oss-ap-southeast-1</Location>
  1531    <Location>oss-ap-southeast-2</Location>
  1532    <Location>oss-ap-southeast-3</Location>
  1533    <Location>oss-ap-southeast-5</Location>
  1534    <Location>oss-ap-southeast-6</Location>
  1535    <Location>oss-ap-southeast-7</Location>
  1536    <Location>oss-cn-beijing</Location>
  1537    <Location>oss-cn-chengdu</Location>
  1538    <Location>oss-cn-fuzhou</Location>
  1539    <Location>oss-cn-guangzhou</Location>
  1540    <Location>oss-cn-heyuan</Location>
  1541    <Location>oss-cn-hongkong</Location>
  1542    <Location>oss-cn-huhehaote</Location>
  1543    <Location>oss-cn-nanjing</Location>
  1544    <Location>oss-cn-qingdao</Location>
  1545    <Location>oss-cn-shanghai</Location>
  1546    <Location>oss-cn-shenzhen</Location>
  1547    <Location>oss-cn-wulanchabu</Location>
  1548    <Location>oss-cn-zhangjiakou</Location>
  1549    <Location>oss-eu-central-1</Location>
  1550    <Location>oss-eu-west-1</Location>
  1551    <Location>oss-me-central-1</Location>
  1552    <Location>oss-me-east-1</Location>
  1553    <Location>oss-rus-west-1</Location>
  1554    <Location>oss-us-east-1</Location>
  1555    <Location>oss-us-west-1</Location>
  1556    <LocationTransferTypeConstraint>
  1557      <LocationTransferType>
  1558        <Location>oss-cn-hongkong</Location>
  1559        <TransferTypes>
  1560          <Type>oss_acc</Type>
  1561        </TransferTypes>
  1562      </LocationTransferType>
  1563      <LocationTransferType>
  1564        <Location>oss-eu-central-1</Location>
  1565        <TransferTypes>
  1566          <Type>oss_acc</Type>
  1567        </TransferTypes>
  1568      </LocationTransferType>
  1569      <LocationTransferType>
  1570        <Location>oss-ap-southeast-7</Location>
  1571        <TransferTypes>
  1572          <Type>oss_acc</Type>
  1573        </TransferTypes>
  1574      </LocationTransferType>
  1575      <LocationTransferType>
  1576        <Location>oss-ap-southeast-6</Location>
  1577        <TransferTypes>
  1578          <Type>oss_acc</Type>
  1579        </TransferTypes>
  1580      </LocationTransferType>
  1581      <LocationTransferType>
  1582        <Location>oss-ap-southeast-5</Location>
  1583        <TransferTypes>
  1584          <Type>oss_acc</Type>
  1585        </TransferTypes>
  1586      </LocationTransferType>
  1587      <LocationTransferType>
  1588        <Location>oss-eu-west-1</Location>
  1589        <TransferTypes>
  1590          <Type>oss_acc</Type>
  1591        </TransferTypes>
  1592      </LocationTransferType>
  1593      <LocationTransferType>
  1594        <Location>oss-rus-west-1</Location>
  1595        <TransferTypes>
  1596          <Type>oss_acc</Type>
  1597        </TransferTypes>
  1598      </LocationTransferType>
  1599      <LocationTransferType>
  1600        <Location>oss-ap-southeast-2</Location>
  1601        <TransferTypes>
  1602          <Type>oss_acc</Type>
  1603        </TransferTypes>
  1604      </LocationTransferType>
  1605      <LocationTransferType>
  1606        <Location>oss-ap-southeast-1</Location>
  1607        <TransferTypes>
  1608          <Type>oss_acc</Type>
  1609        </TransferTypes>
  1610      </LocationTransferType>
  1611      <LocationTransferType>
  1612        <Location>oss-me-central-1</Location>
  1613        <TransferTypes>
  1614          <Type>oss_acc</Type>
  1615        </TransferTypes>
  1616      </LocationTransferType>
  1617      <LocationTransferType>
  1618        <Location>oss-ap-south-1</Location>
  1619        <TransferTypes>
  1620          <Type>oss_acc</Type>
  1621        </TransferTypes>
  1622      </LocationTransferType>
  1623      <LocationTransferType>
  1624        <Location>oss-us-east-1</Location>
  1625        <TransferTypes>
  1626          <Type>oss_acc</Type>
  1627        </TransferTypes>
  1628      </LocationTransferType>
  1629      <LocationTransferType>
  1630        <Location>oss-ap-northeast-1</Location>
  1631        <TransferTypes>
  1632          <Type>oss_acc</Type>
  1633        </TransferTypes>
  1634      </LocationTransferType>
  1635      <LocationTransferType>
  1636        <Location>oss-me-east-1</Location>
  1637        <TransferTypes>
  1638          <Type>oss_acc</Type>
  1639        </TransferTypes>
  1640      </LocationTransferType>
  1641      <LocationTransferType>
  1642        <Location>oss-ap-northeast-2</Location>
  1643        <TransferTypes>
  1644          <Type>oss_acc</Type>
  1645        </TransferTypes>
  1646      </LocationTransferType>
  1647      <LocationTransferType>
  1648        <Location>oss-ap-southeast-3</Location>
  1649        <TransferTypes>
  1650          <Type>oss_acc</Type>
  1651        </TransferTypes>
  1652      </LocationTransferType>
  1653      <LocationTransferType>
  1654        <Location>oss-us-west-1</Location>
  1655        <TransferTypes>
  1656          <Type>oss_acc</Type>
  1657        </TransferTypes>
  1658      </LocationTransferType>
  1659    </LocationTransferTypeConstraint>
  1660    <LocationRTCConstraint>
  1661      <Location>oss-cn-beijing</Location>
  1662      <Location>oss-cn-qingdao</Location>
  1663      <Location>oss-cn-shanghai</Location>
  1664      <Location>oss-cn-shenzhen</Location>
  1665      <Location>oss-cn-zhangjiakou</Location>
  1666    </LocationRTCConstraint>
  1667  </ReplicationLocation>`
  1668  	var repResult GetBucketReplicationLocationResult
  1669  	err := xmlUnmarshal(strings.NewReader(xmlData), &repResult)
  1670  	c.Assert(err, IsNil)
  1671  	c.Assert(repResult.Location[0], Equals, "oss-ap-northeast-1")
  1672  	c.Assert(repResult.Location[9], Equals, "oss-cn-beijing")
  1673  	testLogger.Println(repResult.LocationTransferType[1].Location)
  1674  	c.Assert(repResult.LocationTransferType[1].Location, Equals, "oss-eu-central-1")
  1675  	c.Assert(repResult.LocationTransferType[1].TransferTypes, Equals, "oss_acc")
  1676  	c.Assert(repResult.RTCLocation[2], Equals, "oss-cn-shanghai")
  1677  }
  1678  
  1679  func (s *OssTypeSuite) TestGetBucketReplicationProgressResult(c *C) {
  1680  	xmlData := `<?xml version="1.0" encoding="UTF-8"?>
  1681  <ReplicationProgress>
  1682   <Rule>
  1683     <ID>test_replication_1</ID>
  1684     <PrefixSet>
  1685      <Prefix>source_image</Prefix>
  1686      <Prefix>video</Prefix>
  1687     </PrefixSet>
  1688     <Action>PUT</Action>
  1689     <Destination>
  1690      <Bucket>target-bucket</Bucket>
  1691      <Location>oss-cn-beijing</Location>
  1692      <TransferType>oss_acc</TransferType>
  1693     </Destination>
  1694     <Status>doing</Status>
  1695     <HistoricalObjectReplication>enabled</HistoricalObjectReplication>
  1696     <Progress>
  1697      <HistoricalObject>0.85</HistoricalObject>
  1698      <NewObject>2015-09-24T15:28:14.000Z</NewObject>
  1699     </Progress>
  1700   </Rule>
  1701  </ReplicationProgress>`
  1702  	var repResult GetBucketReplicationProgressResult
  1703  	err := xmlUnmarshal(strings.NewReader(xmlData), &repResult)
  1704  	c.Assert(err, IsNil)
  1705  	c.Assert(repResult.Rule[0].ID, Equals, "test_replication_1")
  1706  	c.Assert(*repResult.Rule[0].PrefixSet.Prefix[0], Equals, "source_image")
  1707  	c.Assert(*repResult.Rule[0].PrefixSet.Prefix[1], Equals, "video")
  1708  	c.Assert(repResult.Rule[0].Action, Equals, "PUT")
  1709  	c.Assert(repResult.Rule[0].Destination.Bucket, Equals, "target-bucket")
  1710  	c.Assert(repResult.Rule[0].Destination.Location, Equals, "oss-cn-beijing")
  1711  	c.Assert(repResult.Rule[0].Destination.TransferType, Equals, "oss_acc")
  1712  	c.Assert(repResult.Rule[0].Status, Equals, "doing")
  1713  	c.Assert(repResult.Rule[0].HistoricalObjectReplication, Equals, "enabled")
  1714  	c.Assert((*repResult.Rule[0].Progress).HistoricalObject, Equals, "0.85")
  1715  	c.Assert((*repResult.Rule[0].Progress).NewObject, Equals, "2015-09-24T15:28:14.000Z")
  1716  }
  1717  
  1718  func (s *OssTypeSuite) TestGetBucketRefererResult(c *C) {
  1719  	xmlData := `<?xml version="1.0" encoding="UTF-8"?>
  1720  <RefererConfiguration>
  1721    <AllowEmptyReferer>true</AllowEmptyReferer>
  1722    <RefererList>
  1723    </RefererList>
  1724  </RefererConfiguration>`
  1725  	var repResult GetBucketRefererResult
  1726  	err := xmlUnmarshal(strings.NewReader(xmlData), &repResult)
  1727  	c.Assert(err, IsNil)
  1728  	c.Assert(repResult.AllowEmptyReferer, Equals, true)
  1729  	c.Assert(repResult.AllowTruncateQueryString, IsNil)
  1730  	c.Assert(repResult.RefererList, IsNil)
  1731  	c.Assert(repResult.RefererBlacklist, IsNil)
  1732  
  1733  	xmlData = `<?xml version="1.0" encoding="UTF-8"?>
  1734  <RefererConfiguration>
  1735  <AllowEmptyReferer>true</AllowEmptyReferer>
  1736  <AllowTruncateQueryString>false</AllowTruncateQueryString>
  1737      <RefererList>
  1738          <Referer>http://www.aliyun.com</Referer>
  1739          <Referer>https://www.aliyun.com</Referer>
  1740          <Referer>http://www.*.com</Referer>
  1741          <Referer>https://www.?.aliyuncs.com</Referer>
  1742      </RefererList>
  1743  </RefererConfiguration>`
  1744  
  1745  	var repResult0 GetBucketRefererResult
  1746  	err = xmlUnmarshal(strings.NewReader(xmlData), &repResult0)
  1747  	c.Assert(err, IsNil)
  1748  	c.Assert(repResult0.AllowEmptyReferer, Equals, true)
  1749  	c.Assert(*repResult0.AllowTruncateQueryString, Equals, false)
  1750  	c.Assert(len(repResult0.RefererList), Equals, 4)
  1751  	c.Assert(repResult0.RefererList[1], Equals, "https://www.aliyun.com")
  1752  	c.Assert(repResult0.RefererBlacklist, IsNil)
  1753  
  1754  	xmlData = `<?xml version="1.0" encoding="UTF-8"?>
  1755  <RefererConfiguration>
  1756    <AllowEmptyReferer>false</AllowEmptyReferer>
  1757    <AllowTruncateQueryString>false</AllowTruncateQueryString>
  1758    <RefererList>
  1759          <Referer>http://www.aliyun.com</Referer>
  1760          <Referer>https://www.aliyun.com</Referer>
  1761          <Referer>http://www.*.com</Referer>
  1762          <Referer>https://www.?.aliyuncs.com</Referer>
  1763    </RefererList>
  1764    <RefererBlacklist>
  1765          <Referer>http://www.refuse.com</Referer>
  1766          <Referer>https://*.hack.com</Referer>
  1767          <Referer>http://ban.*.com</Referer>
  1768      	  <Referer>https://www.?.deny.com</Referer>
  1769    </RefererBlacklist>
  1770  </RefererConfiguration>`
  1771  	var repResult1 GetBucketRefererResult
  1772  	err = xmlUnmarshal(strings.NewReader(xmlData), &repResult1)
  1773  	c.Assert(err, IsNil)
  1774  	c.Assert(repResult1.AllowEmptyReferer, Equals, false)
  1775  	c.Assert(*repResult1.AllowTruncateQueryString, Equals, false)
  1776  	c.Assert(len(repResult1.RefererList), Equals, 4)
  1777  	c.Assert(repResult1.RefererList[3], Equals, "https://www.?.aliyuncs.com")
  1778  
  1779  	c.Assert(len(repResult1.RefererList), Equals, 4)
  1780  	c.Assert((repResult1.RefererBlacklist).Referer[2], Equals, "http://ban.*.com")
  1781  }
  1782  
  1783  func (s *OssTypeSuite) TestRefererXML(c *C) {
  1784  	xmlData := `<RefererConfiguration><AllowEmptyReferer>true</AllowEmptyReferer><RefererList></RefererList></RefererConfiguration>`
  1785  	var setBucketReferer RefererXML
  1786  	setBucketReferer.AllowEmptyReferer = true
  1787  	setBucketReferer.RefererList = []string{}
  1788  	xmlBody, err := xml.Marshal(setBucketReferer)
  1789  	log.Println(string(xmlBody))
  1790  	c.Assert(err, IsNil)
  1791  	c.Assert(string(xmlBody), Equals, xmlData)
  1792  
  1793  	xmlData1 := `<RefererConfiguration><AllowEmptyReferer>true</AllowEmptyReferer><AllowTruncateQueryString>false</AllowTruncateQueryString><RefererList><Referer>http://www.aliyun.com</Referer><Referer>https://www.aliyun.com</Referer><Referer>http://www.*.com</Referer><Referer>https://www.?.aliyuncs.com</Referer></RefererList></RefererConfiguration>`
  1794  
  1795  	setBucketReferer.AllowEmptyReferer = true
  1796  	boolFalse := false
  1797  	setBucketReferer.AllowTruncateQueryString = &boolFalse
  1798  	setBucketReferer.RefererList = []string{
  1799  		"http://www.aliyun.com",
  1800  		"https://www.aliyun.com",
  1801  		"http://www.*.com",
  1802  		"https://www.?.aliyuncs.com",
  1803  	}
  1804  	c.Log(setBucketReferer)
  1805  	xmlBody, err = xml.Marshal(setBucketReferer)
  1806  	c.Assert(err, IsNil)
  1807  	c.Assert(string(xmlBody), Equals, xmlData1)
  1808  
  1809  	xmlData2 := `<RefererConfiguration><AllowEmptyReferer>false</AllowEmptyReferer><AllowTruncateQueryString>false</AllowTruncateQueryString><RefererList><Referer>http://www.aliyun.com</Referer><Referer>https://www.aliyun.com</Referer><Referer>http://www.*.com</Referer><Referer>https://www.?.aliyuncs.com</Referer></RefererList><RefererBlacklist><Referer>http://www.refuse.com</Referer><Referer>https://*.hack.com</Referer><Referer>http://ban.*.com</Referer><Referer>https://www.?.deny.com</Referer></RefererBlacklist></RefererConfiguration>`
  1810  
  1811  	setBucketReferer.AllowEmptyReferer = false
  1812  	setBucketReferer.AllowTruncateQueryString = &boolFalse
  1813  	setBucketReferer.RefererList = []string{
  1814  		"http://www.aliyun.com",
  1815  		"https://www.aliyun.com",
  1816  		"http://www.*.com",
  1817  		"https://www.?.aliyuncs.com",
  1818  	}
  1819  	referer1 := "http://www.refuse.com"
  1820  	referer2 := "https://*.hack.com"
  1821  	referer3 := "http://ban.*.com"
  1822  	referer4 := "https://www.?.deny.com"
  1823  	setBucketReferer.RefererBlacklist = &RefererBlacklist{
  1824  		[]string{
  1825  			referer1, referer2, referer3, referer4,
  1826  		},
  1827  	}
  1828  	xmlBody, err = xml.Marshal(setBucketReferer)
  1829  	c.Assert(err, IsNil)
  1830  	c.Assert(string(xmlBody), Equals, xmlData2)
  1831  }
  1832  
  1833  func (s *OssTypeSuite) TestDescribeRegionsResult(c *C) {
  1834  	xmlData := `<?xml version="1.0" encoding="UTF-8"?>
  1835  <RegionInfoList>
  1836    <RegionInfo>
  1837       <Region>oss-cn-hangzhou</Region>
  1838       <InternetEndpoint>oss-cn-hangzhou.aliyuncs.com</InternetEndpoint>
  1839       <InternalEndpoint>oss-cn-hangzhou-internal.aliyuncs.com</InternalEndpoint>
  1840       <AccelerateEndpoint>oss-accelerate.aliyuncs.com</AccelerateEndpoint>  
  1841    </RegionInfo>
  1842    <RegionInfo>
  1843       <Region>oss-cn-shanghai</Region>
  1844       <InternetEndpoint>oss-cn-shanghai.aliyuncs.com</InternetEndpoint>
  1845       <InternalEndpoint>oss-cn-shanghai-internal.aliyuncs.com</InternalEndpoint>
  1846       <AccelerateEndpoint>oss-accelerate.aliyuncs.com</AccelerateEndpoint>  
  1847    </RegionInfo>
  1848  </RegionInfoList>`
  1849  	var repResult DescribeRegionsResult
  1850  	err := xmlUnmarshal(strings.NewReader(xmlData), &repResult)
  1851  	c.Assert(err, IsNil)
  1852  	c.Assert(repResult.Regions[0].Region, Equals, "oss-cn-hangzhou")
  1853  	c.Assert(repResult.Regions[0].InternetEndpoint, Equals, "oss-cn-hangzhou.aliyuncs.com")
  1854  	c.Assert(repResult.Regions[0].InternalEndpoint, Equals, "oss-cn-hangzhou-internal.aliyuncs.com")
  1855  	c.Assert(repResult.Regions[0].AccelerateEndpoint, Equals, "oss-accelerate.aliyuncs.com")
  1856  
  1857  	c.Assert(repResult.Regions[1].Region, Equals, "oss-cn-shanghai")
  1858  	c.Assert(repResult.Regions[1].InternetEndpoint, Equals, "oss-cn-shanghai.aliyuncs.com")
  1859  	c.Assert(repResult.Regions[1].InternalEndpoint, Equals, "oss-cn-shanghai-internal.aliyuncs.com")
  1860  	c.Assert(repResult.Regions[1].AccelerateEndpoint, Equals, "oss-accelerate.aliyuncs.com")
  1861  }
  1862  
  1863  func (s *OssTypeSuite) TestAsyncProcessResult(c *C) {
  1864  	jsonData := `{"EventId":"10C-1XqxdjCRx3x7gRim3go1yLUVWgm","RequestId":"B8AD6942-BBDE-571D-A9A9-525A4C34B2B3","TaskId":"MediaConvert-58a8f19f-697f-4f8d-ae2c-0d7b15bef68d"}`
  1865  	var repResult AsyncProcessObjectResult
  1866  	err := jsonUnmarshal(strings.NewReader(jsonData), &repResult)
  1867  	c.Assert(err, IsNil)
  1868  	c.Assert(repResult.EventId, Equals, "10C-1XqxdjCRx3x7gRim3go1yLUVWgm")
  1869  	c.Assert(repResult.RequestId, Equals, "B8AD6942-BBDE-571D-A9A9-525A4C34B2B3")
  1870  	c.Assert(repResult.TaskId, Equals, "MediaConvert-58a8f19f-697f-4f8d-ae2c-0d7b15bef68d")
  1871  }
  1872  
  1873  func (s *OssTypeSuite) TestPutResponseHeader(c *C) {
  1874  	reqHeader := PutBucketResponseHeader{
  1875  		Rule: []ResponseHeaderRule{
  1876  			{
  1877  				Name: "name1",
  1878  				Filters: ResponseHeaderRuleFilters{
  1879  					[]string{
  1880  						"Put", "GetObject",
  1881  					},
  1882  				},
  1883  				HideHeaders: ResponseHeaderRuleHeaders{
  1884  					[]string{
  1885  						"Last-Modified",
  1886  					},
  1887  				},
  1888  			},
  1889  		},
  1890  	}
  1891  	xmlData, err := xml.Marshal(reqHeader)
  1892  	c.Assert(err, IsNil)
  1893  	c.Assert(string(xmlData), Equals, "<ResponseHeaderConfiguration><Rule><Name>name1</Name><Filters><Operation>Put</Operation><Operation>GetObject</Operation></Filters><HideHeaders><Header>Last-Modified</Header></HideHeaders></Rule></ResponseHeaderConfiguration>")
  1894  
  1895  	reqHeader = PutBucketResponseHeader{
  1896  		Rule: []ResponseHeaderRule{
  1897  			{
  1898  				Name: "name1",
  1899  				Filters: ResponseHeaderRuleFilters{
  1900  					[]string{
  1901  						"Put", "GetObject",
  1902  					},
  1903  				},
  1904  				HideHeaders: ResponseHeaderRuleHeaders{
  1905  					[]string{
  1906  						"Last-Modified",
  1907  					},
  1908  				},
  1909  			},
  1910  			{
  1911  				Name: "name2",
  1912  				Filters: ResponseHeaderRuleFilters{
  1913  					[]string{
  1914  						"*",
  1915  					},
  1916  				},
  1917  				HideHeaders: ResponseHeaderRuleHeaders{
  1918  					[]string{
  1919  						"Last-Modified",
  1920  					},
  1921  				},
  1922  			},
  1923  		},
  1924  	}
  1925  	xmlData, err = xml.Marshal(reqHeader)
  1926  	c.Assert(err, IsNil)
  1927  	c.Assert(string(xmlData), Equals, "<ResponseHeaderConfiguration><Rule><Name>name1</Name><Filters><Operation>Put</Operation><Operation>GetObject</Operation></Filters><HideHeaders><Header>Last-Modified</Header></HideHeaders></Rule><Rule><Name>name2</Name><Filters><Operation>*</Operation></Filters><HideHeaders><Header>Last-Modified</Header></HideHeaders></Rule></ResponseHeaderConfiguration>")
  1928  
  1929  	reqHeader = PutBucketResponseHeader{
  1930  		Rule: []ResponseHeaderRule{
  1931  			{
  1932  				Name: "name1",
  1933  			},
  1934  		},
  1935  	}
  1936  	xmlData, err = xml.Marshal(reqHeader)
  1937  	c.Assert(err, IsNil)
  1938  	c.Assert(string(xmlData), Equals, "<ResponseHeaderConfiguration><Rule><Name>name1</Name><Filters></Filters><HideHeaders></HideHeaders></Rule></ResponseHeaderConfiguration>")
  1939  }
  1940  
  1941  func (s *OssTypeSuite) TestGetResponseHeaderResult(c *C) {
  1942  	xmlData := `<ResponseHeaderConfiguration>
  1943      <Rule>
  1944          <Name>rule1</Name>
  1945          <Filters>
  1946              <Operation>Put</Operation>
  1947              <Operation>GetObject</Operation>
  1948          </Filters>
  1949          <HideHeaders>
  1950             	<Header>Last-Modified</Header>
  1951  			<Header>x-oss-request-id</Header>
  1952          </HideHeaders>
  1953      </Rule>
  1954  	<Rule>
  1955          <Name>rule2</Name>
  1956          <Filters>
  1957              <Operation>*</Operation>
  1958          </Filters>
  1959          <HideHeaders>
  1960             	<Header>Last-Modified</Header>
  1961  			<Header>x-oss-request-id</Header>
  1962          </HideHeaders>
  1963      </Rule>
  1964  </ResponseHeaderConfiguration>`
  1965  	var repResult GetBucketResponseHeaderResult
  1966  	err := xmlUnmarshal(strings.NewReader(xmlData), &repResult)
  1967  	c.Assert(err, IsNil)
  1968  	c.Assert(repResult.Rule[0].Name, Equals, "rule1")
  1969  	c.Assert(repResult.Rule[0].Filters.Operation[0], Equals, "Put")
  1970  	c.Assert(repResult.Rule[0].HideHeaders.Header[0], Equals, "Last-Modified")
  1971  
  1972  	c.Assert(repResult.Rule[1].Name, Equals, "rule2")
  1973  	c.Assert(repResult.Rule[1].Filters.Operation[0], Equals, "*")
  1974  	c.Assert(repResult.Rule[1].HideHeaders.Header[0], Equals, "Last-Modified")
  1975  }
  1976  
  1977  func (s *OssTypeSuite) TestGetBucketCORSResult(c *C) {
  1978  	xmlData := `<?xml version="1.0" encoding="UTF-8"?>
  1979  <CORSConfiguration>
  1980      <CORSRule>
  1981        <AllowedOrigin>*</AllowedOrigin>
  1982        <AllowedMethod>PUT</AllowedMethod>
  1983        <AllowedMethod>GET</AllowedMethod>
  1984        <AllowedHeader>Authorization</AllowedHeader>
  1985      </CORSRule>
  1986      <CORSRule>
  1987        <AllowedOrigin>http://example.com</AllowedOrigin>
  1988        <AllowedOrigin>http://example.net</AllowedOrigin>
  1989        <AllowedMethod>GET</AllowedMethod>
  1990        <AllowedHeader>Authorization</AllowedHeader>
  1991        <ExposeHeader>x-oss-test</ExposeHeader>
  1992        <ExposeHeader>x-oss-test1</ExposeHeader>
  1993        <MaxAgeSeconds>100</MaxAgeSeconds>
  1994      </CORSRule>
  1995      <ResponseVary>false</ResponseVary>
  1996  </CORSConfiguration>`
  1997  	var repResult GetBucketCORSResult
  1998  	err := xmlUnmarshal(strings.NewReader(xmlData), &repResult)
  1999  	c.Assert(err, IsNil)
  2000  	c.Assert(repResult.CORSRules[0].AllowedOrigin[0], Equals, "*")
  2001  	c.Assert(repResult.CORSRules[0].AllowedMethod[0], Equals, "PUT")
  2002  	c.Assert(repResult.CORSRules[0].AllowedMethod[1], Equals, "GET")
  2003  	c.Assert(repResult.CORSRules[0].AllowedHeader[0], Equals, "Authorization")
  2004  
  2005  	c.Assert(repResult.CORSRules[1].AllowedOrigin[0], Equals, "http://example.com")
  2006  	c.Assert(repResult.CORSRules[1].AllowedOrigin[1], Equals, "http://example.net")
  2007  	c.Assert(repResult.CORSRules[1].AllowedMethod[0], Equals, "GET")
  2008  	c.Assert(repResult.CORSRules[1].AllowedHeader[0], Equals, "Authorization")
  2009  	c.Assert(repResult.CORSRules[1].ExposeHeader[0], Equals, "x-oss-test")
  2010  	c.Assert(repResult.CORSRules[1].ExposeHeader[1], Equals, "x-oss-test1")
  2011  	c.Assert(repResult.CORSRules[1].MaxAgeSeconds, Equals, int(100))
  2012  	c.Assert(*repResult.ResponseVary, Equals, false)
  2013  }
  2014  
  2015  func (s *OssTypeSuite) TestPutBucketCORS(c *C) {
  2016  	isTrue := true
  2017  	rule1 := CORSRule{
  2018  		AllowedOrigin: []string{"*"},
  2019  		AllowedMethod: []string{"PUT", "GET", "POST"},
  2020  		AllowedHeader: []string{},
  2021  		ExposeHeader:  []string{},
  2022  		MaxAgeSeconds: 100,
  2023  	}
  2024  
  2025  	rule2 := CORSRule{
  2026  		AllowedOrigin: []string{"http://www.a.com", "http://www.b.com"},
  2027  		AllowedMethod: []string{"GET"},
  2028  		AllowedHeader: []string{"Authorization"},
  2029  		ExposeHeader:  []string{"x-oss-test", "x-oss-test1"},
  2030  		MaxAgeSeconds: 100,
  2031  	}
  2032  
  2033  	put := PutBucketCORS{}
  2034  	put.CORSRules = []CORSRule{rule1, rule2}
  2035  	put.ResponseVary = &isTrue
  2036  
  2037  	bs, err := xml.Marshal(put)
  2038  	c.Assert(err, IsNil)
  2039  	c.Assert(string(bs), Equals, "<CORSConfiguration><CORSRule><AllowedOrigin>*</AllowedOrigin><AllowedMethod>PUT</AllowedMethod><AllowedMethod>GET</AllowedMethod><AllowedMethod>POST</AllowedMethod><MaxAgeSeconds>100</MaxAgeSeconds></CORSRule><CORSRule><AllowedOrigin>http://www.a.com</AllowedOrigin><AllowedOrigin>http://www.b.com</AllowedOrigin><AllowedMethod>GET</AllowedMethod><AllowedHeader>Authorization</AllowedHeader><ExposeHeader>x-oss-test</ExposeHeader><ExposeHeader>x-oss-test1</ExposeHeader><MaxAgeSeconds>100</MaxAgeSeconds></CORSRule><ResponseVary>true</ResponseVary></CORSConfiguration>")
  2040  }