testPresignedPostPolicyWrongFile tests that when we have a policy with a checksum, we cannot POST the wrong file
()
| 5962 | |
| 5963 | // testPresignedPostPolicyWrongFile tests that when we have a policy with a checksum, we cannot POST the wrong file |
| 5964 | func testPresignedPostPolicyWrongFile() { |
| 5965 | // initialize logging params |
| 5966 | startTime := time.Now() |
| 5967 | testName := getFuncName() |
| 5968 | function := "PresignedPostPolicy(policy)" |
| 5969 | args := map[string]interface{}{ |
| 5970 | "policy": "", |
| 5971 | } |
| 5972 | |
| 5973 | c, err := NewClient(ClientConfig{}) |
| 5974 | if err != nil { |
| 5975 | logError(testName, function, args, startTime, "", "MinIO client object creation failed", err) |
| 5976 | return |
| 5977 | } |
| 5978 | |
| 5979 | // Generate a new random bucket name. |
| 5980 | bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") |
| 5981 | |
| 5982 | // Make a new bucket in 'us-east-1' (source bucket). |
| 5983 | err = c.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: "us-east-1"}) |
| 5984 | if err != nil { |
| 5985 | logError(testName, function, args, startTime, "", "MakeBucket failed", err) |
| 5986 | return |
| 5987 | } |
| 5988 | |
| 5989 | defer cleanupBucket(bucketName, c) |
| 5990 | |
| 5991 | objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") |
| 5992 | // Azure requires the key to not start with a number |
| 5993 | metadataKey := randString(60, rand.NewSource(time.Now().UnixNano()), "user") |
| 5994 | metadataValue := randString(60, rand.NewSource(time.Now().UnixNano()), "") |
| 5995 | |
| 5996 | policy := minio.NewPostPolicy() |
| 5997 | policy.SetBucket(bucketName) |
| 5998 | policy.SetKey(objectName) |
| 5999 | policy.SetExpires(time.Now().UTC().AddDate(0, 0, 10)) // expires in 10 days |
| 6000 | policy.SetContentType("binary/octet-stream") |
| 6001 | policy.SetContentLengthRange(10, 1024*1024) |
| 6002 | policy.SetUserMetadata(metadataKey, metadataValue) |
| 6003 | |
| 6004 | // Add CRC32C of some data that the policy will explicitly allow. |
| 6005 | checksum := minio.ChecksumCRC32C.ChecksumBytes([]byte{0x01, 0x02, 0x03}) |
| 6006 | err = policy.SetChecksum(checksum) |
| 6007 | if err != nil { |
| 6008 | logError(testName, function, args, startTime, "", "SetChecksum failed", err) |
| 6009 | return |
| 6010 | } |
| 6011 | |
| 6012 | args["policy"] = policy.String() |
| 6013 | |
| 6014 | presignedPostPolicyURL, formData, err := c.PresignedPostPolicy(context.Background(), policy) |
| 6015 | if err != nil { |
| 6016 | logError(testName, function, args, startTime, "", "PresignedPostPolicy failed", err) |
| 6017 | return |
| 6018 | } |
| 6019 | |
| 6020 | // At this stage, we have a policy that allows us to upload for a specific checksum. |
| 6021 | // Test that uploading datafile-10-kB, with a different checksum, fails as expected |
no test coverage detected