clientv3/integration: return err if err == rpctypes.ErrAuthNotEnable

This commit is contained in:
cfc4n 2019-02-02 14:06:54 +08:00
parent 3e0f0ba40e
commit a033686acf
2 changed files with 46 additions and 0 deletions

View File

@ -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
}

View File

@ -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)
}
}