diff --git a/apis/actions.github.com/v1alpha1/tls_config_test.go b/apis/actions.github.com/v1alpha1/tls_config_test.go deleted file mode 100644 index e05bf81b..00000000 --- a/apis/actions.github.com/v1alpha1/tls_config_test.go +++ /dev/null @@ -1,105 +0,0 @@ -package v1alpha1_test - -import ( - "crypto/tls" - "crypto/x509" - "net/http" - "os" - "path/filepath" - "testing" - - "github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1" - "github.com/actions/actions-runner-controller/github/actions/testserver" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - v1 "k8s.io/api/core/v1" -) - -func TestGitHubServerTLSConfig_ToCertPool(t *testing.T) { - t.Run("returns an error if CertificateFrom not specified", func(t *testing.T) { - c := &v1alpha1.TLSConfig{ - CertificateFrom: nil, - } - - pool, err := c.ToCertPool(nil) - assert.Nil(t, pool) - - require.Error(t, err) - assert.Equal(t, err.Error(), "certificateFrom not specified") - }) - - t.Run("returns an error if CertificateFrom.ConfigMapKeyRef not specified", func(t *testing.T) { - c := &v1alpha1.TLSConfig{ - CertificateFrom: &v1alpha1.TLSCertificateSource{}, - } - - pool, err := c.ToCertPool(nil) - assert.Nil(t, pool) - - require.Error(t, err) - assert.Equal(t, err.Error(), "configMapKeyRef not specified") - }) - - t.Run("returns a valid cert pool with correct configuration", func(t *testing.T) { - c := &v1alpha1.TLSConfig{ - CertificateFrom: &v1alpha1.TLSCertificateSource{ - ConfigMapKeyRef: &v1.ConfigMapKeySelector{ - LocalObjectReference: v1.LocalObjectReference{ - Name: "name", - }, - Key: "key", - }, - }, - } - - certsFolder := filepath.Join( - "../../../", - "github", - "actions", - "testdata", - ) - - fetcher := func(name, key string) ([]byte, error) { - cert, err := os.ReadFile(filepath.Join(certsFolder, "rootCA.crt")) - require.NoError(t, err) - - pool := x509.NewCertPool() - ok := pool.AppendCertsFromPEM(cert) - assert.True(t, ok) - - return cert, nil - } - - pool, err := c.ToCertPool(fetcher) - require.NoError(t, err) - require.NotNil(t, pool) - - // can be used to communicate with a server - serverSuccessfullyCalled := false - server := testserver.NewUnstarted(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - serverSuccessfullyCalled = true - w.WriteHeader(http.StatusOK) - })) - - cert, err := tls.LoadX509KeyPair( - filepath.Join(certsFolder, "server.crt"), - filepath.Join(certsFolder, "server.key"), - ) - require.NoError(t, err) - - server.TLS = &tls.Config{Certificates: []tls.Certificate{cert}} - server.StartTLS() - - client := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{ - RootCAs: pool, - }, - }, - } - - _, err = client.Get(server.URL) - assert.NoError(t, err) - assert.True(t, serverSuccessfullyCalled) - }) -} diff --git a/cmd/ghalistener/config/config_client_test.go b/cmd/ghalistener/config/config_client_test.go index 797adf9c..2997b64f 100644 --- a/cmd/ghalistener/config/config_client_test.go +++ b/cmd/ghalistener/config/config_client_test.go @@ -1,18 +1,13 @@ package config_test import ( - "context" - "crypto/tls" "encoding/json" "log/slog" - "net/http" "os" - "path/filepath" "testing" "github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1/appconfig" "github.com/actions/actions-runner-controller/cmd/ghalistener/config" - "github.com/actions/actions-runner-controller/github/actions/testserver" "github.com/actions/scaleset" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -20,54 +15,6 @@ import ( var discardLogger = slog.New(slog.DiscardHandler) -func TestCustomerServerRootCA(t *testing.T) { - ctx := context.Background() - certsFolder := filepath.Join( - "../../../", - "github", - "actions", - "testdata", - ) - certPath := filepath.Join(certsFolder, "server.crt") - keyPath := filepath.Join(certsFolder, "server.key") - - serverCalledSuccessfully := false - - server := testserver.NewUnstarted(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - serverCalledSuccessfully = true - w.WriteHeader(http.StatusOK) - w.Write([]byte(`{"count": 0}`)) - })) - cert, err := tls.LoadX509KeyPair(certPath, keyPath) - require.NoError(t, err) - - server.TLS = &tls.Config{Certificates: []tls.Certificate{cert}} - server.StartTLS() - - var certsString string - rootCA, err := os.ReadFile(filepath.Join(certsFolder, "rootCA.crt")) - require.NoError(t, err) - certsString = string(rootCA) - - intermediate, err := os.ReadFile(filepath.Join(certsFolder, "intermediate.crt")) - require.NoError(t, err) - certsString = certsString + string(intermediate) - - config := config.Config{ - ConfigureURL: server.ConfigURLForOrg("myorg"), - ServerRootCA: certsString, - AppConfig: &appconfig.AppConfig{ - Token: "token", - }, - } - - client, err := config.ActionsClient(discardLogger) - require.NoError(t, err) - _, err = client.GetRunnerScaleSet(ctx, 1, "test") - require.NoError(t, err) - assert.True(t, serverCalledSuccessfully) -} - func TestProxySettings(t *testing.T) { assertHasProxy := func(t *testing.T, debugInfo string, want bool) { type debugInfoContent struct { diff --git a/controllers/actions.github.com/ephemeralrunner_controller_test.go b/controllers/actions.github.com/ephemeralrunner_controller_test.go index 24d11e15..bbb87275 100644 --- a/controllers/actions.github.com/ephemeralrunner_controller_test.go +++ b/controllers/actions.github.com/ephemeralrunner_controller_test.go @@ -13,7 +13,6 @@ import ( "time" "github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1" - "github.com/actions/actions-runner-controller/github/actions" "github.com/actions/actions-runner-controller/controllers/actions.github.com/multiclient" scalefake "github.com/actions/actions-runner-controller/controllers/actions.github.com/multiclient/fake" @@ -1113,12 +1112,7 @@ var _ = Describe("EphemeralRunner", func() { scalefake.NewClient( scalefake.WithGetRunner( nil, - &actions.ActionsError{ - StatusCode: http.StatusNotFound, - Err: &actions.ActionsExceptionError{ - ExceptionName: "AgentNotFoundException", - }, - }, + scaleset.RunnerNotFoundError, ), scalefake.WithGenerateJitRunnerConfig( &scaleset.RunnerScaleSetJitRunnerConfig{