Skip to content

Commit

Permalink
Address code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
djjuhasz committed Jan 11, 2024
1 parent d9ca335 commit 7324d03
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
8 changes: 4 additions & 4 deletions internal/am/upload_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ func TestUploadTransferActivity(t *testing.T) {
).Return(
0,
"",
sftp.NewAuthError(
errors.New("ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain"),
),
&sftp.AuthError{
Message: "ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain",
},
)
},
wantErr: "activity error (type: UploadTransferActivity, scheduledEventID: 0, startedEventID: 0, identity: ): UploadTransferActivity: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain",
wantErr: "activity error (type: UploadTransferActivity, scheduledEventID: 0, startedEventID: 0, identity: ): UploadTransferActivity: auth: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain",
wantNonRetryErr: true,
},
} {
Expand Down
13 changes: 5 additions & 8 deletions internal/sftp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ package sftp

import (
"context"
"fmt"
"io"
)

type AuthError struct {
err error
Message string
}

func (e *AuthError) Error() string {
return e.err.Error()
return fmt.Sprintf("auth: %s", e.Message)
}

func (e *AuthError) Unwrap() error {
return e.err
}

func NewAuthError(e error) *AuthError {
return &AuthError{err: e}
func NewAuthError(e error) error {
return &AuthError{Message: e.Error()}
}

// A Client manages the transmission of data over SFTP.
Expand Down
25 changes: 12 additions & 13 deletions internal/sftp/goclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -233,9 +232,9 @@ func TestUpload(t *testing.T) {
src: strings.NewReader("Testing 1-2-3"),
dest: "test.txt",
},
wantErr: sftp.NewAuthError(
errors.New("ssh: parse private key with passphrase: x509: decryption password incorrect"),
),
wantErr: &sftp.AuthError{
Message: "ssh: parse private key with passphrase: x509: decryption password incorrect",
},
},
{
name: "Errors when the SFTP server isn't there",
Expand Down Expand Up @@ -266,9 +265,9 @@ func TestUpload(t *testing.T) {
Path: "./testdata/clientkeys/test_unk_ed25519",
},
},
wantErr: sftp.NewAuthError(
errors.New("ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain"),
),
wantErr: &sftp.AuthError{
Message: "ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain",
},
},
{
name: "Errors when the host key is not in known_hosts",
Expand All @@ -280,9 +279,9 @@ func TestUpload(t *testing.T) {
Path: "./testdata/clientkeys/test_ed25519",
},
},
wantErr: sftp.NewAuthError(
errors.New("ssh: handshake failed: knownhosts: key is unknown"),
),
wantErr: &sftp.AuthError{
Message: "ssh: handshake failed: knownhosts: key is unknown",
},
},
{
name: "Errors when the known_hosts file doesn't exist",
Expand All @@ -294,9 +293,9 @@ func TestUpload(t *testing.T) {
Path: "./testdata/clientkeys/test_ed25519",
},
},
wantErr: sftp.NewAuthError(
errors.New("ssh: parse known_hosts: open testdata/missing: no such file or directory"),
),
wantErr: &sftp.AuthError{
Message: "ssh: parse known_hosts: open testdata/missing: no such file or directory",
},
},
} {
tc := tc
Expand Down

0 comments on commit 7324d03

Please sign in to comment.