Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cmd/cli/aws_isolation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"os"
"testing"

"github.com/NVIDIA/holodeck/pkg/testutil"
)

// TestMain runs this package's tests in a child process that cannot reach
// real AWS credentials: some of these tests construct real AWS clients, and
// they must never reach a real account, whatever credentials the machine has.
func TestMain(m *testing.M) { os.Exit(testutil.RunAWSIsolated(m)) }

// TestAWSIsolation fails unless the AWS isolation from TestMain is in effect.
func TestAWSIsolation(t *testing.T) { testutil.RequireAWSIsolation(t) }
32 changes: 32 additions & 0 deletions cmd/cli/cleanup/aws_isolation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cleanup_test

import (
"os"
"testing"

"github.com/NVIDIA/holodeck/pkg/testutil"
)

// TestMain runs this package's tests in a child process that cannot reach
// real AWS credentials: some of these tests construct real AWS clients, and
// they must never reach a real account, whatever credentials the machine has.
func TestMain(m *testing.M) { os.Exit(testutil.RunAWSIsolated(m)) }

// TestAWSIsolation fails unless the AWS isolation from TestMain is in effect.
func TestAWSIsolation(t *testing.T) { testutil.RequireAWSIsolation(t) }
32 changes: 32 additions & 0 deletions cmd/cli/common/aws_isolation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package common

import (
"os"
"testing"

"github.com/NVIDIA/holodeck/pkg/testutil"
)

// TestMain runs this package's tests in a child process that cannot reach
// real AWS credentials: some of these tests construct real AWS clients, and
// they must never reach a real account, whatever credentials the machine has.
func TestMain(m *testing.M) { os.Exit(testutil.RunAWSIsolated(m)) }

// TestAWSIsolation fails unless the AWS isolation from TestMain is in effect.
func TestAWSIsolation(t *testing.T) { testutil.RequireAWSIsolation(t) }
32 changes: 32 additions & 0 deletions cmd/cli/create/aws_isolation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package create_test

import (
"os"
"testing"

"github.com/NVIDIA/holodeck/pkg/testutil"
)

// TestMain runs this package's tests in a child process that cannot reach
// real AWS credentials: some of these tests construct real AWS clients, and
// they must never reach a real account, whatever credentials the machine has.
func TestMain(m *testing.M) { os.Exit(testutil.RunAWSIsolated(m)) }

// TestAWSIsolation fails unless the AWS isolation from TestMain is in effect.
func TestAWSIsolation(t *testing.T) { testutil.RequireAWSIsolation(t) }
32 changes: 32 additions & 0 deletions cmd/cli/delete/aws_isolation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package delete_test

import (
"os"
"testing"

"github.com/NVIDIA/holodeck/pkg/testutil"
)

// TestMain runs this package's tests in a child process that cannot reach
// real AWS credentials: some of these tests construct real AWS clients, and
// they must never reach a real account, whatever credentials the machine has.
func TestMain(m *testing.M) { os.Exit(testutil.RunAWSIsolated(m)) }

// TestAWSIsolation fails unless the AWS isolation from TestMain is in effect.
func TestAWSIsolation(t *testing.T) { testutil.RequireAWSIsolation(t) }
32 changes: 32 additions & 0 deletions cmd/cli/describe/aws_isolation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package describe

import (
"os"
"testing"

"github.com/NVIDIA/holodeck/pkg/testutil"
)

// TestMain runs this package's tests in a child process that cannot reach
// real AWS credentials: some of these tests construct real AWS clients, and
// they must never reach a real account, whatever credentials the machine has.
func TestMain(m *testing.M) { os.Exit(testutil.RunAWSIsolated(m)) }

// TestAWSIsolation fails unless the AWS isolation from TestMain is in effect.
func TestAWSIsolation(t *testing.T) { testutil.RequireAWSIsolation(t) }
32 changes: 32 additions & 0 deletions cmd/cli/dryrun/aws_isolation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dryrun_test

import (
"os"
"testing"

"github.com/NVIDIA/holodeck/pkg/testutil"
)

// TestMain runs this package's tests in a child process that cannot reach
// real AWS credentials: some of these tests construct real AWS clients, and
// they must never reach a real account, whatever credentials the machine has.
func TestMain(m *testing.M) { os.Exit(testutil.RunAWSIsolated(m)) }

// TestAWSIsolation fails unless the AWS isolation from TestMain is in effect.
func TestAWSIsolation(t *testing.T) { testutil.RequireAWSIsolation(t) }
32 changes: 32 additions & 0 deletions cmd/cli/list/aws_isolation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package list_test

import (
"os"
"testing"

"github.com/NVIDIA/holodeck/pkg/testutil"
)

// TestMain runs this package's tests in a child process that cannot reach
// real AWS credentials: some of these tests construct real AWS clients, and
// they must never reach a real account, whatever credentials the machine has.
func TestMain(m *testing.M) { os.Exit(testutil.RunAWSIsolated(m)) }

