MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / MakeUser

Function MakeUser

rest/utilities_testing_user.go:25–54  ·  view source on GitHub ↗
(t *testing.T, httpClient *http.Client, serverURL, username, password string, roles []string)

Source from the content-addressed store, hash-verified

23)
24
25func MakeUser(t *testing.T, httpClient *http.Client, serverURL, username, password string, roles []string) {
26 form := url.Values{}
27 form.Add("password", password)
28 form.Add("roles", strings.Join(roles, ","))
29
30 retryWorker := func() (shouldRetry bool, err error, value interface{}) {
31 req, err := http.NewRequest("PUT", fmt.Sprintf("%s/settings/rbac/users/local/%s", serverURL, username), strings.NewReader(form.Encode()))
32 require.NoError(t, err)
33
34 req.SetBasicAuth(base.TestClusterUsername(), base.TestClusterPassword())
35 req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
36
37 resp, err := httpClient.Do(req)
38 if err != nil {
39 return true, err, nil
40 }
41 defer func() { assert.NoError(t, resp.Body.Close()) }()
42 var bodyResp []byte
43 if resp.StatusCode != http.StatusOK {
44 bodyResp, err = io.ReadAll(resp.Body)
45 require.NoError(t, err, "Failed to create user: %s", bodyResp)
46 }
47 require.Equalf(t, http.StatusOK, resp.StatusCode, "Failed to create user: %s", bodyResp)
48 return false, err, nil
49 }
50
51 err, _ := base.RetryLoop(base.TestCtx(t), "Admin Auth testing MakeUser", retryWorker, base.CreateSleeperFunc(10, 100))
52 require.NoError(t, err)
53
54}
55
56func DeleteUser(t *testing.T, httpClient *http.Client, serverURL, username string) {
57 retryWorker := func() (shouldRetry bool, err error, value *http.Response) {

Callers 13

TestRemoveCollectionFunction · 0.92
TestNotExistentDBRequestFunction · 0.92
TestAuditLoggingFieldsFunction · 0.85
TestCheckPermissionsFunction · 0.85
TestCheckRolesFunction · 0.85
TestAdminAuthFunction · 0.85
TestAdminAPIAuthFunction · 0.85

Calls 8

TestClusterUsernameFunction · 0.92
TestClusterPasswordFunction · 0.92
RetryLoopFunction · 0.92
TestCtxFunction · 0.92
CreateSleeperFuncFunction · 0.92
EncodeMethod · 0.65
CloseMethod · 0.65
AddMethod · 0.45

Tested by 13

TestRemoveCollectionFunction · 0.74
TestNotExistentDBRequestFunction · 0.74
TestAuditLoggingFieldsFunction · 0.68
TestCheckPermissionsFunction · 0.68
TestCheckRolesFunction · 0.68
TestAdminAuthFunction · 0.68
TestAdminAPIAuthFunction · 0.68