fix: 代理 Runner 仓库 HTTP 流量
This commit is contained in:
@@ -130,6 +130,31 @@ func TestAPIHandlerMatchesOfficialRunnerBasePath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerProxiesRepositoryTrafficToGitea(t *testing.T) {
|
||||
upstream := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
|
||||
if request.URL.Path != "/owner/repo/info/refs" || request.Header.Get("Authorization") != "Basic checkout-token" {
|
||||
t.Errorf("request path=%q authorization=%q", request.URL.Path, request.Header.Get("Authorization"))
|
||||
response.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
response.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer upstream.Close()
|
||||
|
||||
facade, _, _ := testFacade(t)
|
||||
handler, err := Handler(facade, upstream.URL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
request := httptest.NewRequest(http.MethodGet, "http://facade/owner/repo/info/refs", nil)
|
||||
request.Header.Set("Authorization", "Basic checkout-token")
|
||||
response := httptest.NewRecorder()
|
||||
handler.ServeHTTP(response, request)
|
||||
if response.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d", response.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFacadeRejectsWrongIdentityOrCapability(t *testing.T) {
|
||||
facade, assignment, token := testFacade(t)
|
||||
wrongIdentity := WithSPIFFEID(context.Background(), "spiffe://ddupan.top/ci/owner/repo/other")
|
||||
|
||||
Reference in New Issue
Block a user