Skip to content

Commit

Permalink
UserCredentials
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison committed Nov 22, 2018
1 parent 321c91a commit 9527d54
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,9 @@ func TokenHandler(cb AuthTokenHandler) Option {
}
}

// UserAndNkey is a convenience function that takes a filename
// UserCredentials is a convenience function that takes a filename
// for a user's JWT and a filename for the user's private Nkey seed.
func UserAndNkeyFiles(userJWTFile, seedFile string) Option {
func UserCredentials(userJWTFile, seedFile string) Option {
userCB := func() (string, error) {
return userFromFile(userJWTFile)
}
Expand Down
20 changes: 20 additions & 0 deletions nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,26 @@ func TestBasicUserJWTAuth(t *testing.T) {
nc.Close()
}

func TestUserCredentials(t *testing.T) {
if server.VERSION[0] == '1' {
t.Skip()
}
ts := runTrustServer()
defer ts.Shutdown()

userJWTFile := createTmpFile(t, []byte(uJWT))
defer os.Remove(userJWTFile)
userSeedFile := createTmpFile(t, uSeed)
defer os.Remove(userSeedFile)

url := fmt.Sprintf("nats://127.0.0.1:%d", TEST_PORT)
nc, err := Connect(url, UserCredentials(userJWTFile, userSeedFile))
if err != nil {
t.Fatalf("Expected to connect, got %v", err)
}
nc.Close()
}

func TestNkeyAuth(t *testing.T) {
if server.VERSION[0] == '1' {
t.Skip()
Expand Down

0 comments on commit 9527d54

Please sign in to comment.