mirror of
https://github.com/actions-runner-controller/actions-runner-controller.git
synced 2026-10-07 03:02:06 +02:00
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:
co-authored by
Bassem Dghaidi
Nikola Jokic
Tingluo Huang
parent
068f987238
commit
c569304271
@@ -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")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user