...

Source file src/go.etcd.io/etcd/server/v3/embed/auth_test.go

Documentation: go.etcd.io/etcd/server/v3/embed

     1  // Copyright 2020 The etcd Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package embed
    16  
    17  import (
    18  	"context"
    19  	"io/ioutil"
    20  	"os"
    21  	"testing"
    22  
    23  	"go.etcd.io/etcd/server/v3/etcdserver/api/v3client"
    24  )
    25  
    26  func TestEnableAuth(t *testing.T) {
    27  	tdir, err := ioutil.TempDir(os.TempDir(), "auth-test")
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  	defer os.RemoveAll(tdir)
    32  	cfg := NewConfig()
    33  	cfg.Dir = tdir
    34  	e, err := StartEtcd(cfg)
    35  	if err != nil {
    36  		t.Fatal(err)
    37  	}
    38  	defer e.Close()
    39  	client := v3client.New(e.Server)
    40  	defer client.Close()
    41  
    42  	_, err = client.RoleAdd(context.TODO(), "root")
    43  	if err != nil {
    44  		t.Fatal(err)
    45  	}
    46  	_, err = client.UserAdd(context.TODO(), "root", "root")
    47  	if err != nil {
    48  		t.Fatal(err)
    49  	}
    50  	_, err = client.UserGrantRole(context.TODO(), "root", "root")
    51  	if err != nil {
    52  		t.Fatal(err)
    53  	}
    54  	_, err = client.AuthEnable(context.TODO())
    55  	if err != nil {
    56  		t.Fatal(err)
    57  	}
    58  }
    59  

View as plain text