Lint / Lint (push) Successful in 1m29s
Security / Secrets (gitleaks) (push) Successful in 1m11s
Security / Dependencies (Trivy) (push) Successful in 1m59s
Tests / Dashboard checks (push) Successful in 1m49s
Security / Code (Semgrep) (push) Successful in 3m8s
Tests / Go backend (push) Successful in 2m50s
Docker / Docker Build & Push (push) Successful in 8m42s
- Target API 37 and use build-tools 37 for release signature checks - Adjust list pagination spacing and clarify shared backend docs
42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package media
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
sharedauth "repos.gfranz.ch/Gabriel20xx/shared/backend/auth"
|
|
)
|
|
|
|
// TestMediaRoutesRefuseAnonymousRequests walks the media route table: every route mounted behind
|
|
// Require answers 401 to a caller with no session, before any handler runs. The Service has no
|
|
// database or CarrierNode client, so a request that got past the gate would panic.
|
|
func TestMediaRoutesRefuseAnonymousRequests(t *testing.T) {
|
|
auth := sharedauth.NewWithStore(loginRequiredStore{}, "session", false, "", "testproject")
|
|
router := chi.NewRouter()
|
|
New(Config{Auth: auth}).Mount(router)
|
|
|
|
for _, route := range []struct{ method, target string }{
|
|
{http.MethodPost, "/media/like"},
|
|
{http.MethodPost, "/media/save"},
|
|
{http.MethodGet, "/media/liked"},
|
|
{http.MethodPost, "/media/7/tags"},
|
|
{http.MethodPost, "/media/7/tags/funny/vote"},
|
|
{http.MethodGet, "/playlists"},
|
|
{http.MethodPost, "/playlists"},
|
|
{http.MethodDelete, "/playlists/3"},
|
|
{http.MethodPost, "/playlists/3/items"},
|
|
{http.MethodDelete, "/playlists/3/items"},
|
|
{http.MethodPatch, "/playlists/3/items/reorder"},
|
|
} {
|
|
response := httptest.NewRecorder()
|
|
router.ServeHTTP(response, httptest.NewRequest(route.method, route.target, strings.NewReader(`{}`)))
|
|
if response.Code != http.StatusUnauthorized {
|
|
t.Errorf("%s %s status = %d, want 401", route.method, route.target, response.Code)
|
|
}
|
|
}
|
|
}
|