nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: fsouza/fake-gcs-server
Pull request #1801 (2024-11-05 16:46:04)

Disallow uppercase in bucket names
This updates the pattern for valid bucket names to remove support for uppercase characters.

Per https://cloud.google.com/storage/docs/buckets#naming:

> Bucket names can only contain lowercase letters, numeric characters, dashes (-), underscores (_), and dots (.).

I imagine this is a potentially breaking change depending on peoples' setups/fixture data, but this would have caught a bug for one of our projects when changing an internal naming pattern.


Patch:
diff --git a/fakestorage/bucket.go b/fakestorage/bucket.go
index 4026f1a..93c67e5 100644
--- a/fakestorage/bucket.go
+++ b/fakestorage/bucket.go
@@ -16,7 +16,8 @@ import (
 	"github.com/gorilla/mux"
 )
 
-var bucketRegexp = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]$`)
+// https://cloud.google.com/storage/docs/buckets#naming
+var bucketRegexp = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]*[a-z0-9]$`)
 
 // CreateBucket creates a bucket inside the server, so any API calls that
 // require the bucket name will recognize this bucket.


Test patch:
diff --git a/fakestorage/bucket_test.go b/fakestorage/bucket_test.go
index 977b492..edebddf 100644
--- a/fakestorage/bucket_test.go
+++ b/fakestorage/bucket_test.go
@@ -252,6 +252,7 @@ func TestServerClientBucketCreateValidation(t *testing.T) {
 		"or spaces",
 		"don't even try",
 		"no/slashes/either",
+		"uppercaseNOTallowed",
 	}
 
 	for _, bucketName := range bucketNames {
Repository: fsouza/fake-gcs-server
Pull request #134 (2019-11-18 19:02:58)

GetObject can download content
Getting an object through the storage api can download the content of file when query param `alt=media`. Docs: https://cloud.google.com/storage/docs/json_api/v1/objects/get

chrisrecalis: This fixes the nodejs client as it uses the storage api to download the data

Patch:
diff --git a/fakestorage/object.go b/fakestorage/object.go
index e94e888..8eb849f 100644
--- a/fakestorage/object.go
+++ b/fakestorage/object.go
@@ -154,6 +154,12 @@ func (s *Server) listObjects(w http.ResponseWriter, r *http.Request) {
 
 func (s *Server) getObject(w http.ResponseWriter, r *http.Request) {
 	vars := mux.Vars(r)
+
+	if alt := r.URL.Query().Get("alt"); alt == "media" {
+		s.downloadObject(w, r)
+		return
+	}
+
 	encoder := json.NewEncoder(w)
 	obj, err := s.GetObject(vars["bucketName"], vars["objectName"])
 	if err != nil {


Test patch:
diff --git a/fakestorage/server_test.go b/fakestorage/server_test.go
index 9a03f4d..e5c1ed8 100644
--- a/fakestorage/server_test.go
+++ b/fakestorage/server_test.go
@@ -83,6 +83,13 @@ func testDownloadObject(t *testing.T, server *Server) {
 			map[string]string{"accept-ranges": "bytes", "content-length": "21"},
 			"body {display: none;}",
 		},
+		{
+			"GET: using storage api",
+			http.MethodGet,
+			"https://storage.googleapis.com/storage/v1/b/some-bucket/o/files/txt/text-01.txt?alt=media",
+			map[string]string{"accept-ranges": "bytes", "content-length": "9"},
+			"something",
+		},
 		{
 			"HEAD: bucket in the path",
 			http.MethodHead,
Repository: fsouza/fake-gcs-server
Pull request #266 (2020-06-08 14:56:04)

Add check to ensure Range is less than content
* This fixes the case where a Range value greater than the length of the
  content is requested, causing the server to crash and fail the
  request.

gjabell: Hey @fsouza, can do :)
gjabell: Let me know how those look @fsouza; the `Too-long range specified` test should fail without the fix and pass with it :)

Patch:
diff --git a/fakestorage/object.go b/fakestorage/object.go
index f1851d3..d287c47 100644
--- a/fakestorage/object.go
+++ b/fakestorage/object.go
@@ -401,6 +401,9 @@ func (s *Server) handleRange(obj Object, r *http.Request) (start, end int, conte
 				} else {
 					end++
 				}
+				if end > len(obj.Content) {
+					end = len(obj.Content)
+				}
 				return start, end, obj.Content[start:end]
 			}
 		}


Test patch:
diff --git a/fakestorage/server_test.go b/fakestorage/server_test.go
index a052b85..e908fb3 100644
--- a/fakestorage/server_test.go
+++ b/fakestorage/server_test.go
@@ -86,6 +86,7 @@ func TestDownloadObject(t *testing.T) {
 		{BucketName: "other-bucket", Name: "static/css/website.css", Content: []byte("body {display: none;}")},
 	}
 	runServersTest(t, objs, testDownloadObject)
+	runServersTest(t, objs, testDownloadObjectRange)
 }
 
 func testDownloadObject(t *testing.T, server *Server) {
@@ -168,6 +169,48 @@ func testDownloadObject(t *testing.T, server *Server) {
 	}
 }
 
