Skip to content

Commit

Permalink
clientv3/integration: return err if err == rpctypes.ErrAuthNotEnable
Browse files Browse the repository at this point in the history
  • Loading branch information
cfc4n committed Feb 2, 2019
1 parent 3e0f0ba commit a033686
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clientv3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ func (c *Client) getToken(ctx context.Context) error {
var resp *AuthenticateResponse
resp, err = auth.authenticate(ctx, c.Username, c.Password)
if err != nil {
// return err without retrying other endpoints
if err == rpctypes.ErrAuthNotEnabled {
return err
}
continue
}

Expand Down
42 changes: 42 additions & 0 deletions clientv3/integration/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,45 @@ func authSetupRoot(t *testing.T, auth clientv3.Auth) {
t.Fatal(err)
}
}

func TestGetTokenWithoutAuth(t *testing.T) {
defer testutil.AfterTest(t)

clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 10})
defer clus.Terminate(t)

authapi := clus.RandClient()

var err error
var client *clientv3.Client

// make sure "auth" was disabled
if _, err = authapi.AuthDisable(context.TODO()); err != nil {
t.Fatal(err)
}

// "Username" and "Password" must be used
cfg := clientv3.Config{
Endpoints: authapi.Endpoints(),
DialTimeout: 1 * time.Second, // make sure all connection time of connect all endpoint must be more DialTimeout
Username: "root",
Password: "123",
}

client, err = clientv3.New(cfg)
if err == nil {
defer client.Close()
}

switch err {
case nil:
t.Log("passes as expected, but may be connection time less than DialTimeout")
case context.DeadlineExceeded:
t.Errorf("not expected result:%v with endpoint:%s", err, authapi.Endpoints())
case rpctypes.ErrAuthNotEnabled:
t.Logf("passes as expected:%v", err)
default:
t.Errorf("other errors:%v", err)
}

}

0 comments on commit a033686

Please sign in to comment.