Repository: google/exposure-notifications-server
Pull request #1002 (2020-09-16 19:59:07)

Explicitly set application/zip on zip files.

## Proposed Changes

* When writing zip files set application/zip as the content-type

**Release Note**

```release-note
Sets content type on blob storage for zip archives.
```

google-oss-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/google/exposure-notifications-server/pull/1002#" title="Author self-approved">mikehelmick</a>*, *<a href="https://github.com/google/exposure-notifications-server/pull/1002#pullrequestreview-489977378" title="Approved">sethvargo</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=google%2Fexposure-notifications-server).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/google/exposure-notifications-server/blob/main/OWNERS)~~ [mikehelmick,sethvargo]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/internal/export/worker.go b/internal/export/worker.go
index 3b26291..67bf8f3 100644
--- a/internal/export/worker.go
+++ b/internal/export/worker.go
@@ -275,7 +275,7 @@ func (s *Server) createFile(ctx context.Context, cfi createFileInfo) (string, er
 	logger.Infof("Created file %v, signed with %v keys", objectName, len(signers))
 	ctx, cancel := context.WithTimeout(ctx, blobOperationTimeout)
 	defer cancel()
-	if err := s.env.Blobstore().CreateObject(ctx, cfi.exportBatch.BucketName, objectName, data, true, storage.ContentTypeDefault); err != nil {
+	if err := s.env.Blobstore().CreateObject(ctx, cfi.exportBatch.BucketName, objectName, data, true, storage.ContentTypeZip); err != nil {
 		return "", fmt.Errorf("creating file %s in bucket %s: %w", objectName, cfi.exportBatch.BucketName, err)
 	}
 	return objectName, nil
diff --git a/internal/storage/storage.go b/internal/storage/storage.go
index 370dc2f..345d0f5 100644
--- a/internal/storage/storage.go
+++ b/internal/storage/storage.go
@@ -24,7 +24,7 @@ var ErrNotFound = fmt.Errorf("storage object not found")
 
 const (
 	ContentTypeTextPlain = "text/plain"
-	ContentTypeDefault   = ""
+	ContentTypeZip       = "application/zip"
 )
 
 // Blobstore defines the minimum interface for a blob storage system.


Test patch:
diff --git a/internal/storage/filesystem_storage_test.go b/internal/storage/filesystem_storage_test.go
index ac4d1a4..ff42f15 100644
--- a/internal/storage/filesystem_storage_test.go
+++ b/internal/storage/filesystem_storage_test.go
@@ -67,7 +67,7 @@ func TestFilesystemStorage_CreateObject(t *testing.T) {
 				t.Fatal(err)
 			}
 
-			err = storage.CreateObject(ctx, tc.folder, tc.filepath, tc.contents, false, ContentTypeDefault)
+			err = storage.CreateObject(ctx, tc.folder, tc.filepath, tc.contents, false, ContentTypeZip)
 			if (err != nil) != tc.err {
 				t.Fatal(err)
 			}
diff --git a/internal/storage/google_cloud_storage_test.go b/internal/storage/google_cloud_storage_test.go
index 253ba83..ea6af91 100644
--- a/internal/storage/google_cloud_storage_test.go
+++ b/internal/storage/google_cloud_storage_test.go
@@ -155,7 +155,7 @@ func TestGoogleCloudStorage_CreateObject(t *testing.T) {
 				t.Fatal(err)
 			}
 
-			err = gcsStorage.CreateObject(ctx, tc.bucket, tc.object, tc.contents, false, ContentTypeDefault)
+			err = gcsStorage.CreateObject(ctx, tc.bucket, tc.object, tc.contents, false, ContentTypeZip)
 			if (err != nil) != tc.err {
 				t.Fatal(err)
 			}