Skip to content

Commit

Permalink
e2e: add TestV3CurlAuthWithoutOption for issue #11414
Browse files Browse the repository at this point in the history
  • Loading branch information
YoyinZyc committed Dec 10, 2019
1 parent aea34c1 commit e4376b0
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/e2e/v3_curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func TestV3CurlAuth(t *testing.T) {
testCtl(t, testV3CurlAuth, withApiPrefix(p))
}
}
func TestV3CurlAuthWithoutOption(t *testing.T) {
for _, p := range apiPrefix {
testCtl(t, testV3CurlAuthWithoutOption, withApiPrefix(p))
}
}
func TestV3CurlAuthClientTLSCertAuth(t *testing.T) {
for _, p := range apiPrefix {
testCtl(t, testV3CurlAuth, withApiPrefix(p), withCfg(configClientTLSCertAuthWithNoCN))
Expand Down Expand Up @@ -274,6 +279,63 @@ func testV3CurlAuth(cx ctlCtx) {
}
}

func testV3CurlAuthWithoutOption(cx ctlCtx) {
p := cx.apiPrefix

// create root user
if err := cURLPost(cx.epc, cURLReq{endpoint: path.Join(p, "/auth/user/add"), value: "{\"name\":\"root\", \"password\":\"toor\"}", expected: "revision"}); err != nil {
cx.t.Fatalf("failed testV3CurlAuth add user with curl (%v)", err)
}

// create root role
if err := cURLPost(cx.epc, cURLReq{endpoint: path.Join(p, "/auth/role/add"), value: "{\"name\":\"root\"}", expected: "revision"}); err != nil {
cx.t.Fatalf("failed testV3CurlAuth create role with curl using prefix (%s) (%v)", p, err)
}

// grant root role
if err := cURLPost(cx.epc, cURLReq{endpoint: path.Join(p, "/auth/user/grant"), value: "{\"user\":\"root\", \"role\":\"root\"}", expected: "revision"}); err != nil {
cx.t.Fatalf("failed testV3CurlAuth grant role with curl using prefix (%s) (%v)", p, err)
}

// enable auth
if err := cURLPost(cx.epc, cURLReq{endpoint: path.Join(p, "/auth/enable"), value: string("{}"), expected: "revision"}); err != nil {
cx.t.Fatalf("failed testV3CurlAuth enable auth with curl using prefix (%s) (%v)", p, err)
}

// auth request
var (
authHeader string
cmdArgs []string
lineFunc = func(txt string) bool { return true }
)

cmdArgs = cURLPrefixArgs(cx.epc, "POST", cURLReq{endpoint: path.Join(p, "/auth/authenticate"), value: "{\"name\":\"root\", \"password\":\"toor\"}"})
proc, err := spawnCmd(cmdArgs)
testutil.AssertNil(cx.t, err)

cURLRes, err := proc.ExpectFunc(lineFunc)
testutil.AssertNil(cx.t, err)

authRes := make(map[string]interface{})
testutil.AssertNil(cx.t, json.Unmarshal([]byte(cURLRes), &authRes))

token, ok := authRes[rpctypes.TokenFieldNameGRPC].(string)
if !ok {
cx.t.Fatalf("failed invalid token in authenticate response with curl")
}

authHeader = "Authorization: " + token

// put "bar" into "foo"
putreq, err := json.Marshal(&pb.PutRequest{Key: []byte("foo"), Value: []byte("bar")})
testutil.AssertNil(cx.t, err)

// put with auth
if err = cURLPost(cx.epc, cURLReq{endpoint: path.Join(p, "/kv/put"), value: string(putreq), header: authHeader, expected: "revision"}); err != nil {
cx.t.Fatalf("failed testV3CurlAuth auth put with curl using prefix (%s) (%v)", p, err)
}
}

func TestV3CurlCampaignNoTLS(t *testing.T) {
for _, p := range apiPrefix {
testCtl(t, testV3CurlCampaign, withApiPrefix(p), withCfg(configNoTLS))
Expand Down

0 comments on commit e4376b0

Please sign in to comment.