Skip to content

Commit

Permalink
Merge pull request #337 from juju/v3
Browse files Browse the repository at this point in the history
Merge ssh check from v3 into master
  • Loading branch information
Aflynn50 committed Mar 11, 2024
2 parents 72bc90d + 130bac1 commit 5f18edb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# GoLand
.idea/

# Dependency directories (remove the comment below to include it)
# vendor/

3 changes: 3 additions & 0 deletions ssh/authorisedkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func authKeysDir(username string) (string, error) {
// authorized_keys file and returns the constituent parts.
// Based on description in "man sshd".
func ParseAuthorisedKey(line string) (*AuthorisedKey, error) {
if strings.Contains(line, "\n") {
return nil, errors.NotValidf("newline in authorized_key %q", line)
}
key, comment, _, _, err := ssh.ParseAuthorizedKey([]byte(line))
if err != nil {
return nil, errors.Errorf("invalid authorized_key %q", line)
Expand Down
3 changes: 3 additions & 0 deletions ssh/authorisedkeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ func (s *AuthorisedKeysKeysSuite) TestParseAuthorisedKey(c *gc.C) {
}, {
line: "ssh-rsa",
err: "invalid authorized_key \"ssh-rsa\"",
}, {
line: sshtesting.ValidKeyOne.Key + " line1\nline2",
err: "newline in authorized_key \".*",
}} {
c.Logf("test %d: %s", i, test.line)
ak, err := ssh.ParseAuthorisedKey(test.line)
Expand Down
6 changes: 6 additions & 0 deletions ssh/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ func PatchTerminal(s *testing.CleanupSuite, rlw ReadLineWriter) {
c.Assert(atomic.LoadInt64(&balance), gc.Equals, int64(0))
})
}

func PatchNilTerminal(s *testing.CleanupSuite) {
s.PatchValue(&getTerminal, func() (readLineWriter, func(), error) {
return nil, func() {}, nil
})
}
5 changes: 1 addition & 4 deletions ssh/ssh_gocrypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,9 @@ func (s *SSHGoCryptoCommandSuite) SetUpTest(c *gc.C) {
generateKeyRestorer := overrideGenerateKey()
s.AddCleanup(func(*gc.C) { generateKeyRestorer.Restore() })

client, err := ssh.NewGoCryptoClient()
c.Assert(err, jc.ErrorIsNil)
s.client = client

s.knownHostsFile = filepath.Join(c.MkDir(), "known_hosts")
ssh.SetGoCryptoKnownHostsFile(s.knownHostsFile)
ssh.PatchNilTerminal(&s.CleanupSuite)
}

func (s *SSHGoCryptoCommandSuite) newServer(c *gc.C, serverConfig cryptossh.ServerConfig) (*sshServer, cryptossh.PublicKey) {
Expand Down

0 comments on commit 5f18edb

Please sign in to comment.