Skip to content

Commit

Permalink
Use certificates in end-to-end tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardGomezEscandell committed Oct 18, 2023
1 parent ffa07b6 commit fa3606c
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 4 deletions.
2 changes: 0 additions & 2 deletions end-to-end/organization_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ func TestOrganizationProvidedToken(t *testing.T) {
testSetup(t)

lis, server, landscapeService := setUpLandscapeMock(t, ctx, "localhost:")
writeUbuntuProRegistry(t, "LandscapeAgentURL", lis.Addr().String())

go func() {
if err := server.Serve(lis); err != nil {
log.Printf("Landscape server exited with an error: %v", err)
}
}()
defer server.Stop()
defer server.Stop()

proToken := os.Getenv(proTokenEnv)
require.NotEmptyf(t, proToken, "Setup: environment variable %q should contain a valid pro token, but is empty", proTokenEnv)
Expand Down
32 changes: 32 additions & 0 deletions end-to-end/testdata/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-----BEGIN CERTIFICATE-----
MIIFdDCCA1ygAwIBAgIUYVCcZCPg7h/nnpPCBnuOANV32BswDQYJKoZIhvcNAQEL
BQAwQTELMAkGA1UEBhMCVVMxEjAQBgNVBAoMCUNhbm9uaWNhbDEeMBwGA1UEAwwV
Q2Fub25pY2FsR3JvdXBMaW1pdGVkMB4XDTIzMTAxODA3NTgxOVoXDTIzMTExNzA3
NTgxOVowQTELMAkGA1UEBhMCVVMxEjAQBgNVBAoMCUNhbm9uaWNhbDEeMBwGA1UE
AwwVQ2Fub25pY2FsR3JvdXBMaW1pdGVkMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A
MIICCgKCAgEAxSYsyFpJI+xqx4Bor91vrIJhm9cjJyIvsUqKXpV/W7XS4dwm3w7x
V4rOXSFwPfBEOuRDnFZe6edmhj6T2aSBYrake0WUWpzcVnrAh8Deu/1fEpkK8NkE
W1VBSW+8aVVTZm1Xo8PAYY4omXm2me6qIfHW/6ta4LiV41AckdaI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J/3b8NVHPBdtNV2KLoJuEMVFBU5dWAcH/9L
sxBnUFbhL+13rBd8W82XarrRcDGiMmAkFbDNqzjDW6rDXNq+ATIyY93KDStrU9a9
qm3DUoOlJGmggWd7hTTqxXjmGA2SQmsg//+pel+dvgva9PcE6RbPujN6/EpSCjps
SF4vI0des3U7IX+uU7c3AQ4Cq0BKuWaZq7vHrCksx4yipVMiomgEdouXmrn2GlOr
6sjDBd1wSyFv05Zo5K+0gGzmtPep0SEdsMJoxLkQIX5qOXKetpNwNuUtKBc2asuv
oHV2TbCL6Yw=
-----END CERTIFICATE-----
52 changes: 52 additions & 0 deletions end-to-end/testdata/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDFJizIWkkj7GrH
gGiv3W+sgmGb1yMnIi+xSopelX9btdLh3CbfDvFXis5dIXA98EQ65EOcVl7p52aG
PpPZpIFitqR7RZRanNxWesCHwN67/V8SmQrw2QRbVUFJb7xpVVNmbVejw8BhjiiZ
ebaZ7qoh8db/q1rguJXjUByR1ohsgURC9HE4PCXtyv7kPDcdKQqaANPi4WEyYEio
JpDK1OAnCGS+rssBXBPPOuMVPmKr9/dZL7KmUVUdGq1XJmiY2bwHojn2WVM5W2Km
TsWtCmUuamw0z4sxcURLW+Ulf03h82zgf5u7Oex7eEsyd4tRzMVdm5LMbDC9gaBl
5wb5cCl6ie0xQoW859hU0LWs2KCVNfXbOD6naSXq6cO70lDmX2hmB/L8TswO8dqf
q4crMhU6ouudjWKKaxe+Lth2Jq227JB2oDgq7AxghoFmVwlVQX4gK9DLf2nLxy9c
86t+E1DjvTXvQsxC3xxbATy9ucE2P5ehLYeXoYPwlxybuOcIfv+aPoLpTS/CW9Cj
jFosDuLbGf8JJiHMpyc77920WJoHfBKMkJRFwjoLD48ZTIyeATbyd8R+m5acBPB5
l9z/v3go8XWwGVOp6HWQn6ifvoRv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HT33c2YWOtm3ca1q0Afdh5f4iRjjO
PSECggEADJ+fDkmlggdiPjF4s9ognFe/6kWaMYleQOx6zU2wDcjri4iKNfS80Z2A
0jCnUddYbkOJhoo+7FQr7itg3IndDWyN3uPJPVqk+Yg48JMZUZVDzCUT8w1p3LWE
BbIl2IkkQAOvA4x/F2xImlb5k2sCAypZqIFwIC3miMqtq0mXzkpEqFHq8hYkvJ/Z
5nB9LLvcZWaIoHhieuRNhaeKjPpfeFL83Wr56CHmBxK2TlXxqvA17r9zzX3yuQi8
j+1b11ZkDOvd0pfoXDHiyJzZab6e+Fm7Vo+ztwQ9zFNqGiV5P/nx2oMWMqQzbZP2
2PMZ+1fCA7xGpJCGK3EUi6QPKXauEg==
-----END PRIVATE KEY-----
2 changes: 2 additions & 0 deletions end-to-end/testdata/landscape.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[client]
ssl_public_key = testdata/cert.pem
23 changes: 21 additions & 2 deletions end-to-end/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package endtoend_test
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
Expand All @@ -24,6 +25,7 @@ import (
wsl "github.com/ubuntu/gowsl"
"golang.org/x/sys/windows/registry"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)

func testSetup(t *testing.T) {
Expand Down Expand Up @@ -186,6 +188,8 @@ func logWslProServiceJournal(t *testing.T, ctx context.Context, d wsl.Distro) {
t.Logf("wsl-pro-service logs:\n%s\n", out)
}

// setUpLandscapeMock sets up the Landscape mock server (but does not start it). It also sets up the registry so the Windows Agent can connect to it.
//
//nolint:revive // Context goes after testing.T
func setUpLandscapeMock(t *testing.T, ctx context.Context, addr string) (lis net.Listener, server *grpc.Server, service *landscapemockservice.Service) {
t.Helper()
Expand All @@ -194,10 +198,25 @@ func setUpLandscapeMock(t *testing.T, ctx context.Context, addr string) (lis net
lis, err := cfg.Listen(ctx, "tcp", addr)
require.NoError(t, err, "Setup: can't listen")

server = grpc.NewServer()
serverCert, err := tls.LoadX509KeyPair("testdata/cert.pem", "testdata/key.pem")
require.NoError(t, err, "Setup: could not load Landscape mock server credentials")

config := &tls.Config{
Certificates: []tls.Certificate{serverCert},
ClientAuth: tls.NoClientCert,
MinVersion: tls.VersionTLS12,
}

server = grpc.NewServer(grpc.Creds(credentials.NewTLS(config)))
service = landscapemockservice.New()
landscapeapi.RegisterLandscapeHostAgentServer(server, service)

out, err := os.ReadFile("testdata/landscape.conf")
require.NoError(t, err, "could not read landscape configuration file")

writeUbuntuProRegistry(t, "LandscapeClientConfig", string(out))
writeUbuntuProRegistry(t, "LandscapeAgentURL", lis.Addr().String())

return lis, server, service
}

Expand All @@ -208,6 +227,6 @@ func writeUbuntuProRegistry(t *testing.T, field string, value string) {
require.NoErrorf(t, err, "Setup: could not open UbuntuPro registry key")
defer key.Close()

err = key.SetStringValue(field, value)
err = key.SetStringsValue(field, strings.Split(value, "\n"))
require.NoError(t, err, "could not write token in registry")
}

0 comments on commit fa3606c

Please sign in to comment.