MCPcopy
hub / github.com/mattermost/mattermost / TestCreateUser

Function TestCreateUser

server/channels/app/user_test.go:341–409  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

339}
340
341func TestCreateUser(t *testing.T) {
342 mainHelper.Parallel(t)
343 th := Setup(t)
344
345 t.Run("fails if the username matches a group name", func(t *testing.T) {
346 group := th.CreateGroup(t)
347
348 id := model.NewId()
349 user := &model.User{
350 Email: "success+" + id + "@simulator.amazonses.com",
351 Username: *group.Name,
352 Nickname: "nn_" + id,
353 Password: model.NewTestPassword(),
354 EmailVerified: true,
355 }
356
357 user.Username = *group.Name
358 u, err := th.App.CreateUser(th.Context, user)
359 require.NotNil(t, err)
360 require.Nil(t, u)
361 })
362
363 t.Run("should sanitize user authdata before publishing to plugin hooks", func(t *testing.T) {
364 tearDown, _, _ := SetAppEnvironmentWithPlugins(t,
365 []string{
366 `
367 package main
368
369 import (
370 "github.com/mattermost/mattermost/server/public/plugin"
371 "github.com/mattermost/mattermost/server/public/model"
372 )
373
374 type MyPlugin struct {
375 plugin.MattermostPlugin
376 }
377
378 func (p *MyPlugin) UserHasBeenCreated(c *plugin.Context, user *model.User) {
379 user.Nickname = "sanitized"
380 if len(user.Password) > 0 {
381 user.Nickname = "not-sanitized"
382 }
383 p.API.UpdateUser(user)
384 }
385
386 func main() {
387 plugin.ClientMain(&MyPlugin{})
388 }
389 `,
390 }, th.App, th.NewPluginAPI)
391 defer tearDown()
392
393 user := &model.User{
394 Email: model.NewId() + "success+test@example.com",
395 Nickname: "Darth Vader",
396 Username: "vader" + model.NewId(),
397 Password: model.NewTestPassword(),
398 AuthService: "",

Callers

nothing calls this directly

Calls 10

tearDownFunction · 0.85
NotNilMethod · 0.80
SetupFunction · 0.70
RunMethod · 0.65
CreateGroupMethod · 0.65
CreateUserMethod · 0.65
GetUserMethod · 0.65
ParallelMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…