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

[IMPROVED] Connect error when given an invalid user creds file #916

Merged
merged 1 commit into from Feb 23, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions nats.go
Expand Up @@ -2138,7 +2138,7 @@ func (nc *Conn) connectProto() (string, error) {
}
sigraw, err := o.SignatureCB([]byte(nc.info.Nonce))
if err != nil {
return _EMPTY_, err
return _EMPTY_, fmt.Errorf("error signing nonce: %v", err)
}
sig = base64.RawURLEncoding.EncodeToString(sigraw)
}
Expand Down Expand Up @@ -5237,7 +5237,7 @@ func nkeyPairFromSeedFile(seedFile string) (nkeys.KeyPair, error) {
func sigHandler(nonce []byte, seedFile string) ([]byte, error) {
kp, err := nkeyPairFromSeedFile(seedFile)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to extract key pair from file %q: %v", seedFile, err)
}
// Wipe our key on exit.
defer kp.Wipe()
Expand Down
11 changes: 11 additions & 0 deletions nats_test.go
Expand Up @@ -1483,6 +1483,17 @@ func TestUserCredentialsChainedFile(t *testing.T) {
t.Fatalf("Expected to connect, got %v", err)
}
nc.Close()

chainedFile = createTmpFile(t, []byte("invalid content"))
defer os.Remove(chainedFile)
nc, err = Connect(url, UserCredentials(chainedFile))
if err == nil || !strings.Contains(err.Error(),
"error signing nonce: unable to extract key pair from file") {
if nc != nil {
nc.Close()
}
t.Fatalf("Expected error about invalid creds file, got %q", err)
}
}

func TestExpiredAuthentication(t *testing.T) {
Expand Down