Skip to content

Commit

Permalink
Merge pull request #916 from nats-io/improve_invalid_certs_error
Browse files Browse the repository at this point in the history
[IMPROVED] Connect error when given an invalid user creds file
  • Loading branch information
kozlovic committed Feb 23, 2022
2 parents 0096b1b + abfa624 commit 268c37b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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

0 comments on commit 268c37b

Please sign in to comment.