mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
client: correctly unmarshal users in ListUsers
This commit is contained in:
parent
a31f84121b
commit
2a0d64bb4a
@ -41,6 +41,10 @@ type UserRoles struct {
|
|||||||
Roles []Role `json:"roles"`
|
Roles []Role `json:"roles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type userName struct {
|
||||||
|
User string `json:"user"`
|
||||||
|
}
|
||||||
|
|
||||||
func v2AuthURL(ep url.URL, action string, name string) *url.URL {
|
func v2AuthURL(ep url.URL, action string, name string) *url.URL {
|
||||||
if name != "" {
|
if name != "" {
|
||||||
ep.Path = path.Join(ep.Path, defaultV2AuthPrefix, action, name)
|
ep.Path = path.Join(ep.Path, defaultV2AuthPrefix, action, name)
|
||||||
@ -192,13 +196,20 @@ func (u *httpAuthUserAPI) ListUsers(ctx context.Context) ([]string, error) {
|
|||||||
}
|
}
|
||||||
return nil, sec
|
return nil, sec
|
||||||
}
|
}
|
||||||
|
|
||||||
var userList struct {
|
var userList struct {
|
||||||
Users []string `json:"users"`
|
Users []User `json:"users"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = json.Unmarshal(body, &userList); err != nil {
|
if err = json.Unmarshal(body, &userList); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return userList.Users, nil
|
|
||||||
|
ret := make([]string, 0, len(userList.Users))
|
||||||
|
for _, u := range userList.Users {
|
||||||
|
ret = append(ret, u.User)
|
||||||
|
}
|
||||||
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *httpAuthUserAPI) AddUser(ctx context.Context, username string, password string) error {
|
func (u *httpAuthUserAPI) AddUser(ctx context.Context, username string, password string) error {
|
||||||
|
@ -214,6 +214,29 @@ func testCtlV2GetRoleUser(t *testing.T, cfg *etcdProcessClusterConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCtlV2UserList(t *testing.T) {
|
||||||
|
defer testutil.AfterTest(t)
|
||||||
|
|
||||||
|
mustEtcdctl(t)
|
||||||
|
|
||||||
|
epc, cerr := newEtcdProcessCluster(&defaultConfigWithProxy)
|
||||||
|
if cerr != nil {
|
||||||
|
t.Fatalf("could not start etcd process cluster (%v)", cerr)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if err := epc.Close(); err != nil {
|
||||||
|
t.Fatalf("error closing etcd processes (%v)", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err := etcdctlUserAdd(epc, "username", "password"); err != nil {
|
||||||
|
t.Fatalf("failed to add user (%v)", err)
|
||||||
|
}
|
||||||
|
if err := etcdctlUserList(epc, "username"); err != nil {
|
||||||
|
t.Fatalf("failed to list users (%v)", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func etcdctlPrefixArgs(clus *etcdProcessCluster, noSync bool) []string {
|
func etcdctlPrefixArgs(clus *etcdProcessCluster, noSync bool) []string {
|
||||||
endpoints := ""
|
endpoints := ""
|
||||||
if proxies := clus.proxies(); len(proxies) != 0 {
|
if proxies := clus.proxies(); len(proxies) != 0 {
|
||||||
@ -295,6 +318,11 @@ func etcdctlUserGet(clus *etcdProcessCluster, user string) error {
|
|||||||
return spawnWithExpectedString(cmdArgs, "User: "+user)
|
return spawnWithExpectedString(cmdArgs, "User: "+user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func etcdctlUserList(clus *etcdProcessCluster, expectedUser string) error {
|
||||||
|
cmdArgs := append(etcdctlPrefixArgs(clus, false), "user", "list")
|
||||||
|
return spawnWithExpectedString(cmdArgs, expectedUser)
|
||||||
|
}
|
||||||
|
|
||||||
func mustEtcdctl(t *testing.T) {
|
func mustEtcdctl(t *testing.T) {
|
||||||
if !fileutil.Exist("../bin/etcdctl") {
|
if !fileutil.Exist("../bin/etcdctl") {
|
||||||
t.Fatalf("could not find etcdctl binary")
|
t.Fatalf("could not find etcdctl binary")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user