MCPcopy
hub / github.com/seaweedfs/seaweedfs / TestCreateUserDoesNotSaveAllUsers

Function TestCreateUserDoesNotSaveAllUsers

weed/iamapi/iamapi_test.go:624–659  ·  view source on GitHub ↗

TestCreateUserDoesNotSaveAllUsers is a regression test for the bug where creating a new user triggered a full SaveConfiguration over all existing identities (causing N file writes + reload cycles in the filer_etc store). The fix uses credentialManager.CreateUser for a targeted single-file write.

(t *testing.T)

Source from the content-addressed store, hash-verified

622// identities (causing N file writes + reload cycles in the filer_etc store).
623// The fix uses credentialManager.CreateUser for a targeted single-file write.
624func TestCreateUserDoesNotSaveAllUsers(t *testing.T) {
625 srv, cm, counter := iamApiServerWithCredentialManager()
626 ctx := context.Background()
627
628 // Pre-populate three existing users.
629 for _, name := range []string{"existing-1", "existing-2", "existing-3"} {
630 require.NoError(t, cm.CreateUser(ctx, &iam_pb.Identity{Name: name}))
631 }
632
633 // Create a new user via the HTTP API.
634 params := &iam.CreateUserInput{UserName: aws.String("new-user")}
635 req, _ := iam.New(session.New()).CreateUserRequest(params)
636 _ = req.Build()
637 out := CreateUserResponse{}
638 resp, err := executeRequestWith(srv, req.HTTPRequest, &out)
639 require.NoError(t, err)
640 require.Equal(t, http.StatusOK, resp.Code)
641
642 // The new user must appear in the store.
643 newUser, userErr := cm.GetUser(ctx, "new-user")
644 require.NoError(t, userErr)
645 require.Equal(t, "new-user", newUser.Name)
646
647 // Critical: full SaveConfiguration (PutS3ApiConfiguration) must NOT have
648 // been called. Before the fix it was called once per CreateUser, rewriting
649 // every existing user file and triggering a cascade of reload events.
650 assert.Equal(t, 0, counter.putCalled,
651 "CreateUser must not trigger a full PutS3ApiConfiguration over all users")
652
653 // All pre-existing users must still be intact.
654 for _, name := range []string{"existing-1", "existing-2", "existing-3"} {
655 u, err := cm.GetUser(ctx, name)
656 require.NoError(t, err, "pre-existing user %s should still exist", name)
657 assert.Equal(t, name, u.Name)
658 }
659}

Callers

nothing calls this directly

Calls 5

executeRequestWithFunction · 0.85
CreateUserMethod · 0.65
StringMethod · 0.65
GetUserMethod · 0.65

Tested by

no test coverage detected