Files
skillshare/internal/server/handler_search_test.go
T
Willie 1d0ee69955 feat: support SSH hub sources for private and GHE hosts
Hub index fetch previously handled only unauthenticated HTTP(S) GET or
local file paths, leaving private and GitHub Enterprise repos out of
reach — raw HTTPS URLs redirect to login before token headers apply, and
SSH-style hub URLs were unrecognized.

Resolve SSH hub sources by shallow-cloning the repo with the user's SSH
keys and reading the index from it. The in-repo index path uses the
existing //path subdir convention (consistent with `install`), defaulting
to skillshare-hub.json at the repo root. Both scp-style and ssh:// URLs
are accepted. In the web dashboard, SSH clones are restricted to saved
hubs so a request-supplied URL can't drive an arbitrary clone.

Ref #185
2026-06-02 16:29:25 +08:00

38 lines
925 B
Go

package server
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
"skillshare/internal/config"
)
func TestSavedHubURLSet(t *testing.T) {
hub := config.HubConfig{Hubs: []config.HubEntry{
{Label: "team", URL: "git@ghe.corp.com:team/skills.git"},
{Label: "blank", URL: " "},
}}
set := savedHubURLSet(hub)
if !set["git@ghe.corp.com:team/skills.git"] {
t.Error("expected saved SSH hub URL to be in set")
}
if set[""] {
t.Error("blank URL should not be added to set")
}
}
func TestHandleSearch_SSHHubNotSaved_Forbidden(t *testing.T) {
s, _ := newTestServer(t)
target := "/api/search?q=x&hub=" + url.QueryEscape("git@ghe.corp.com:team/skills.git")
req := httptest.NewRequest(http.MethodGet, target, nil)
rr := httptest.NewRecorder()
s.handler.ServeHTTP(rr, req)
if rr.Code != http.StatusForbidden {
t.Fatalf("expected 403 for unsaved SSH hub, got %d: %s", rr.Code, rr.Body.String())
}
}