From 87592be6d3586557b281cabb1f384b34605cd734 Mon Sep 17 00:00:00 2001 From: Junya Okabe <86868255+Okabe-Junya@users.noreply.github.com> Date: Mon, 7 Sep 2026 17:40:28 +0900 Subject: [PATCH] Remove orphaned testserver package (#4620) --- github/actions/testserver/server.go | 159 ---------------------------- go.mod | 2 +- 2 files changed, 1 insertion(+), 160 deletions(-) delete mode 100644 github/actions/testserver/server.go diff --git a/github/actions/testserver/server.go b/github/actions/testserver/server.go deleted file mode 100644 index abe9c197..00000000 --- a/github/actions/testserver/server.go +++ /dev/null @@ -1,159 +0,0 @@ -package testserver - -import ( - "net/http" - "net/http/httptest" - "strings" - "time" - - "github.com/golang-jwt/jwt/v4" - "github.com/onsi/ginkgo/v2" - "github.com/stretchr/testify/require" -) - -// New returns a new httptest.Server that handles the -// authentication requests neeeded to create a new client. Any requests not -// made to the /actions/runners/registration-token or -// /actions/runner-registration endpoints will be handled by the provided -// handler. The returned server is started and will be automatically closed -// when the test ends. -// -// TODO: this uses ginkgo interface _only_ to support our current controller tests -func New(t ginkgo.GinkgoTInterface, handler http.Handler, options ...actionsServerOption) *actionsServer { - s := NewUnstarted(t, handler, options...) - s.Start() - return s -} - -// TODO: this uses ginkgo interface _only_ to support our current controller tests -func NewUnstarted(t ginkgo.GinkgoTInterface, handler http.Handler, options ...actionsServerOption) *actionsServer { - s := httptest.NewUnstartedServer(handler) - server := &actionsServer{ - Server: s, - } - t.Cleanup(func() { - server.Close() - }) - - server.setDefaults(t) - - for _, option := range options { - option(server) - } - - h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // handle getRunnerRegistrationToken - if strings.HasSuffix(r.URL.Path, "/runners/registration-token") { - server.runnerRegistrationTokenHandler(w, r) - return - } - - // handle getActionsServiceAdminConnection - if strings.HasSuffix(r.URL.Path, "/actions/runner-registration") { - server.actionRegistrationTokenHandler(w, r) - return - } - - handler.ServeHTTP(w, r) - }) - - server.Config.Handler = h - - return server -} - -type actionsServerOption func(*actionsServer) - -func WithActionsToken(token string) actionsServerOption { - return func(s *actionsServer) { - s.token = token - } -} - -func WithRunnerRegistrationTokenHandler(h http.HandlerFunc) actionsServerOption { - return func(s *actionsServer) { - s.runnerRegistrationTokenHandler = h - } -} - -func WithActionsRegistrationTokenHandler(h http.HandlerFunc) actionsServerOption { - return func(s *actionsServer) { - s.actionRegistrationTokenHandler = h - } -} - -type actionsServer struct { - *httptest.Server - - token string - runnerRegistrationTokenHandler http.HandlerFunc - actionRegistrationTokenHandler http.HandlerFunc -} - -func (s *actionsServer) setDefaults(t ginkgo.GinkgoTInterface) { - if s.runnerRegistrationTokenHandler == nil { - s.runnerRegistrationTokenHandler = func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusCreated) - w.Write([]byte(`{"token":"token"}`)) - } - } - - if s.actionRegistrationTokenHandler == nil { - s.actionRegistrationTokenHandler = func(w http.ResponseWriter, r *http.Request) { - if s.token == "" { - s.token = DefaultActionsToken(t) - } - - w.WriteHeader(http.StatusCreated) - w.Write([]byte(`{"url":"` + s.URL + `/tenant/123/","token":"` + s.token + `"}`)) - } - } -} - -func (s *actionsServer) ConfigURLForOrg(org string) string { - return s.URL + "/" + org -} - -func DefaultActionsToken(t ginkgo.GinkgoTInterface) string { - claims := &jwt.RegisteredClaims{ - IssuedAt: jwt.NewNumericDate(time.Now().Add(-10 * time.Minute)), - ExpiresAt: jwt.NewNumericDate(time.Now().Add(10 * time.Minute)), - Issuer: "123", - } - - token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims) - privateKey, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(samplePrivateKey)) - require.NoError(t, err) - tokenString, err := token.SignedString(privateKey) - require.NoError(t, err) - return tokenString -} - -const samplePrivateKey = `-----BEGIN PRIVATE KEY----- -MIIEugIBADANBgkqhkiG9w0BAQEFAASCBKQwggSgAgEAAoIBAQC7tgquvNIp+Ik3 -rRVZ9r0zJLsSzTHqr2dA6EUUmpRiQ25MzjMqKqu0OBwvh/pZyfjSIk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P2mTOD/jfCmgR6f+z2zNbj9zAgO93at9+yDUl -AFPm2j7rQgBTa+HhACb+h6HDZebDMNsuqzmaTWZuJ+wr89VWV5c17QKBgH3jwNNQ -mCAIUidynaulQNfTOZIe7IMC7WK7g9CBmPkx7Y0uiXr6C25hCdJKFllLTP6vNWOy -uCcQqf8LhgDiilBDifO3op9xpyuOJlWMYocJVkxx3l2L/rSU07PYcbKNAFAxXuJ4 -xym51qZnkznMN5ei/CPFxVKeqHgaXDpekVStAoGAV3pSWAKDXY/42XEHixrCTqLW -kBxfaf3g7iFnl3u8+7Z/7Cb4ZqFcw0bRJseKuR9mFvBhcZxSErbMDEYrevefU9aM -APeCxEyw6hJXgbWKoG7Fw2g2HP3ytCJ4YzH0zNitHjk/1h4BG7z8cEQILCSv5mN2 -etFcaQuTHEZyRhhJ4BU= ------END PRIVATE KEY-----` diff --git a/go.mod b/go.mod index 43bdb097..8543c4db 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/evanphx/json-patch v5.9.11+incompatible github.com/go-logr/logr v1.4.3 - github.com/golang-jwt/jwt/v4 v4.5.2 github.com/google/go-cmp v0.7.0 github.com/google/go-github/v52 v52.0.0 github.com/google/uuid v1.6.0 @@ -116,6 +115,7 @@ require ( github.com/go-sql-driver/mysql v1.9.3 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/go-viper/mapstructure/v2 v2.5.0 // indirect + github.com/golang-jwt/jwt/v4 v4.5.2 // indirect github.com/golang-jwt/jwt/v5 v5.3.1 // indirect github.com/gonvenience/bunt v1.4.3 // indirect github.com/gonvenience/idem v0.0.3 // indirect