Add support for self-signed CA certificates (#2268)

Co-authored-by: Bassem Dghaidi <568794+Link-@users.noreply.github.com>
Co-authored-by: Nikola Jokic <jokicnikola07@gmail.com>
Co-authored-by: Tingluo Huang <tingluohuang@github.com>
This commit is contained in:
Francesco Renzi
2023-03-09 17:23:32 +00:00
committed by GitHub
co-authored by Bassem Dghaidi Nikola Jokic Tingluo Huang
parent 068f987238
commit c569304271
36 changed files with 1860 additions and 93 deletions
+47
View File
@@ -1,6 +1,9 @@
package actions_test
import (
"crypto/x509"
"os"
"path/filepath"
"testing"
"github.com/actions/actions-runner-controller/github/actions"
@@ -108,4 +111,48 @@ func TestClient_Identifier(t *testing.T) {
})
}
})
t.Run("changes in TLS config", func(t *testing.T) {
configURL := "https://github.com/org/repo"
defaultCreds := &actions.ActionsAuth{
Token: "token",
}
noTlS, err := actions.NewClient(configURL, defaultCreds)
require.NoError(t, err)
poolFromCert := func(t *testing.T, path string) *x509.CertPool {
t.Helper()
f, err := os.ReadFile(path)
require.NoError(t, err)
pool := x509.NewCertPool()
require.True(t, pool.AppendCertsFromPEM(f))
return pool
}
root, err := actions.NewClient(
configURL,
defaultCreds,
actions.WithRootCAs(poolFromCert(t, filepath.Join("testdata", "rootCA.crt"))),
)
require.NoError(t, err)
chain, err := actions.NewClient(
configURL,
defaultCreds,
actions.WithRootCAs(poolFromCert(t, filepath.Join("testdata", "intermediate.pem"))),
)
require.NoError(t, err)
clients := []*actions.Client{
noTlS,
root,
chain,
}
identifiers := map[string]struct{}{}
for _, client := range clients {
identifiers[client.Identifier()] = struct{}{}
}
assert.Len(t, identifiers, len(clients), "all clients should have a unique identifier")
})
}