From fe92b773067fa4ab02ae8dc1e3e445f19a246d94 Mon Sep 17 00:00:00 2001 From: Hitoshi Mitake Date: Thu, 10 Jan 2019 00:37:49 +0900 Subject: [PATCH] auth: add a unit test for creating a user with no password --- auth/store_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/auth/store_test.go b/auth/store_test.go index 74146da3aa96..9c975413dba0 100644 --- a/auth/store_test.go +++ b/auth/store_test.go @@ -848,3 +848,21 @@ func testAuthInfoFromCtxWithRoot(t *testing.T, opts string) { t.Errorf("expected user name 'root', got %+v", ai) } } + +func TestUserNoPasswordAdd(t *testing.T) { + as, tearDown := setupAuthStore(t) + defer tearDown(t) + + username := "usernopass" + ua := &pb.AuthUserAddRequest{Name: username, Options: &authpb.UserAddOptions{NoPassword: true}} + _, err := as.UserAdd(ua) + if err != nil { + t.Fatal(err) + } + + ctx := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, token) + _, err = as.Authenticate(ctx, username, "") + if err != ErrAuthFailed { + t.Fatalf("expected %v, got %v", ErrAuthFailed, err) + } +}