Skip to content
Merged
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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module github.com/ZaparooProject/zaparoo-core/v2

go 1.25.7
go 1.26.1

require (
fyne.io/systray v1.11.0
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/Microsoft/go-winio v0.6.2
github.com/ZaparooProject/go-pn532 v0.20.3
github.com/ZaparooProject/go-zapscript v0.1.0
github.com/ZaparooProject/go-zapscript v0.2.0
github.com/adrg/xdg v0.5.3
github.com/andygrunwald/vdf v1.1.0
github.com/bendahl/uinput v1.7.0
Expand Down Expand Up @@ -76,7 +76,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidmz/go-pageant v1.0.2 // indirect
github.com/ebitengine/purego v0.9.1 // indirect
github.com/expr-lang/expr v1.17.7 // indirect
github.com/expr-lang/expr v1.17.8 // indirect
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
github.com/gdamore/encoding v1.0.1 // indirect
github.com/geoffgarside/ber v1.1.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/ZaparooProject/go-pn532 v0.20.3 h1:okjV/BVttJZvjXDZ0wuNlI165iT3N9g1B+
github.com/ZaparooProject/go-pn532 v0.20.3/go.mod h1:38r+NvAyNsUa/McJC4FEk2+uxOzrN1AUgrh/fpc0oLk=
github.com/ZaparooProject/go-zapscript v0.1.0 h1:IlDzx4WsYOy17cADbWyegIjB7wprAy6dNr6WsXyx/Ts=
github.com/ZaparooProject/go-zapscript v0.1.0/go.mod h1:mXkIhNUoWCdsoUkjFPmbVba9PTkzD5H4ntmIxnNNSD0=
github.com/ZaparooProject/go-zapscript v0.2.0 h1:MrZ1923LgLCcybX7kO5uJEHM8tZn995tXzJsSkK0Ep4=
github.com/ZaparooProject/go-zapscript v0.2.0/go.mod h1:P5qov6iCMzYiSF3tqr8BAanvNNh/YjPuUENfmPo6Yj4=
github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78=
github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ=
github.com/andygrunwald/vdf v1.1.0 h1:gmstp0R7DOepIZvWoSJY97ix7QOrsxpGPU6KusKXqvw=
Expand Down Expand Up @@ -57,6 +59,8 @@ github.com/eclipse/paho.mqtt.golang v1.5.1 h1:/VSOv3oDLlpqR2Epjn1Q7b2bSTplJIeV2I
github.com/eclipse/paho.mqtt.golang v1.5.1/go.mod h1:1/yJCneuyOoCOzKSsOTUc0AJfpsItBGWvYpBLimhArU=
github.com/expr-lang/expr v1.17.7 h1:Q0xY/e/2aCIp8g9s/LGvMDCC5PxYlvHgDZRQ4y16JX8=
github.com/expr-lang/expr v1.17.7/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/expr-lang/expr v1.17.8 h1:W1loDTT+0PQf5YteHSTpju2qfUfNoBt4yw9+wOEU9VM=
github.com/expr-lang/expr v1.17.8/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
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
5 changes: 3 additions & 2 deletions pkg/api/methods/media_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ func HandleMediaControl(env requests.RequestEnv) (any, error) { //nolint:gocriti
var err error
switch {
case control.Func != nil:
err = control.Func(env.Config, platforms.ControlParams{Args: params.Args})
err = control.Func(env.Context, env.Config, platforms.ControlParams{Args: params.Args})
case control.Script != "":
err = zapscript.RunControlScript(env.Platform, env.Config, env.Database, env.State, control.Script)
exprEnv := zapscript.GetExprEnv(env.Platform, env.Config, env.State, nil, nil)
err = zapscript.RunControlScript(env.Platform, env.Config, env.Database, control.Script, &exprEnv)
default:
err = fmt.Errorf("control %q has no implementation", params.Action)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/methods/media_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestHandleMediaControl_UnknownAction(t *testing.T) {
ID: "test-launcher",
SystemID: "NES",
Controls: map[string]platforms.Control{
"save_state": {Func: func(_ *config.Instance, _ platforms.ControlParams) error {
"save_state": {Func: func(_ context.Context, _ *config.Instance, _ platforms.ControlParams) error {
return nil
}},
},
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestHandleMediaControl_Success(t *testing.T) {
ID: "test-launcher",
SystemID: "NES",
Controls: map[string]platforms.Control{
"save_state": {Func: func(_ *config.Instance, _ platforms.ControlParams) error {
"save_state": {Func: func(_ context.Context, _ *config.Instance, _ platforms.ControlParams) error {
called = true
return nil
}},
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestHandleMediaControl_ArgsPassThrough(t *testing.T) {
ID: "test-launcher",
SystemID: "NES",
Controls: map[string]platforms.Control{
"save_state": {Func: func(_ *config.Instance, cp platforms.ControlParams) error {
"save_state": {Func: func(_ context.Context, _ *config.Instance, cp platforms.ControlParams) error {
receivedArgs = cp.Args
return nil
}},
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestHandleMediaControl_ArgsNilWhenOmitted(t *testing.T) {
ID: "test-launcher",
SystemID: "NES",
Controls: map[string]platforms.Control{
"save_state": {Func: func(_ *config.Instance, cp platforms.ControlParams) error {
"save_state": {Func: func(_ context.Context, _ *config.Instance, cp platforms.ControlParams) error {
receivedArgs = cp.Args
return nil
}},
Expand Down
10 changes: 10 additions & 0 deletions pkg/api/middleware/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func TestHTTPAuthMiddleware(t *testing.T) {
url += "?key=" + tt.queryParam
}

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

//nolint:noctx // test helper, no context needed
req := httptest.NewRequest(http.MethodGet, url, http.NoBody)
if tt.authHeader != "" {
req.Header.Set("Authorization", tt.authHeader)
Expand Down Expand Up @@ -373,6 +375,7 @@ func TestHTTPAuthMiddleware_Integration(t *testing.T) {

// Test valid key - should reach all middlewares and handler
callCount = 0
//nolint:noctx // test helper, no context needed
req := httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req.Header.Set("Authorization", "Bearer valid-key")
recorder := httptest.NewRecorder()
Expand All @@ -383,6 +386,7 @@ func TestHTTPAuthMiddleware_Integration(t *testing.T) {

// Test invalid key - should not reach subsequent middlewares or handler
callCount = 0
//nolint:noctx // test helper, no context needed
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req.Header.Set("Authorization", "Bearer invalid-key")
recorder = httptest.NewRecorder()
Expand All @@ -393,6 +397,7 @@ func TestHTTPAuthMiddleware_Integration(t *testing.T) {

// Test no key - should not reach subsequent middlewares or handler
callCount = 0
//nolint:noctx // test helper, no context needed
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
recorder = httptest.NewRecorder()
wrapped.ServeHTTP(recorder, req)
Expand Down Expand Up @@ -445,6 +450,7 @@ func TestHTTPAuthMiddleware_LocalhostExempt(t *testing.T) {

wrapped := middleware(handler)

//nolint:noctx // test helper, no context needed
req := httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = tt.remoteAddr

Expand Down Expand Up @@ -487,6 +493,7 @@ func TestWebSocketAuthHandler_LocalhostExempt(t *testing.T) {

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

//nolint:noctx // test helper, no context needed
req := httptest.NewRequest(http.MethodGet, "/ws", http.NoBody)
req.RemoteAddr = tt.remoteAddr

Expand Down Expand Up @@ -546,6 +553,7 @@ func TestHTTPAuthMiddleware_HotReload(t *testing.T) {
wrapped := middleware(handler)

// Request with valid key should succeed
//nolint:noctx // test helper, no context needed
req := httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.100:12345" // Non-localhost to require auth
req.Header.Set("Authorization", "Bearer secret")
Expand All @@ -557,6 +565,7 @@ func TestHTTPAuthMiddleware_HotReload(t *testing.T) {
keys = []string{"new-secret"}

// Old key should now fail
//nolint:noctx // test helper, no context needed
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.100:12345"
req.Header.Set("Authorization", "Bearer secret")
Expand All @@ -565,6 +574,7 @@ func TestHTTPAuthMiddleware_HotReload(t *testing.T) {
assert.Equal(t, http.StatusUnauthorized, recorder.Code)

// New key should succeed
//nolint:noctx // test helper, no context needed
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.100:12345"
req.Header.Set("Authorization", "Bearer new-secret")
Expand Down
7 changes: 7 additions & 0 deletions pkg/api/middleware/ipfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ func TestHTTPIPFilterMiddleware(t *testing.T) {

wrapped := middleware(handler)

//nolint:noctx // test helper, no context needed
req := httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = tt.remoteAddr

Expand Down Expand Up @@ -351,6 +352,7 @@ func TestHTTPIPFilterMiddleware_Integration(t *testing.T) {

// Test allowed IP - should reach all middlewares and handler
callCount = 0
//nolint:noctx // test helper, no context needed
req := httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.100:12345"
recorder := httptest.NewRecorder()
Expand All @@ -361,6 +363,7 @@ func TestHTTPIPFilterMiddleware_Integration(t *testing.T) {

// Test blocked IP - should not reach subsequent middlewares or handler
callCount = 0
//nolint:noctx // test helper, no context needed
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "10.0.0.1:12345"
recorder = httptest.NewRecorder()
Expand Down Expand Up @@ -515,13 +518,15 @@ func TestHTTPIPFilterMiddleware_HotReload(t *testing.T) {
wrapped := middleware(handler)

// Request from allowed IP should succeed
//nolint:noctx // test helper, no context needed
req := httptest.NewRequest(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
//nolint:noctx // test helper, no context needed
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.200:12345"
recorder = httptest.NewRecorder()
Expand All @@ -532,13 +537,15 @@ func TestHTTPIPFilterMiddleware_HotReload(t *testing.T) {
allowedIPs = []string{"192.168.1.200"}

// Old IP should now be blocked
//nolint:noctx // test helper, no context needed
req = httptest.NewRequest(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
//nolint:noctx // test helper, no context needed
req = httptest.NewRequest(http.MethodGet, "/test", http.NoBody)
req.RemoteAddr = "192.168.1.200:12345"
recorder = httptest.NewRecorder()
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/server_fileserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func TestFsCustom404(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

//nolint:noctx // test helper, no context needed
req := httptest.NewRequest(http.MethodGet, tt.path, http.NoBody)
rec := httptest.NewRecorder()

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

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

//nolint:noctx // test helper, no context needed
req := httptest.NewRequest(http.MethodGet, "/unknown", http.NoBody)
rec := httptest.NewRecorder()

Expand Down
1 change: 1 addition & 0 deletions pkg/api/server_pna_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestPrivateNetworkAccessMiddleware(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

//nolint:noctx // test helper, no context needed
req := httptest.NewRequest(tt.method, "/api", http.NoBody)
if tt.requestPNAHeader != "" {
req.Header.Set("Access-Control-Request-Private-Network", tt.requestPNAHeader)
Expand Down
Loading
Loading