Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ZaparooProject/zaparoo-core/v2

go 1.25.7
go 1.25.8

require (
fyne.io/systray v1.11.0
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func TestLocalClient_ContextCancellation(t *testing.T) {
cfg := testConfigWithPort(t, port)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Cancel context after a short delay
go func() {
Expand Down Expand Up @@ -456,6 +457,7 @@ func TestWaitNotification_ContextCancellation(t *testing.T) {
cfg := testConfigWithPort(t, port)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

go func() {
time.Sleep(50 * time.Millisecond)
Expand Down
21 changes: 11 additions & 10 deletions pkg/api/middleware/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package middleware

import (
"context"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -262,7 +263,7 @@ func TestHTTPAuthMiddleware(t *testing.T) {
url += "?key=" + tt.queryParam
}

req := httptest.NewRequest(http.MethodGet, url, http.NoBody)
req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, url, http.NoBody)
if tt.authHeader != "" {
req.Header.Set("Authorization", tt.authHeader)
}
Expand Down Expand Up @@ -336,7 +337,7 @@ func TestWebSocketAuthHandler(t *testing.T) {
url += "?key=" + tt.queryParam
}

req := httptest.NewRequest(http.MethodGet, url, http.NoBody)
req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, url, http.NoBody)
if tt.authHeader != "" {
req.Header.Set("Authorization", tt.authHeader)
}
Expand Down Expand Up @@ -373,7 +374,7 @@ func TestHTTPAuthMiddleware_Integration(t *testing.T) {

// Test valid key - should reach all middlewares and handler
callCount = 0
req := httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.Header.Set("Authorization", "Bearer valid-key")
recorder := httptest.NewRecorder()
wrapped.ServeHTTP(recorder, req)
Expand All @@ -383,7 +384,7 @@ func TestHTTPAuthMiddleware_Integration(t *testing.T) {

// Test invalid key - should not reach subsequent middlewares or handler
callCount = 0
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req = httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.Header.Set("Authorization", "Bearer invalid-key")
recorder = httptest.NewRecorder()
wrapped.ServeHTTP(recorder, req)
Expand All @@ -393,7 +394,7 @@ func TestHTTPAuthMiddleware_Integration(t *testing.T) {

// Test no key - should not reach subsequent middlewares or handler
callCount = 0
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req = httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
recorder = httptest.NewRecorder()
wrapped.ServeHTTP(recorder, req)

Expand Down Expand Up @@ -445,7 +446,7 @@ func TestHTTPAuthMiddleware_LocalhostExempt(t *testing.T) {

wrapped := middleware(handler)

req := httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = tt.remoteAddr

recorder := httptest.NewRecorder()
Expand Down Expand Up @@ -487,7 +488,7 @@ func TestWebSocketAuthHandler_LocalhostExempt(t *testing.T) {

cfg := NewAuthConfig(keysProvider([]string{"secret-key"}))

req := httptest.NewRequest(http.MethodGet, "/ws", http.NoBody)
req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/ws", http.NoBody)
req.RemoteAddr = tt.remoteAddr

result := WebSocketAuthHandler(cfg, req)
Expand Down Expand Up @@ -546,7 +547,7 @@ func TestHTTPAuthMiddleware_HotReload(t *testing.T) {
wrapped := middleware(handler)

// Request with valid key should succeed
req := httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.100:12345" // Non-localhost to require auth
req.Header.Set("Authorization", "Bearer secret")
recorder := httptest.NewRecorder()
Expand All @@ -557,15 +558,15 @@ func TestHTTPAuthMiddleware_HotReload(t *testing.T) {
keys = []string{"new-secret"}

// Old key should now fail
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req = httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.100:12345"
req.Header.Set("Authorization", "Bearer secret")
recorder = httptest.NewRecorder()
wrapped.ServeHTTP(recorder, req)
assert.Equal(t, http.StatusUnauthorized, recorder.Code)

// New key should succeed
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req = httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.100:12345"
req.Header.Set("Authorization", "Bearer new-secret")
recorder = httptest.NewRecorder()
Expand Down
15 changes: 8 additions & 7 deletions pkg/api/middleware/ipfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package middleware

import (
"context"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -312,7 +313,7 @@ func TestHTTPIPFilterMiddleware(t *testing.T) {

wrapped := middleware(handler)

req := httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = tt.remoteAddr

recorder := httptest.NewRecorder()
Expand Down Expand Up @@ -351,7 +352,7 @@ func TestHTTPIPFilterMiddleware_Integration(t *testing.T) {

// Test allowed IP - should reach all middlewares and handler
callCount = 0
req := httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.100:12345"
recorder := httptest.NewRecorder()
wrapped.ServeHTTP(recorder, req)
Expand All @@ -361,7 +362,7 @@ func TestHTTPIPFilterMiddleware_Integration(t *testing.T) {

// Test blocked IP - should not reach subsequent middlewares or handler
callCount = 0
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req = httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "10.0.0.1:12345"
recorder = httptest.NewRecorder()
wrapped.ServeHTTP(recorder, req)
Expand Down Expand Up @@ -515,14 +516,14 @@ func TestHTTPIPFilterMiddleware_HotReload(t *testing.T) {
wrapped := middleware(handler)

// Request from allowed IP should succeed
req := httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.100:12345"
recorder := httptest.NewRecorder()
wrapped.ServeHTTP(recorder, req)
assert.Equal(t, http.StatusOK, recorder.Code)

// Request from blocked IP should fail
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req = httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.200:12345"
recorder = httptest.NewRecorder()
wrapped.ServeHTTP(recorder, req)
Expand All @@ -532,14 +533,14 @@ func TestHTTPIPFilterMiddleware_HotReload(t *testing.T) {
allowedIPs = []string{"192.168.1.200"}

// Old IP should now be blocked
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req = httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.100:12345"
recorder = httptest.NewRecorder()
wrapped.ServeHTTP(recorder, req)
assert.Equal(t, http.StatusForbidden, recorder.Code)

// New IP should now be allowed
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req = httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.200:12345"
recorder = httptest.NewRecorder()
wrapped.ServeHTTP(recorder, req)
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/server_fileserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package api

import (
"context"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -136,7 +137,7 @@ func TestFsCustom404(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

req := httptest.NewRequest(http.MethodGet, tt.path, http.NoBody)
req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, tt.path, http.NoBody)
rec := httptest.NewRecorder()

handler.ServeHTTP(rec, req)
Expand Down Expand Up @@ -176,7 +177,7 @@ func TestFsCustom404_MissingIndex(t *testing.T) {

handler := fsCustom404(http.FS(mockFS))

req := httptest.NewRequest(http.MethodGet, "/unknown", http.NoBody)
req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/unknown", http.NoBody)
rec := httptest.NewRecorder()

handler.ServeHTTP(rec, req)
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/server_pna_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package api

import (
"context"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -79,7 +80,7 @@ func TestPrivateNetworkAccessMiddleware(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

req := httptest.NewRequest(tt.method, "/api", http.NoBody)
req := httptest.NewRequestWithContext(context.Background(), tt.method, "/api", http.NoBody)
if tt.requestPNAHeader != "" {
req.Header.Set("Access-Control-Request-Private-Network", tt.requestPNAHeader)
}
Expand Down
Loading
Loading