// TestAWSIsolation fails unless the AWS isolation from TestMain is in effect.
func TestAWSIsolation(t *testing.T) { testutil.RequireAWSIsolation(t) }
3 changes: 2 additions & 1 deletion cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/NVIDIA/holodeck/cmd/cli/ssh"
"github.com/NVIDIA/holodeck/cmd/cli/status"
"github.com/NVIDIA/holodeck/cmd/cli/update"
internalaws "github.com/NVIDIA/holodeck/internal/aws"
"github.com/NVIDIA/holodeck/internal/logger"

cli "github.com/urfave/cli/v3"
Expand Down Expand Up @@ -220,7 +221,7 @@ For more information about a command, run:

err := c.Run(context.Background(), os.Args)
if err != nil {
log.Error(err)
log.Error(internalaws.SSOHint(err))
log.Exit(1)
}
}
80 changes: 80 additions & 0 deletions cmd/cli/os/ami_wiring_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package os_test

import (
"bytes"
"context"
"crypto/sha1" //nolint:gosec // the SDK names SSO token cache files by SHA-1
"encoding/hex"
"errors"
"os"
"path/filepath"
"testing"

"github.com/aws/aws-sdk-go-v2/credentials/ssocreds"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
cli "github.com/urfave/cli/v3"

oscmd "github.com/NVIDIA/holodeck/cmd/cli/os"
"github.com/NVIDIA/holodeck/internal/logger"
"github.com/NVIDIA/holodeck/pkg/testutil"
)

const amiStartURL = "https://holodeck-sso-test.awsapps.com/start"

// TestAMIUsesLoadConfig guards the "holodeck os ami" wiring. The fixture is
// Carlos's layout: an SSO profile in the config file, stale static keys for
// it in the default credentials file, and an expired cached SSO token.
// Through internalaws.LoadConfig the command prefers SSO and fails on the
// expired token with the typed SSO error. Raw config.LoadDefaultConfig
// would take the static keys and fail on the closed local endpoint instead.
// No request reaches AWS either way (package TestMain).
func TestAMIUsesLoadConfig(t *testing.T) {
home := testutil.IsolatedHome(t)
t.Setenv("HOME", home)
for _, k := range []string{"AWS_CONFIG_FILE", "AWS_SHARED_CREDENTIALS_FILE"} {
t.Setenv(k, "")
require.NoError(t, os.Unsetenv(k))
}
cacheDir := filepath.Join(home, ".aws", "sso", "cache")
require.NoError(t, os.MkdirAll(cacheDir, 0o700))
require.NoError(t, os.WriteFile(filepath.Join(home, ".aws", "config"), []byte(`[default]
sso_start_url = `+amiStartURL+`
sso_region = us-east-1
sso_account_id = 123456789012
sso_role_name = HolodeckTest
`), 0o600))
require.NoError(t, os.WriteFile(filepath.Join(home, ".aws", "credentials"), []byte(
"[default]\naws_access_key_id = AKIAHOLODECKFAKE0001\naws_secret_access_key = holodeck-fake-secret\n"), 0o600))
sum := sha1.Sum([]byte(amiStartURL)) //nolint:gosec // matches the SDK naming scheme
require.NoError(t, os.WriteFile(filepath.Join(cacheDir, hex.EncodeToString(sum[:])+".json"), []byte(
`{"accessToken":"fake-access-token","expiresAt":"2020-01-01T00:00:00Z","region":"us-east-1","startUrl":"`+
amiStartURL+`"}`), 0o600))

log := logger.NewLogger()
var stderr bytes.Buffer
log.Out = &stderr
app := &cli.Command{Commands: []*cli.Command{oscmd.NewCommand(log)}}
err := app.Run(context.Background(), []string{"holodeck", "os", "ami", "ubuntu-22.04", "--region", "us-west-2"})

require.Error(t, err)
var tokenErr *ssocreds.InvalidTokenError
assert.True(t, errors.As(err, &tokenErr),
"os ami must load through internalaws.LoadConfig, which prefers the SSO login; err=%v", err)
}
32 changes: 32 additions & 0 deletions cmd/cli/os/aws_isolation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package os_test

import (
"os"
"testing"

"github.com/NVIDIA/holodeck/pkg/testutil"
)

// TestMain runs this package's tests in a child process that cannot reach
// real AWS credentials: some of these tests construct real AWS clients, and
// they must never reach a real account, whatever credentials the machine has.
func TestMain(m *testing.M) { os.Exit(testutil.RunAWSIsolated(m)) }

// TestAWSIsolation fails unless the AWS isolation from TestMain is in effect.
func TestAWSIsolation(t *testing.T) { testutil.RequireAWSIsolation(t) }
Loading