MCPcopy Index your code
hub / github.com/coder/coder / addUser

Function addUser

coderd/httpmw/authorize_test.go:143–187  ·  view source on GitHub ↗
(t *testing.T, db database.Store, roles ...string)

Source from the content-addressed store, hash-verified

141}
142
143func addUser(t *testing.T, db database.Store, roles ...string) (database.User, string) {
144 id, secret, hashed := randomAPIKeyParts()
145 if roles == nil {
146 roles = []string{}
147 }
148
149 user, err := db.InsertUser(context.Background(), database.InsertUserParams{
150 ID: uuid.New(),
151 Email: "admin@email.com",
152 Username: "admin",
153 RBACRoles: roles,
154 LoginType: database.LoginTypePassword,
155 })
156 require.NoError(t, err)
157
158 user, err = db.UpdateUserStatus(context.Background(), database.UpdateUserStatusParams{
159 ID: user.ID,
160 Status: database.UserStatusActive,
161 UpdatedAt: dbtime.Now(),
162 })
163 require.NoError(t, err)
164
165 _, err = db.InsertAPIKey(context.Background(), database.InsertAPIKeyParams{
166 ID: id,
167 UserID: user.ID,
168 HashedSecret: hashed,
169 LastUsed: dbtime.Now(),
170 ExpiresAt: dbtime.Now().Add(time.Minute),
171 LoginType: database.LoginTypePassword,
172 Scopes: database.APIKeyScopes{database.ApiKeyScopeCoderAll},
173 AllowList: database.AllowList{
174 {Type: policy.WildcardSymbol, ID: policy.WildcardSymbol},
175 },
176 IPAddress: pqtype.Inet{
177 IPNet: net.IPNet{
178 IP: net.ParseIP("0.0.0.0"),
179 Mask: net.IPMask{0, 0, 0, 0},
180 },
181 Valid: true,
182 },
183 })
184 require.NoError(t, err)
185
186 return user, fmt.Sprintf("%s-%s", id, secret)
187}

Callers 1

TestExtractUserRolesFunction · 0.70

Calls 7

NowFunction · 0.92
randomAPIKeyPartsFunction · 0.85
InsertUserMethod · 0.65
NewMethod · 0.65
UpdateUserStatusMethod · 0.65
InsertAPIKeyMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected