Skip to content

test: add regression tests for null name in Users.CreateUser endpoints#11618

Open
abishekgiri wants to merge 2 commits intoappwrite:1.9.xfrom
abishekgiri:test-8785-null-name-create-user
Open

test: add regression tests for null name in Users.CreateUser endpoints#11618
abishekgiri wants to merge 2 commits intoappwrite:1.9.xfrom
abishekgiri:test-8785-null-name-create-user

Conversation

@abishekgiri
Copy link
Copy Markdown

Fixes #8785

Summary

The issue describes that Users.CreateUser endpoints return a vague server error when name is null.

The core fix already exists in app/controllers/api/users.php, where null names are normalized to an empty string.

This PR adds regression test coverage to ensure this behavior is preserved.

Changes

  • Added provider-backed e2e tests for create user endpoints with name: null
  • Verified endpoints return 201 and normalize name to empty string
  • This ensures future changes do not reintroduce the bug.

Testing

docker compose exec appwrite test /usr/src/code/tests/e2e/Services/Users --filter=testCreateUserWithNullName

All tests passed:

  • 8 tests
  • 45 assertions

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

The pull request adds comprehensive test coverage for user creation with null name values. A new static data provider supplies test variants for eight password hashing endpoints (/users, /users/md5, /users/bcrypt, /users/argon2, /users/sha, /users/phpass, /users/scrypt, /users/scrypt-modified). A corresponding parameterized test method validates that users can be created with name set to null, expects HTTP 201 responses, and verifies that the null name is normalized to an empty string in the response body.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding regression tests for null name handling in Users.CreateUser endpoints.
Description check ✅ Passed The description is related to the changeset, explaining the fix context, the tests added, and the testing approach.
Linked Issues check ✅ Passed The PR directly addresses issue #8785 by adding test coverage for the null name handling behavior that should prevent server errors.
Out of Scope Changes check ✅ Passed All changes focus solely on adding regression test coverage for null name behavior, which is directly aligned with the PR objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@abishekgiri
Copy link
Copy Markdown
Author

Hi! This is my first contribution. Happy to make any changes if needed. Thanks!

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 24, 2026

Greptile Summary

This PR adds a DataProvider-driven regression test (testCreateUserWithNullName) to verify that all 8 Users.CreateUser endpoints return HTTP 201 and normalize a null name parameter to an empty string — the core fix ($name = $name ?? '') already exists in app/controllers/api/users.php.

Key observations:

  • All 8 password-type endpoints (/users, /users/md5, /users/bcrypt, /users/argon2, /users/sha, /users/phpass, /users/scrypt, /users/scrypt-modified) are covered, matching the PR's stated count of 8 tests / 45 assertions.
  • The SHA-512 hash value (4243da0a...c70) and Scrypt hash value (3fdef497...1d5b) are both 128 hex characters, which are the correct lengths for their respective algorithms (passwordLength: 64 → 64 bytes → 128 hex chars).
  • The test creates users with unique IDs on every run, so repeated executions will not conflict, but the created users are never deleted — this will accumulate stale records in the test database over time (see inline comment).
  • The array_merge ordering correctly keeps name: null for all providers since none of the payload arrays include a name key.

Confidence Score: 4/5

  • Safe to merge — test-only PR with no production code changes; regression coverage is thorough and correct.
  • The PR adds only test code covering a pre-existing bug fix. The data provider correctly covers all 8 user-creation endpoints, hash values are the right lengths, and the assertion logic is sound. The single deduction is for the missing teardown, which will accumulate stale users in the test database on repeated runs but does not affect correctness or production code.
  • No files require special attention; the only recommendation is adding cleanup for created users in tests/e2e/Services/Users/UsersBase.php.

Important Files Changed

Filename Overview
tests/e2e/Services/Users/UsersBase.php Adds a DataProvider-driven test method testCreateUserWithNullName covering all 8 user-creation endpoints; test logic is correct but created users are never cleaned up and two minor hash-length concerns are worth verifying.

Reviews (1): Last reviewed commit: "Merge branch '1.9.x' into test-8785-null..." | Re-trigger Greptile

