Skip to content

Commit

Permalink
Updates tests
Browse files Browse the repository at this point in the history
Adding the cert requirement where it makes sense
And using insecure channel by default on most other cases
(via testReceiveCommands) mostly.
  • Loading branch information
CarlosNihelton committed Dec 2, 2024
1 parent 0c788ce commit 4df31dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions windows-agent/internal/proservices/landscape/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ func testReceiveCommand(t *testing.T, distrosettings distroSettings, homedir str
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

ctx = context.WithValue(ctx, landscape.InsecureCredentials, true)

tb.wslMock = wslmock.New()
ctx = wsl.WithMock(ctx, tb.wslMock)

Expand Down
22 changes: 13 additions & 9 deletions windows-agent/internal/proservices/landscape/landscape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,25 @@ func TestConnect(t *testing.T) {
"Error when the first-contact SendUpdatedInfo fails": {tokenErr: true, wantErr: true},
"Error when the config cannot be accessed": {breakLandscapeClientConfig: true, wantErr: true},
"Error when the config cannot be parsed": {wantErr: true},
"Error when the SSL certificate cannot be read": {wantErr: true},
"Error when the SSL certificate is not valid": {wantErr: true},
"Error when the SSL certificate cannot be read": {requireCertificate: true, wantErr: true},
"Error when the SSL certificate is not valid": {requireCertificate: true, wantErr: true},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if wsl.MockAvailable() {
t.Parallel()
ctx = wsl.WithMock(ctx, wslmock.New())
}

p := ""
if tc.requireCertificate {
p = certPath
} else {
ctx = context.WithValue(ctx, landscape.InsecureCredentials, true)
}

if wsl.MockAvailable() {
t.Parallel()
ctx = wsl.WithMock(ctx, wslmock.New())
}

lis, server, mockService := setUpLandscapeMock(t, ctx, "localhost:", p)
Expand Down Expand Up @@ -305,7 +307,7 @@ func TestSendUpdatedInfo(t *testing.T) {

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
ctx := context.Background()
ctx := context.WithValue(context.Background(), landscape.InsecureCredentials, true)
if wsl.MockAvailable() {
t.Parallel()
mock := wslmock.New()
Expand Down Expand Up @@ -519,7 +521,7 @@ func TestAutoReconnection(t *testing.T) {

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.WithValue(context.Background(), landscape.InsecureCredentials, true))
defer cancel()

if wsl.MockAvailable() {
Expand Down Expand Up @@ -760,6 +762,8 @@ func TestReconnect(t *testing.T) {
certPath = t.TempDir()
testutils.GenerateTempCertificate(t, certPath)
lcapeConfig = fmt.Sprintf("%s\nssl_public_key = {{ .CertPath }}/cert.pem", defaultLandscapeConfig)
} else {
ctx = context.WithValue(ctx, landscape.InsecureCredentials, true)
}

lis, server, mockServerService := setUpLandscapeMock(t, ctx, "localhost:", certPath)
Expand Down

0 comments on commit 4df31dc

Please sign in to comment.