Repository navigation
fix: execute SSH bootstrap through a shell-safe POSIX launcher #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c0c159a
fix: execute SSH bootstrap through a shell-safe POSIX launcher
skevetter 4722dd2
test: verify remote command failures without shell-specific wording
skevetter e662d53
fix: join SSH stdin copies and preserve source failures
skevetter cf24b4c
ci: serialize provider snapshot builds to bound disk usage
skevetter e9c4c75
fix: leave caller stdin untouched during SSH initialization
skevetter b718c87
fix: preserve SSH cancellation identity and CLI classification
skevetter 6437814
fix: preserve cancellation through all built-in SSH phases
skevetter df18ed4
fix: remove cancelreader use and verification document
skevetter c9f0c66
test: accept EOF from canceled Windows console reads
skevetter a14daf3
ci: avoid persisting checkout credentials during tests
skevetter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| //go:build !windows | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "bytes" | ||
| "context" | ||
| "errors" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strings" | ||
| "syscall" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| func TestExecuteProcess(t *testing.T) { | ||
| if os.Getenv("DEVSY_TEST_EXECUTE") != "1" { | ||
| return | ||
| } | ||
| os.Args = []string{"devsy-provider-ssh", "command"} | ||
| Execute() | ||
| } | ||
|
|
||
| func executeTestProcess(t *testing.T, script string) *exec.Cmd { | ||
| t.Helper() | ||
| dir := t.TempDir() | ||
| // #nosec G306 -- Controlled executable models the SSH child at the CLI boundary. | ||
| if err := os.WriteFile( | ||
| filepath.Join(dir, "ssh"), | ||
| []byte("#!/bin/sh\n"+script), | ||
| 0o700, | ||
| ); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| for key, value := range map[string]string{ | ||
| "DEVSY_TEST_EXECUTE": "1", "DOCKER_PATH": "docker", "AGENT_PATH": "/tmp/agent", | ||
| "HOST": "fixture", "PORT": "22", "USE_BUILTIN_SSH": "false", "COMMAND": "fixture", | ||
| "EXTRA_FLAGS": "", "PATH": dir + string(os.PathListSeparator) + os.Getenv("PATH"), | ||
| } { | ||
| t.Setenv(key, value) | ||
| } | ||
| executable, err := os.Executable() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| t.Cleanup(cancel) | ||
| // #nosec G204 -- Re-execute only this test binary with a controlled helper selector. | ||
| return exec.CommandContext(ctx, executable, "-test.run=^TestExecuteProcess$") | ||
| } | ||
|
|
||
| func TestExecuteCancellation(t *testing.T) { | ||
| cmd := executeTestProcess(t, "printf 'ready\\n'\nexec sleep 30\n") | ||
| var stderr bytes.Buffer | ||
| cmd.Stderr = &stderr | ||
| stdout, err := cmd.StdoutPipe() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err = cmd.Start(); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| ready, err := bufio.NewReader(stdout).ReadString('\n') | ||
| if err != nil || ready != "ready\n" { | ||
| t.Fatalf("SSH child did not start: %q, %v", ready, err) | ||
| } | ||
| if err = cmd.Process.Signal(syscall.SIGTERM); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| assertProcessExit(t, cmd.Wait(), 1) | ||
| if !strings.Contains(stderr.String(), "context canceled") { | ||
| t.Fatalf("missing cancellation diagnostic: %q", stderr.String()) | ||
| } | ||
| } | ||
|
|
||
| func TestExecuteRemoteExit(t *testing.T) { | ||
| cmd := executeTestProcess(t, "printf 'remote diagnostic' >&2\nexit 37\n") | ||
| var stderr bytes.Buffer | ||
| cmd.Stderr = &stderr | ||
| assertProcessExit(t, cmd.Run(), 37) | ||
| if stderr.String() != "remote diagnostic" { | ||
| t.Fatalf("remote diagnostic changed: %q", stderr.String()) | ||
| } | ||
| } | ||
|
|
||
| func assertProcessExit(t *testing.T, err error, code int) { | ||
| t.Helper() | ||
| var exit *exec.ExitError | ||
| if !errors.As(err, &exit) || exit.ExitCode() != code { | ||
| t.Fatalf("expected exit %d, got %v", code, err) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.