+func testDownloadObjectRange(t *testing.T, server *Server) {
+	tests := []struct {
+		name           string
+		headers        map[string]string
+		expectedStatus int
+		expectedBody   string
+	}{
+		{"No range specified", map[string]string{}, http.StatusOK, "something"},
+		{"Partial range specified", map[string]string{"Range": "bytes=1-4"}, http.StatusPartialContent, "omet"},
+		{"Exact range specified", map[string]string{"Range": "bytes=0-8"}, http.StatusOK, "something"},
+		{"Too-long range specified", map[string]string{"Range": "bytes=0-100"}, http.StatusOK, "something"},
+	}
+	for _, test := range tests {
+		test := test
+		t.Run(test.name, func(t *testing.T) {
+			client := server.HTTPClient()
+			req, err := http.NewRequest("GET", "https://storage.googleapis.com/some-bucket/files/txt/text-01.txt", nil)
+			if err != nil {
+				t.Fatal(err)
+			}
+			for header, value := range test.headers {
+				req.Header.Add(header, value)
+			}
+			resp, err := client.Do(req)
+			if err != nil {
+				t.Fatal(err)
+			}
+			defer resp.Body.Close()
+			if resp.StatusCode != test.expectedStatus {
+				t.Errorf("wrong status returned\nwant %d\ngot  %d", test.expectedStatus, resp.StatusCode)
+			}
+			data, err := ioutil.ReadAll(resp.Body)
+			if err != nil {
+				t.Fatal(err)
+			}
+			if body := string(data); body != test.expectedBody {
+				t.Errorf("wrong body\nwant %q\ngot  %q", test.expectedBody, body)
+			}
+		})
+	}
+}
+
 func TestDownloadObjectAlternatePublicHost(t *testing.T) {
 	tests := []struct {
 		name            string
Repository: fsouza/fake-gcs-server
Pull request #511 (2021-06-11 12:57:16)

Always respond with HTTP 206 for range requests
This matches the GCS behavior.

fsouza: Change looks good. Can you fix the test?
gaul: > Change looks good. Can you fix the test?

Done.

Patch:
diff --git a/fakestorage/object.go b/fakestorage/object.go
index 18f4a1c..f796406 100644
--- a/fakestorage/object.go
+++ b/fakestorage/object.go
@@ -516,8 +516,8 @@ func (s *Server) downloadObject(w http.ResponseWriter, r *http.Request) {
 	}
 
 	status := http.StatusOK
-	start, end, content := s.handleRange(obj, r)
-	if len(content) != len(obj.Content) {
+	ranged, start, end, content := s.handleRange(obj, r)
+	if ranged {
 		status = http.StatusPartialContent
 		w.Header().Set("Content-Range", fmt.Sprintf("bytes %d-%d/%d", start, end, len(obj.Content)))
 	}
@@ -535,7 +535,7 @@ func (s *Server) downloadObject(w http.ResponseWriter, r *http.Request) {
 	}
 }
 
-func (s *Server) handleRange(obj Object, r *http.Request) (start, end int, content []byte) {
+func (s *Server) handleRange(obj Object, r *http.Request) (ranged bool, start, end int, content []byte) {
 	if reqRange := r.Header.Get("Range"); reqRange != "" {
 		parts := strings.SplitN(reqRange, "=", 2)
 		if len(parts) == 2 && parts[0] == "bytes" {
@@ -551,11 +551,11 @@ func (s *Server) handleRange(obj Object, r *http.Request) (start, end int, conte
 				if end > len(obj.Content) {
 					end = len(obj.Content)
 				}
-				return start, end, obj.Content[start:end]
+				return true, start, end, obj.Content[start:end]
 			}
 		}
 	}
-	return 0, 0, obj.Content
+	return false, 0, 0, obj.Content
 }
 
 func (s *Server) patchObject(r *http.Request) jsonResponse {


Test patch:
diff --git a/fakestorage/server_test.go b/fakestorage/server_test.go
index abffd77..a26e1c0 100644
--- a/fakestorage/server_test.go
+++ b/fakestorage/server_test.go
@@ -231,8 +231,8 @@ func testDownloadObjectRange(t *testing.T, server *Server) {
 	}{
 		{"No range specified", map[string]string{}, http.StatusOK, "something"},
 		{"Partial range specified", map[string]string{"Range": "bytes=1-4"}, http.StatusPartialContent, "omet"},
-		{"Exact range specified", map[string]string{"Range": "bytes=0-8"}, http.StatusOK, "something"},
-		{"Too-long range specified", map[string]string{"Range": "bytes=0-100"}, http.StatusOK, "something"},
+		{"Exact range specified", map[string]string{"Range": "bytes=0-8"}, http.StatusPartialContent, "something"},
+		{"Too-long range specified", map[string]string{"Range": "bytes=0-100"}, http.StatusPartialContent, "something"},
 	}
 	for _, test := range tests {
 		test := test