Skip to content

Commit

Permalink
Remove obsolete upload route (#1251)
Browse files Browse the repository at this point in the history
POSTing to `/storage/v1/b/my-bucket/o` to upload an object
is not supposed to work. The Google Cloud Storage API returns a 400
error with a response body like this:

```json
{
  "error": {
    "code": 400,
    "message": "Uploads must be sent to the upload URL. Re-send this request to https://storage.googleapis.com/upload/storage/v1/b/my-bucket/o?uploadType=media&name=test.txt",
    "errors": [
      {
        "message": "Uploads must be sent to the upload URL. Re-send this request to https://storage.googleapis.com/upload/storage/v1/b/my-bucket/o?uploadType=media&name=test.txt",
        "domain": "global",
        "reason": "wrongUrlForUpload"
      }
    ]
  }
}
```

To stay true to the GCS API, we remove support from the
`fake-gcs-server` as well.
  • Loading branch information
manuteleco authored Jul 30, 2023
1 parent 63221c8 commit 94427ae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion fakestorage/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ func (s *Server) buildMuxer() {
r.Path("/b/{bucketName}").Methods(http.MethodPatch).HandlerFunc(jsonToHTTPHandler(s.updateBucket))
r.Path("/b/{bucketName}").Methods(http.MethodDelete).HandlerFunc(jsonToHTTPHandler(s.deleteBucket))
r.Path("/b/{bucketName}/o").Methods(http.MethodGet).HandlerFunc(jsonToHTTPHandler(s.listObjects))
r.Path("/b/{bucketName}/o").Methods(http.MethodPost).HandlerFunc(jsonToHTTPHandler(s.insertObject))
r.Path("/b/{bucketName}/o/{objectName:.+}").Methods(http.MethodPatch).HandlerFunc(jsonToHTTPHandler(s.patchObject))
r.Path("/b/{bucketName}/o/{objectName:.+}/acl").Methods(http.MethodGet).HandlerFunc(jsonToHTTPHandler(s.listObjectACL))
r.Path("/b/{bucketName}/o/{objectName:.+}/acl").Methods(http.MethodPost).HandlerFunc(jsonToHTTPHandler(s.setObjectACL))
Expand Down
8 changes: 4 additions & 4 deletions fakestorage/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func TestServerClientSimpleUpload(t *testing.T) {

const data = "some nice content"
const contentType = "text/plain"
req, err := http.NewRequest("POST", server.URL()+"/storage/v1/b/other-bucket/o?uploadType=media&name=some/nice/object.txt", strings.NewReader(data))
req, err := http.NewRequest("POST", server.URL()+"/upload/storage/v1/b/other-bucket/o?uploadType=media&name=some/nice/object.txt", strings.NewReader(data))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -633,7 +633,7 @@ func TestServerClientUploadWithPredefinedAclPublicRead(t *testing.T) {
}
compressed := buf.Bytes()

req, err := http.NewRequest("POST", server.URL()+"/storage/v1/b/other-bucket/o?predefinedAcl=publicRead&uploadType=media&name=some/nice/object.txt&contentEncoding="+contentEncoding, bytes.NewReader(compressed))
req, err := http.NewRequest("POST", server.URL()+"/upload/storage/v1/b/other-bucket/o?predefinedAcl=publicRead&uploadType=media&name=some/nice/object.txt&contentEncoding="+contentEncoding, bytes.NewReader(compressed))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -690,7 +690,7 @@ func TestServerClientSimpleUploadNoName(t *testing.T) {
server.CreateBucketWithOpts(CreateBucketOpts{Name: "other-bucket"})

const data = "some nice content"
req, err := http.NewRequest("POST", server.URL()+"/storage/v1/b/other-bucket/o?uploadType=media", strings.NewReader(data))
req, err := http.NewRequest("POST", server.URL()+"/upload/storage/v1/b/other-bucket/o?uploadType=media", strings.NewReader(data))
if err != nil {
t.Fatal(err)
}
Expand All @@ -715,7 +715,7 @@ func TestServerInvalidUploadType(t *testing.T) {
defer server.Stop()
server.CreateBucketWithOpts(CreateBucketOpts{Name: "other-bucket"})
const data = "some nice content"
req, err := http.NewRequest("POST", server.URL()+"/storage/v1/b/other-bucket/o?uploadType=bananas&name=some-object.txt", strings.NewReader(data))
req, err := http.NewRequest("POST", server.URL()+"/upload/storage/v1/b/other-bucket/o?uploadType=bananas&name=some-object.txt", strings.NewReader(data))
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 94427ae

Please sign in to comment.