feat: add read-only mode to API and UI, disable write actions

This commit is contained in:
Sergey Krashevich
2026-02-01 04:13:43 +03:00
parent 6085c8aabe
commit cc453dd9ed
24 changed files with 438 additions and 8 deletions
+37
View File
@@ -0,0 +1,37 @@
package homekit
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/AlexxIT/go2rtc/internal/api"
"github.com/stretchr/testify/require"
)
func TestApiHomekitReadOnly(t *testing.T) {
prevReadOnly := api.ReadOnly
t.Cleanup(func() {
api.ReadOnly = prevReadOnly
})
api.ReadOnly = true
t.Run("POST blocked", func(t *testing.T) {
req := httptest.NewRequest("POST", "/api/homekit", nil)
w := httptest.NewRecorder()
apiHomekit(w, req)
require.Equal(t, http.StatusForbidden, w.Code)
})
t.Run("GET allowed", func(t *testing.T) {
req := httptest.NewRequest("GET", "/api/homekit", nil)
w := httptest.NewRecorder()
apiHomekit(w, req)
require.Equal(t, http.StatusOK, w.Code)
})
}