Skip to content
Merged
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
7 changes: 7 additions & 0 deletions apps/cinc/cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ cinc node bootstrap web01.example.com --ssh-user ubuntu --policy-name base --pol
if err != nil {
return err
}
// The bootstrap script hard-codes the server URL into the client.rb
// it writes, so the profile must actually name a server. A real run
// gets this from resolveClient below, but a dry run never calls it
// and would otherwise print a script pointing at "/organizations/".
if err := profile.Validate(); err != nil {
return err
}
var privateKey string
if !flags.dryRun {
c, err := resolveClient(cmd)
Expand Down
32 changes: 32 additions & 0 deletions apps/cinc/cmd/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,38 @@ func TestNodeBootstrapRejectsEnvironmentWithPolicy(t *testing.T) {
}
}

// TestNodeBootstrapDryRunRejectsProfileWithoutServer covers a profile that is
// perfectly valid on disk but names no Cinc Server, such as a Supermarket-only
// one. A real bootstrap catches this in resolveClient; a dry run never calls
// it, and used to emit a script whose client.rb pointed at "/organizations/".
func TestNodeBootstrapDryRunRejectsProfileWithoutServer(t *testing.T) {
cfgPath := filepath.Join(t.TempDir(), "credentials")
cfg := fmt.Sprintf(`[default]
supermarket_site = "https://supermarket.cinc.sh"
client_name = "tim"
client_key = %q
`, writeTestKey(t))
if err := os.WriteFile(cfgPath, []byte(cfg), 0o600); err != nil {
t.Fatal(err)
}

root := newRootCmd()
var out bytes.Buffer
root.SetOut(&out)
root.SetErr(new(bytes.Buffer))
root.SetArgs([]string{
"node", "bootstrap", "web01.example.test",
"--ssh-user", "ubuntu", "--config", cfgPath, "--dry-run",
})

if err := root.Execute(); err == nil {
t.Fatalf("dry run accepted a profile with no server URL and printed:\n%s", out.String())
}
if strings.Contains(out.String(), "chef_server_url") {
t.Errorf("dry run emitted a bootstrap script anyway:\n%s", out.String())
}
}

func TestNodeBootstrapDryRunCommand(t *testing.T) {
cfgPath := writeCommandConfig(t, "https://cinc.example.test")
root := newRootCmd()
Expand Down