mirror of
https://github.com/go-shiori/shiori.git
synced 2025-11-10 23:31:20 +08:00
* refactor: base http server stdlib * refactor: swagger and frontend routes * fix: use global middlewares * refactor: removed gin from testutils * fix: object references in legacy webserver * refactor: legacy, swagger and system handlers * fix: added verbs to handlers * fix: server handlers ordering * refactor: bookmarks handlers * refactor: system api routes * tests: bookmark handlers * refactor: migrated api auth routes * chore: remove unused middlewares * docs: add swagger docs to refactored system api * chore: remove old auth routes * refactor: account apis * chore: removed old handlers * fix: api v1 handlers missing middlewares * refactor: migrated tag list route * refactor: bookmark routes * refactor: remove gin * chore: make styles * test: fixed tests * test: generate binary file without text * fix: global middleware missing from system api handler * fix: incorrect api handler * chore: avoid logging screenshot contents * tests: bookmarks domain * tests: shortcuts * test: missing tests * tests: server tests * test: remove test using syscall to avoid windows errors * chore: added middlewares
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package api_v1
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/go-shiori/shiori/internal/testutil"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestHandleSystemInfo(t *testing.T) {
|
|
logger := logrus.New()
|
|
_, deps := testutil.GetTestConfigurationAndDependencies(t, context.Background(), logger)
|
|
|
|
t.Run("requires authentication", func(t *testing.T) {
|
|
c, w := testutil.NewTestWebContext()
|
|
HandleSystemInfo(deps, c)
|
|
require.Equal(t, http.StatusUnauthorized, w.Code)
|
|
})
|
|
|
|
t.Run("requires admin access", func(t *testing.T) {
|
|
c, w := testutil.NewTestWebContext()
|
|
testutil.SetFakeUser(c)
|
|
HandleSystemInfo(deps, c)
|
|
require.Equal(t, http.StatusForbidden, w.Code)
|
|
})
|
|
|
|
t.Run("returns system info for admin", func(t *testing.T) {
|
|
c, w := testutil.NewTestWebContext()
|
|
testutil.SetFakeAdmin(c)
|
|
HandleSystemInfo(deps, c)
|
|
|
|
require.Equal(t, http.StatusOK, w.Code)
|
|
require.Equal(t, "application/json", w.Header().Get("Content-Type"))
|
|
|
|
response, err := testutil.NewTestResponseFromReader(w.Body)
|
|
require.NoError(t, err)
|
|
|
|
response.AssertOk(t)
|
|
response.AssertMessageContains(t, "version")
|
|
response.AssertMessageContains(t, "database")
|
|
response.AssertMessageContains(t, "os")
|
|
})
|
|
}
|