-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support XML API (#331) #1164
Open
tustvold
wants to merge
4
commits into
fsouza:main
Choose a base branch
from
tustvold:support-xml-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+149
−30
Open
Support XML API (#331) #1164
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
"context" | ||
"crypto/tls" | ||
"encoding/binary" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"mime/multipart" | ||
|
@@ -570,9 +569,6 @@ | |
|
||
func TestServerClientSignedUploadBucketCNAME(t *testing.T) { | ||
url := "https://mybucket.mydomain.com:4443/files/txt/text-02.txt?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=fake-gcs&X-Goog-Expires=3600&X-Goog-SignedHeaders=host&X-Goog-Signature=fake-gc" | ||
expectedName := "files/txt/text-02.txt" | ||
expectedContentType := "text/plain" | ||
expectedHash := "bHupxaFBQh4cA8uYB8l8dA==" | ||
opts := Options{ | ||
InitialObjects: []Object{ | ||
{ObjectAttrs: ObjectAttrs{BucketName: "mybucket.mydomain.com", Name: "files/txt/text-01.txt"}, Content: []byte("something")}, | ||
|
@@ -596,23 +592,6 @@ | |
if resp.StatusCode != http.StatusOK { | ||
t.Errorf("wrong status returned\nwant %d\ngot %d", http.StatusOK, resp.StatusCode) | ||
} | ||
data, err := io.ReadAll(resp.Body) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was incorrect, the XML APIs should not return a body and certainly shouldn't return JSON There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 Oh are signed uploads powered by the XML API? Interesting! |
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
var obj Object | ||
if err := json.Unmarshal(data, &obj); err != nil { | ||
t.Fatal(err) | ||
} | ||
if obj.Name != expectedName { | ||
t.Errorf("wrong filename\nwant %q\ngot %q", expectedName, obj.Name) | ||
} | ||
if obj.ContentType != expectedContentType { | ||
t.Errorf("wrong content type\nwant %q\ngot %q", expectedContentType, obj.ContentType) | ||
} | ||
if obj.Md5Hash != expectedHash { | ||
t.Errorf("wrong md5 hash\nwant %q\ngot %q", expectedHash, obj.Md5Hash) | ||
} | ||
} | ||
|
||
func TestServerClientUploadWithPredefinedAclPublicRead(t *testing.T) { | ||
|
@@ -700,6 +679,64 @@ | |
} | ||
} | ||
|
||
func TestServerXMLPut(t *testing.T) { | ||
server, err := NewServerWithOptions(Options{ | ||
PublicHost: "test", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer server.Stop() | ||
server.CreateBucketWithOpts(CreateBucketOpts{Name: "bucket1"}) | ||
server.CreateBucketWithOpts(CreateBucketOpts{Name: "bucket2"}) | ||
|
||
const data = "some nice content" | ||
req, err := http.NewRequest("PUT", server.URL()+"/bucket1/path", strings.NewReader(data)) | ||
req.Host = "test" | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
client := http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
}, | ||
} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer resp.Body.Close() | ||
if resp.StatusCode != http.StatusOK { | ||
t.Errorf("got %d expected %d", resp.StatusCode, http.StatusOK) | ||
} | ||
|
||
req, err = http.NewRequest("PUT", server.URL()+"/bucket2/path", nil) | ||
req.Host = "test" | ||
req.Header.Set("x-goog-copy-source", "bucket1/path") | ||
|
||
resp, err = client.Do(req) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer resp.Body.Close() | ||
if resp.StatusCode != http.StatusOK { | ||
t.Errorf("got %d expected %d", resp.StatusCode, http.StatusOK) | ||
} | ||
|
||
req, err = http.NewRequest("PUT", server.URL()+"/bucket2/path2", nil) | ||
req.Host = "test" | ||
req.Header.Set("x-goog-copy-source", "bucket1/nonexistent") | ||
|
||
resp, err = client.Do(req) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer resp.Body.Close() | ||
if resp.StatusCode != http.StatusNotFound { | ||
t.Errorf("got %d expected %d", resp.StatusCode, http.StatusNotFound) | ||
} | ||
} | ||
|
||
func TestServerInvalidUploadType(t *testing.T) { | ||
server := NewServer(nil) | ||
defer server.Stop() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't have ever worked as insertObject expects query parameters encoding the object name, etc...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
insertObject
does not necessarily read the object name from query parameters:fake-gcs-server/fakestorage/upload.go
Lines 85 to 95 in d7832ec
I need to take a deeper look at this, but curious if you're basing on comment on the docs? There are many undocumented things in the GCS API that we run into when someone tries to integrate with some different SDK, and I've ironically done a poor job in documenting those in fake-gcs-server 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, insertObject has a peculiar special case that uses
X-Goog-Algorithm
to detect a signed URL and then falls back to implementing something that looks like the XML API, because that is what signed URLs are. With this PR that can probably be removed 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, absolutely. insertObject definitely looks like a little monster doing too many things. Thank you very much! I'll go over the PR in details later today.