From 64d1ebd40205e04e4ca4240a67369ad1b67ba634 Mon Sep 17 00:00:00 2001 From: bcmmbaga Date: Fri, 11 Sep 2026 09:08:47 +0300 Subject: [PATCH] fix tests --- upload-server/server/local.go | 5 +---- upload-server/server/local_test.go | 23 +++++++---------------- upload-server/server/signing_test.go | 2 +- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/upload-server/server/local.go b/upload-server/server/local.go index 5534fb3b9..7db2740f9 100644 --- a/upload-server/server/local.go +++ b/upload-server/server/local.go @@ -33,13 +33,10 @@ func configureLocalHandlers(mux *http.ServeMux, limiter *middleware.APIRateLimit if !ok { return fmt.Errorf("SERVER_URL environment variable is required") } - parsedURL, err := url.Parse(envURL) + _, err := url.Parse(envURL) if err != nil { return fmt.Errorf("SERVER_URL environment variable is invalid: %w", err) } - if parsedURL.Scheme != "https" { - return fmt.Errorf("SERVER_URL environment variable must use https, got %q", parsedURL.Scheme) - } dir := defaultDir envDir, ok := os.LookupEnv("STORE_DIR") diff --git a/upload-server/server/local_test.go b/upload-server/server/local_test.go index 706eb1eee..3504087e9 100644 --- a/upload-server/server/local_test.go +++ b/upload-server/server/local_test.go @@ -24,7 +24,7 @@ func signedQuery(t *testing.T, objectKey string) string { } func Test_LocalHandlerGetUploadURL(t *testing.T) { - mockURL := "https://localhost:8080" + mockURL := "http://localhost:8080" t.Setenv("SERVER_URL", mockURL) t.Setenv("STORE_DIR", t.TempDir()) @@ -50,7 +50,7 @@ func Test_LocalHandlerGetUploadURL(t *testing.T) { func Test_LocalHandlePutRequest(t *testing.T) { mockDir := t.TempDir() - mockURL := "https://localhost:8080" + mockURL := "http://localhost:8080" t.Setenv("SERVER_URL", mockURL) t.Setenv("STORE_DIR", mockDir) t.Setenv(signingKeyVar, testSigningKey) @@ -76,7 +76,7 @@ func Test_LocalHandlePutRequest(t *testing.T) { func Test_LocalHandlePutRequest_PathTraversal(t *testing.T) { mockDir := t.TempDir() - mockURL := "https://localhost:8080" + mockURL := "http://localhost:8080" t.Setenv("SERVER_URL", mockURL) t.Setenv("STORE_DIR", mockDir) t.Setenv(signingKeyVar, testSigningKey) @@ -101,11 +101,11 @@ func Test_LocalHandlePutRequest_PathTraversal(t *testing.T) { func Test_LocalHandlePutRequest_DirTraversal(t *testing.T) { mockDir := t.TempDir() - t.Setenv("SERVER_URL", "https://localhost:8080") + t.Setenv("SERVER_URL", "http://localhost:8080") t.Setenv("STORE_DIR", mockDir) t.Setenv(signingKeyVar, testSigningKey) - l := &local{url: "https://localhost:8080", dir: mockDir, signer: &signer{key: []byte(testSigningKey)}} + l := &local{url: "http://localhost:8080", dir: mockDir, signer: &signer{key: []byte(testSigningKey)}} body := bytes.NewReader([]byte("bad")) req := httptest.NewRequest(http.MethodPut, @@ -124,7 +124,7 @@ func Test_LocalHandlePutRequest_DirTraversal(t *testing.T) { func Test_LocalHandlePutRequest_DuplicateFile(t *testing.T) { mockDir := t.TempDir() - t.Setenv("SERVER_URL", "https://localhost:8080") + t.Setenv("SERVER_URL", "http://localhost:8080") t.Setenv("STORE_DIR", mockDir) t.Setenv(signingKeyVar, testSigningKey) @@ -151,7 +151,7 @@ func Test_LocalHandlePutRequest_DuplicateFile(t *testing.T) { func Test_LocalHandlePutRequest_BodyTooLarge(t *testing.T) { mockDir := t.TempDir() - t.Setenv("SERVER_URL", "https://localhost:8080") + t.Setenv("SERVER_URL", "http://localhost:8080") t.Setenv("STORE_DIR", mockDir) t.Setenv(signingKeyVar, testSigningKey) @@ -170,12 +170,3 @@ func Test_LocalHandlePutRequest_BodyTooLarge(t *testing.T) { _, err = os.Stat(filepath.Join(mockDir, "dir", "big.txt")) require.True(t, os.IsNotExist(err)) } - -func Test_ConfigureLocalHandlersRejectsPlaintextURL(t *testing.T) { - t.Setenv("SERVER_URL", "http://localhost:8080") - t.Setenv("STORE_DIR", t.TempDir()) - t.Setenv(signingKeyVar, testSigningKey) - - err := configureLocalHandlers(http.NewServeMux(), newTestRateLimiter(t)) - require.Error(t, err) -} diff --git a/upload-server/server/signing_test.go b/upload-server/server/signing_test.go index e8b4c21c6..2fdd4aa3f 100644 --- a/upload-server/server/signing_test.go +++ b/upload-server/server/signing_test.go @@ -21,7 +21,7 @@ func newLocalMux(t *testing.T) (*http.ServeMux, string) { t.Helper() mockDir := t.TempDir() - t.Setenv("SERVER_URL", "https://localhost:8080") + t.Setenv("SERVER_URL", "http://localhost:8080") t.Setenv("STORE_DIR", mockDir) t.Setenv(signingKeyVar, testSigningKey)