testPresignedPostPolicyWrongFile tests that when we have a policy with a checksum, we cannot POST the wrong file
()
| 5858 | |
| 5859 | // testPresignedPostPolicyWrongFile tests that when we have a policy with a checksum, we cannot POST the wrong file |
| 5860 | func testPresignedPostPolicyWrongFile() { |
| 5861 | // initialize logging params |
| 5862 | startTime := time.Now() |
| 5863 | testName := getFuncName() |
| 5864 | function := "PresignedPostPolicy(policy)" |
| 5865 | args := map[string]interface{}{ |
| 5866 | "policy": "", |
| 5867 | } |
| 5868 | |
| 5869 | c, err := NewClient(ClientConfig{}) |
| 5870 | if err != nil { |
| 5871 | logError(testName, function, args, startTime, "", "MinIO client object creation failed", err) |
| 5872 | return |
| 5873 | } |
| 5874 | |
| 5875 | // Generate a new random bucket name. |
| 5876 | bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") |
| 5877 | |
| 5878 | // Make a new bucket in 'us-east-1' (source bucket). |
| 5879 | err = c.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: "us-east-1"}) |
| 5880 | if err != nil { |
| 5881 | logError(testName, function, args, startTime, "", "MakeBucket failed", err) |
| 5882 | return |
| 5883 | } |
| 5884 | |
| 5885 | defer cleanupBucket(bucketName, c) |
| 5886 | |
| 5887 | objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") |
| 5888 | // Azure requires the key to not start with a number |
| 5889 | metadataKey := randString(60, rand.NewSource(time.Now().UnixNano()), "user") |
| 5890 | metadataValue := randString(60, rand.NewSource(time.Now().UnixNano()), "") |
| 5891 | |
| 5892 | policy := minio.NewPostPolicy() |
| 5893 | policy.SetBucket(bucketName) |
| 5894 | policy.SetKey(objectName) |
| 5895 | policy.SetExpires(time.Now().UTC().AddDate(0, 0, 10)) // expires in 10 days |
| 5896 | policy.SetContentType("binary/octet-stream") |
| 5897 | policy.SetContentLengthRange(10, 1024*1024) |
| 5898 | policy.SetUserMetadata(metadataKey, metadataValue) |
| 5899 | |
| 5900 | // Add CRC32C of some data that the policy will explicitly allow. |
| 5901 | checksum := minio.ChecksumCRC32C.ChecksumBytes([]byte{0x01, 0x02, 0x03}) |
| 5902 | err = policy.SetChecksum(checksum) |
| 5903 | if err != nil { |
| 5904 | logError(testName, function, args, startTime, "", "SetChecksum failed", err) |
| 5905 | return |
| 5906 | } |
| 5907 | |
| 5908 | args["policy"] = policy.String() |
| 5909 | |
| 5910 | presignedPostPolicyURL, formData, err := c.PresignedPostPolicy(context.Background(), policy) |
| 5911 | if err != nil { |
| 5912 | logError(testName, function, args, startTime, "", "PresignedPostPolicy failed", err) |
| 5913 | return |
| 5914 | } |
| 5915 | |
| 5916 | // At this stage, we have a policy that allows us to upload for a specific checksum. |
| 5917 | // Test that uploading datafile-10-kB, with a different checksum, fails as expected |
no test coverage detected