Comment on lines +374 to +393
#[DataProvider('createUserNullNameProvider')]
public function testCreateUserWithNullName(string $path, array $payload): void
{
$userId = 'null-name-' . ID::unique();
$email = $userId . '@example.test';

$user = $this->client->call(Client::METHOD_POST, $path, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), array_merge([
'userId' => $userId,
'email' => $email,
'name' => null,
], $payload));

$this->assertEquals(Response::STATUS_CODE_CREATED, $user['headers']['status-code']);
$this->assertEquals($userId, $user['body']['$id']);
$this->assertEquals($email, $user['body']['email']);
$this->assertSame('', $user['body']['name']);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 No teardown for created users

The test creates up to 8 real users (one per provider entry) but never deletes them. While ID::unique() prevents collisions on repeated runs, the test database will accumulate stale null-name-* users over time.

Consider either adding a teardown step inside the test or deleting each user after asserting the result:

// After your existing assertions:
$this->client->call(Client::METHOD_DELETE, '/users/' . $userId, array_merge([
    'content-type' => 'application/json',
    'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));

This keeps the test database clean without affecting the regression coverage.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
tests/e2e/Services/Users/UsersBase.php (2)

313-370: Reduce fixture duplication to avoid drift between test helpers.

The hashed payloads here duplicate values already defined in setupHashedPasswordUsers() (Line 97-181). Consider centralizing these fixtures in one shared map/helper and reusing it in both places.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/Services/Users/UsersBase.php` around lines 313 - 370, The tests
duplicate hashed-password fixtures between the return dataset and
setupHashedPasswordUsers(); extract the common map into a shared constant or
helper (e.g., HASHED_PASSWORD_FIXTURES) and have both the data provider (the
returned array with keys
'plaintext','md5','bcrypt','argon2','sha','phpass','scrypt','scrypt-modified')
and the setupHashedPasswordUsers() function reference that single source; update
UsersBase.php to remove the inline duplicate arrays and import/consume the
shared map so all fixtures are maintained in one place.

311-312: Add PHPDoc for the new data provider and test method.

Both newly added public methods are missing PHPDoc comments required by repository standards.

✍️ Suggested update
+    /**
+     * Provides create-user endpoint payload variants for null-name regression coverage.
+     *
+     * `@return` array<string, array{0:string, 1:array<string, mixed>}>
+     */
     public static function createUserNullNameProvider(): array
     {
         return [
             // ...
         ];
     }

+    /**
+     * Ensures create-user endpoints accept `name: null` and normalize it to an empty string.
+     */
     #[DataProvider('createUserNullNameProvider')]
     public function testCreateUserWithNullName(string $path, array $payload): void
     {
         // ...
     }

As per coding guidelines, "Include comprehensive PHPDoc comments".

Also applies to: 374-376

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/Services/Users/UsersBase.php` around lines 311 - 312, Add
comprehensive PHPDoc comments for the new public data provider
createUserNullNameProvider and the corresponding public test method: include a
one-line description, the `@return` array annotation for the provider, and for the
test method include a description plus `@dataProvider` annotation reference and
`@param` type annotations as required by repository standards so both methods have
full PHPDoc blocks matching existing tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/e2e/Services/Users/UsersBase.php`:
- Around line 313-370: The tests duplicate hashed-password fixtures between the
return dataset and setupHashedPasswordUsers(); extract the common map into a
shared constant or helper (e.g., HASHED_PASSWORD_FIXTURES) and have both the
data provider (the returned array with keys
'plaintext','md5','bcrypt','argon2','sha','phpass','scrypt','scrypt-modified')
and the setupHashedPasswordUsers() function reference that single source; update
UsersBase.php to remove the inline duplicate arrays and import/consume the
shared map so all fixtures are maintained in one place.
- Around line 311-312: Add comprehensive PHPDoc comments for the new public data
provider createUserNullNameProvider and the corresponding public test method:
include a one-line description, the `@return` array annotation for the provider,
and for the test method include a description plus `@dataProvider` annotation
reference and `@param` type annotations as required by repository standards so
both methods have full PHPDoc blocks matching existing tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 17604927-7fb7-4eb2-b45a-b60b4cc911a9

📥 Commits

Reviewing files that changed from the base of the PR and between d53cad2 and 8119bf8.

📒 Files selected for processing (1)
  • tests/e2e/Services/Users/UsersBase.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: All Users.CreateUser... endpoints return a vague server error is null name is provided

1 participant