Skip to content

Commit

Permalink
Added post policy for starts-with in content type (minio#1421)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHudgins authored Dec 1, 2020
1 parent e4928a6 commit 3316e6a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
11 changes: 7 additions & 4 deletions functional_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2138,7 +2138,7 @@ func testRemoveObjectsContext() {
return
}

defer cleanupBucket(bucketName, c)
defer cleanupBucket(bucketName, c)

// Generate put data.
r := bytes.NewReader(bytes.Repeat([]byte("a"), 8))
Expand Down Expand Up @@ -3381,6 +3381,10 @@ func testPresignedPostPolicy() {
logError(testName, function, args, startTime, "", "SetContentType did not fail for invalid conditions", err)
return
}
if err := policy.SetContentTypeStartsWith(""); err == nil {
logError(testName, function, args, startTime, "", "SetContentTypeStartsWith did not fail for invalid conditions", err)
return
}
if err := policy.SetContentLengthRange(1024*1024, 1024); err == nil {
logError(testName, function, args, startTime, "", "SetContentLengthRange did not fail for invalid conditions", err)
return
Expand Down Expand Up @@ -3554,7 +3558,7 @@ func testCopyObject() {
logError(testName, function, args, startTime, "", "MakeBucket failed", err)
return
}
defer cleanupBucket(bucketName + "-copy", c)
defer cleanupBucket(bucketName+"-copy", c)

// Generate 33K of data.
bufSize := dataFileMap["datafile-33-kB"]
Expand Down Expand Up @@ -5868,7 +5872,7 @@ func testMakeBucketErrorV2() {
logError(testName, function, args, startTime, "", "MakeBucket failed", err)
return
}

defer cleanupBucket(bucketName, c)

if err = c.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: region}); err == nil {
Expand Down Expand Up @@ -6959,7 +6963,6 @@ func testEncryptedEmptyObject() {

delete(args, "objectName")


successLogger(testName, function, args, startTime).Info()
}

Expand Down
18 changes: 18 additions & 0 deletions post-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ func (p *PostPolicy) SetContentType(contentType string) error {
return nil
}

// SetContentTypeStartsWith - Sets what content-type of the object for this policy
// based upload can start with.
func (p *PostPolicy) SetContentTypeStartsWith(contentTypeStartsWith string) error {
if strings.TrimSpace(contentTypeStartsWith) == "" || contentTypeStartsWith == "" {
return errInvalidArgument("No content type specified.")
}
policyCond := policyCondition{
matchType: "starts-with",
condition: "$Content-Type",
value: contentTypeStartsWith,
}
if err := p.addNewPolicy(policyCond); err != nil {
return err
}
p.formData["Content-Type"] = contentTypeStartsWith
return nil
}

// SetContentLengthRange - Set new min and max content length
// condition for all incoming uploads.
func (p *PostPolicy) SetContentLengthRange(min, max int64) error {
Expand Down

0 comments on commit 3316e6a

Please sign in to comment.