Skip to content
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

SSH tests #2003

Merged
merged 1 commit into from
Oct 23, 2023
Merged
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ require (
github.com/google/go-containerregistry v0.15.2
github.com/google/go-github/v49 v49.1.0
github.com/google/uuid v1.3.1
github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95
github.com/heroku/color v0.0.6
github.com/hinshun/vt10x v0.0.0-20220228203356-1ab2cad5fd82
github.com/manifestival/client-go-client v0.5.0
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -569,6 +569,8 @@ github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iP
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95 h1:S4qyfL2sEm5Budr4KVMyEniCy+PbS55651I/a+Kn/NQ=
github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95/go.mod h1:QiyDdbZLaJ/mZP4Zwc9g2QsfaEA4o7XvvgZegSci5/E=
github.com/heroku/color v0.0.6 h1:UTFFMrmMLFcL3OweqP1lAdp8i1y/9oHqkeHjQ/b/Ny0=
github.com/heroku/color v0.0.6/go.mod h1:ZBvOcx7cTF2QKOv4LbmoBtNl5uB17qWxGuzZrsi1wLU=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
@@ -1155,6 +1157,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190529164535-6a60838ec259/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
597 changes: 597 additions & 0 deletions pkg/ssh/server_test.go

Large diffs are not rendered by default.

1,026 changes: 1,026 additions & 0 deletions pkg/ssh/ssh_dialer_test.go

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions pkg/ssh/ssh_posix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build !windows
// +build !windows

package ssh_test

import (
"errors"
"net"
"os"
)

func fixupPrivateKeyMod(path string) {
err := os.Chmod(path, 0600)
if err != nil {
panic(err)
}
}

func listen(addr string) (net.Listener, error) {
return net.Listen("unix", addr)
}

func isErrClosed(err error) bool {
return errors.Is(err, net.ErrClosed)
}
39 changes: 39 additions & 0 deletions pkg/ssh/ssh_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ssh_test

import (
"errors"
"net"
"os/user"
"strings"

"github.com/Microsoft/go-winio"
"github.com/hectane/go-acl"
)

func fixupPrivateKeyMod(path string) {
usr, err := user.Current()
if err != nil {
panic(err)
}
mode := uint32(0600)
err = acl.Apply(path,
true,
false,
acl.GrantName(((mode&0700)<<23)|((mode&0200)<<9), usr.Username))

// See https://github.com/hectane/go-acl/issues/1
if err != nil && err.Error() != "The operation completed successfully." {
panic(err)
}
}

func listen(addr string) (net.Listener, error) {
if strings.Contains(addr, "\\pipe\\") {
return winio.ListenPipe(addr, nil)
}
return net.Listen("unix", addr)
}

func isErrClosed(err error) bool {
return errors.Is(err, net.ErrClosed) || errors.Is(err, winio.ErrPipeListenerClosed) || errors.Is(err, winio.ErrFileClosed)
}