Skip to content

feat(auth2): Extend EmailAccountsAdmin with new methods needed for email account imports - #3690

Merged
tp merged 2 commits into
serverpod:mainfrom
tp:email-account-admin-extension
Jun 19, 2025
Merged

tp merged 2 commits into
serverpod:mainfrom
tp:email-account-admin-extension

Conversation

@tp

@tp tp commented Jun 19, 2025 •

Copy link
Copy Markdown
Contributor
  • findAccount: To check whether the model knows about an email address already
  • createEmailAuthentication: To create an email authentication without going through the verification flow
  • setPassword: To set an account's password without going through the password reset flow

Also, fixes unnecessary_non_null_assertion lint warnings.

Summary by CodeRabbit

  • New Features
    • Added methods for admin management of email authentication accounts, including finding accounts, creating new email authentication records, and setting passwords.
    • Introduced new exception handling for email accounts not found during administrative operations.
  • Bug Fixes
    • Improved password validation to handle empty hashes correctly.
  • Refactor
    • Enhanced internal code readability and consistency with formatting and comment improvements.
    • Replaced local utility extensions with shared internal utilities for byte data conversions.
  • Tests
    • Expanded test coverage for admin operations, password setting, and account retrieval.
    • Simplified test code by removing unnecessary null assertions and unused imports.

@coderabbitai

coderabbitai Bot commented Jun 19, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This update introduces new administrative methods for managing email authentication accounts, including account lookup, creation, and password setting. It adds a custom exception for missing accounts, refactors utility extensions for byte data conversions, and improves code clarity and test coverage. Minor formatting and documentation updates are also included.

Changes

File(s) Change Summary
.../serverpod_auth_email_account_server.dart Exported email_account_not_found_exception.dart to the public API.
.../src/business/email_account_not_found_exception.dart Added EmailAccountNotFoundException class for internal/admin error handling.
.../src/business/email_accounts_admin.dart Added findAccount, createEmailAuthentication, and setPassword methods for admin account management.
.../src/business/email_account_secret_hash.dart Added guard clause in validateHash to return false if hash is empty.
.../src/business/email_accounts.dart Improved formatting, documentation, and replaced local byte conversion extensions with imports.
.../src/util/byte_data_extension.dart Introduced ByteDataAsUint8List extension for converting ByteData to Uint8List.
.../src/util/uint8list_extension.dart Introduced Uint8ListAsByteDataExtension for converting Uint8List to ByteData.
.../test/integration/email_accounts_account_creation_test.dart Removed unnecessary null assertions and unused imports in tests.
.../test/integration/email_accounts_admin_test.dart Added tests for new admin methods; improved test structure and coverage; removed redundant null assertions.
.../test/integration/email_accounts_login_test.dart Removed unused imports and redundant null assertions in tests.
.../test/integration/email_accounts_password_reset_test.dart Removed unused imports and redundant null assertions in tests.

Sequence Diagram(s)

sequenceDiagram
    participant Admin
    participant EmailAccountsAdmin
    participant Database

    Admin->>EmailAccountsAdmin: findAccount(email)
    EmailAccountsAdmin->>Database: Query email account by email
    Database-->>EmailAccountsAdmin: Account data or null
    EmailAccountsAdmin-->>Admin: Account info or null

    Admin->>EmailAccountsAdmin: createEmailAuthentication(authUserId, email, password)
    EmailAccountsAdmin->>Database: Insert new email account (with hashed password)
    Database-->>EmailAccountsAdmin: New account ID
    EmailAccountsAdmin-->>Admin: Account ID

    Admin->>EmailAccountsAdmin: setPassword(email, password)
    EmailAccountsAdmin->>Database: Update password hash for email account
    Database-->>EmailAccountsAdmin: Success or throw EmailAccountNotFoundException
    EmailAccountsAdmin-->>Admin: Success or exception
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 08fd344 and 4647204.

📒 Files selected for processing (1)
  • modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts_admin.dart (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (53)
  • GitHub Check: CLI e2e tests (3.32.1, ubuntu-latest, tests/serverpod_cli_e2e_test)
  • GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_jwt/serverpod_auth_jwt_server with Flutter 3.32.1
  • GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server with Flutter 3.32.1
  • GitHub Check: CLI e2e tests (3.24.0, ubuntu-latest, tests/serverpod_cli_e2e_test)
  • GitHub Check: Version change test
  • GitHub Check: Module integration tests in tests/serverpod_test_module/serverpod_test_module_server with Flutter 3.32.1
  • GitHub Check: Serverpod integration tests (flutter)
  • GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_profile/serverpod_auth_profile_server with Flutter 3.32.1
  • GitHub Check: Module integration tests in modules/serverpod_auth/serverpod_auth_server with Flutter 3.24.0
  • GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server with Flutter 3.32.1
  • GitHub Check: Module integration tests in modules/serverpod_auth/serverpod_auth_server with Flutter 3.32.1
  • GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server with Flutter 3.24.0
  • GitHub Check: Serverpod E2E IO tests (3.32.1)
  • GitHub Check: Module integration tests in tests/serverpod_test_nonvector/serverpod_test_nonvector_server with Flutter 3.32.1
  • GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_profile/serverpod_auth_profile_server with Flutter 3.24.0
  • GitHub Check: Module integration tests in tests/serverpod_test_nonvector/serverpod_test_nonvector_server with Flutter 3.24.0
  • GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_jwt/serverpod_auth_jwt_server with Flutter 3.24.0
  • GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server with Flutter 3.24.0
  • GitHub Check: Serverpod E2E web tests (3.32.1)
  • GitHub Check: Serverpod integration tests (3.32.1, packages/serverpod_shared)
  • GitHub Check: Unit tests Web (3.24.0, windows-latest)
  • GitHub Check: Serverpod E2E web tests (3.24.0)
  • GitHub Check: dart analyze downgrade (3.24.0, windows-latest)
  • GitHub Check: dart analyze downgrade (3.32.1, ubuntu-latest)
  • GitHub Check: Unit tests IO (3.32.1, ubuntu-latest)
  • GitHub Check: Migration e2e tests (3.32.1)
  • GitHub Check: Unit tests IO (3.24.0, ubuntu-latest)
  • GitHub Check: dart analyze downgrade (3.24.0, ubuntu-latest)
  • GitHub Check: Unit tests IO (3.24.0, windows-latest)
  • GitHub Check: Flutter unit tests (3.32.1, windows-latest, packages/serverpod_flutter)
  • GitHub Check: dart analyze downgrade (3.32.1, windows-latest)
  • GitHub Check: Serverpod E2E IO tests (3.24.0)
  • GitHub Check: Unit tests IO (3.32.1, windows-latest)
  • GitHub Check: Unit tests Web (3.32.1, windows-latest)
  • GitHub Check: Serverpod concurrent integration tests (server) (3.24.0)
  • GitHub Check: Serverpod concurrent integration tests (server) (3.32.1)
  • GitHub Check: Unit tests Web (3.32.1, ubuntu-latest)
  • GitHub Check: Flutter unit tests (3.32.1, ubuntu-latest, packages/serverpod_flutter)
  • GitHub Check: Flutter unit tests (3.24.0, windows-latest, packages/serverpod_flutter)
  • GitHub Check: serverpod generate (3.32.1)
  • GitHub Check: Serverpod integration tests (server) (3.32.1)
  • GitHub Check: serverpod generate (3.24.0)
  • GitHub Check: Bootstrap tests (3.24.0, windows-latest, tests/bootstrap_project)
  • GitHub Check: Bootstrap tests (3.24.0, ubuntu-latest, tests/bootstrap_project)
  • GitHub Check: Migration e2e tests (3.24.0)
  • GitHub Check: update pubspecs (3.32.1)
  • GitHub Check: Bootstrap tests (3.32.1, ubuntu-latest, tests/bootstrap_project)
  • GitHub Check: Bootstrap tests (3.32.1, windows-latest, tests/bootstrap_project)
  • GitHub Check: Serverpod integration tests (server) (3.24.0)
  • GitHub Check: dart analyze latest (3.32.1, windows-latest)
  • GitHub Check: dart analyze (3.24.0, ubuntu-latest)
  • GitHub Check: dart analyze (3.24.0, windows-latest)
  • GitHub Check: dart analyze latest (3.32.1, ubuntu-latest)
🔇 Additional comments (6)
modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts_admin.dart (6)

1-1: LGTM: Imports are appropriate for the new functionality.

The new imports support the password hashing, byte data conversions, and typed data operations required by the new admin methods.

Also applies to: 7-7, 9-9


13-18: LGTM: Documentation improvements enhance clarity.

The updated comments provide clearer explanations of the method behavior and parameter usage.

Also applies to: 69-71


88-116: LGTM: Well-structured method with appropriate null handling.

The method correctly handles the email lookup with proper normalization and returns a clear contract. The use of account.id! on line 113 is acceptable since database queries should return records with valid IDs.


118-155: LGTM: Method addresses previous review feedback and implements secure password handling.

The documentation clearly explains the verification bypass and null password implications, addressing the previous review comment. The implementation correctly handles password hashing and provides appropriate transaction support.


88-195: Security considerations are well-documented and appropriate.

The new administrative methods appropriately bypass verification processes for their intended use case (email account imports). The @internal annotation and clear documentation about trusted sources and verification bypasses provide appropriate security context for these administrative functions.


157-195: ```shell
#!/bin/bash

Display the public API exports of the package to verify exception availability

cat modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/serverpod_auth_email_account_server.dart


</details>

</blockquote></details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNxU3bABsvkCiQBHbGlcABpIcVwvOkgAIgAzEmoACjQ8WAAmAEouAFEADxoMegADXOZtLwBBBiZsDFxEKtpmeAwSyAB3dVhIck7INlxYRWRyOhj4/D4SCvhfNFr8etwUZm5pxtDYlAaKRWwGaXsSKSpffsGSYdGI/AjYEkgyueqllaaWto6GLzRERAaGCPdC0WjqeD4DDINq/bBKDhGKAleJtWg1OoNEpcKpXG70AiMR4MADWKHiDyeiFkiBozHQXn8aFo8n8TCIGHgAC9jmhIERJGRILNKqDaP4ARoDMiGEyaOVKlV0ux4AxqJD2ji8SMCfdZUkaOgsCL5jhhiq1eIocK9vJwWyorJwnJuP9EG0iJTINgHGhfGd4KjLRqePsjpLpc9ENcrG7OtNaNjILihjq7idVph0O8GgByZCugHxij0bo3PB+QLYeAUD1e2mYWjOeiFxDF+gS65daYk+JefCdKUGZrgq0YP1eJ1e2xiiXR5CNyCo/LHLxtVadZycjBEZD+P40XXPerkcOIZyyAD6GCh1+8XkvbsoY5KQLgTwYsEwpAX8HphPiRZ5nUagnhNBYc1WP8N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E1rfYPmPqYkz7pbdCLHoiLTlJUgFe40xEJHrbYUzEsiDtAEt8OO9yKeDCYcUDHiHyIxguehqucvsHdWdIRHZ+cfqHa8wnZ82nY+a+daMvEC9Xe49BY3aES3Zix3ehZIYMEmSLxZrpd9dt3wkDfiFL2EiCZTrPmVghcPC1g6p1l3e/nt/KM2fRtWeZQ31mEIjdLtbgsda9ByzLZvCu/I525vTJ65TxYJaJdL9O8ZyT5K/8o5GajzYO+MuZR8V1s57g843liVcT5YGeAO+n2/zQhn/pDu8LbFZ93uFX4e4jKblDlC8gDsJNkcKhFYaJ1cJhfe4lLyPF8RWqal/7v17l+HvXhae17af3i7ZIB7edRt4HevvWZd730neY7QAc/VHbPNVmUUD3rOy94Ts2irpS8EDz94gtxY4WW/kHwz6ZoiGQxOIvuzx7Bsy4ZkaYHXwzaN8MWu3a0GwRxZ8A2+hLLoKPzdCJE6wW/JGEq0JAsCKAw/PSPvknhssy4h7IsmpyNi25mshSaEDQGZCSIm+FBfTgdyLbbpoMDfe8DjypgJtoMAwJ7tUkYEcgVycgo7g1wrBmdyBosZMGCHtaOknW+GV1lThoox99gfrePrwklg98pa47cAZOwxphpMBj3bPsZFGw4Uu+jce4HvyIiH8/sFhPgFYRsIOFQChOFwgOHsZCYrEEvHwn3T4qYRH+Q9CVs0y14ZF3+nbKEA3G/77QRoNoSqNVDwBTR00KcIrA0EWhoBloofdaF3D6hqBtoQ0PaAYFKFNR1Al4FCG0X8CqM6Al0ayCzRKhdCyokAbSBLniC0BVIAAFnmEZBASAgDIBkG0iAlRA8wzSBkHUgkBtImkVSGqAlzqQAA7CQHmG0B4gEuAQAAFYbhsw3aIYFKHzD1I8w04esPeGAl4gGQWgOpHiDzDVIpw04QwHiDxBVIaARIICUOHqQMgEueYQwDeEMBNIAIjIE8IOhQAeh8MfoYgNVxYJhhFUJ4UAA== -->

<!-- internal state end -->
<!-- tips_start -->

---

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.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=serverpod/serverpod&utm_content=3690):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@tp
tp force-pushed the email-account-admin-extension branch from 7fc34da to 64e539f Compare June 19, 2025 11:14
@tp tp changed the title Extend EmailAccountsAdmin with new methods needed for email account imports feat(auth2): Extend EmailAccountsAdmin with new methods needed for email account imports Jun 19, 2025
@tp
tp force-pushed the email-account-admin-extension branch from 64e539f to ee81043 Compare June 19, 2025 11:26
…ccount imports

- findAccount: To check whether the model knows about an email address already
- createEmailAuthentication: To create an email authentication without going through the verification flow
- setPassword: To set an account's password without going through the password reset flow

Also fix `unnecessary_non_null_assertion` lint warnings
@tp
tp force-pushed the email-account-admin-extension branch from ee81043 to 08fd344 Compare June 19, 2025 11:34
@tp
tp marked this pull request as ready for review June 19, 2025 11:44

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 0

♻️ Duplicate comments (3)
modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/test/integration/email_accounts_admin_test.dart (3)

53-75: Comprehensive test coverage for new admin methods.

The tests properly cover the new findAccount and setPassword admin methods with appropriate scenarios:

  • findAccount correctly returns null for pending accounts
  • setPassword properly throws EmailAccountNotFoundException for pending accounts

The test structure and assertions are well-designed and align with the security-focused admin functionality.


78-135: Excellent coverage for existing account scenarios.

The test group properly validates admin methods against verified accounts:

  • findAccount returns valid account data
  • setPassword successfully updates passwords and validates through login

The use of proper test isolation with setup/teardown and the verification through actual login attempts demonstrates thorough testing.


137-192: Comprehensive testing of createEmailAuthentication workflow.

The test group validates the new createEmailAuthentication method effectively:

  • Account creation bypasses normal verification flow
  • Immediate login capability is properly verified
  • Integration with findAccount method works correctly

This demonstrates the admin import functionality working as intended.

🧹 Nitpick comments (1)
modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts_admin.dart (1)

171-176: Consider using findFirstRow for consistency.

The method uses find followed by singleOrNull, while findAccount uses findFirstRow. Both approaches work correctly, but using findFirstRow would be more consistent and slightly more efficient.

-    var account = (await EmailAccount.db.find(
-      session,
-      where: (final t) => t.email.equals(email),
-      transaction: transaction,
-    ))
-        .singleOrNull;
+    var account = await EmailAccount.db.findFirstRow(
+      session,
+      where: (final t) => t.email.equals(email),
+      transaction: transaction,
+    );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e38b321 and 08fd344.

📒 Files selected for processing (11)
  • modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/serverpod_auth_email_account_server.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_account_not_found_exception.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_account_secret_hash.dart (2 hunks)
  • modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts.dart (13 hunks)
  • modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts_admin.dart (3 hunks)
  • modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/util/byte_data_extension.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/util/uint8list_extension.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/test/integration/email_accounts_account_creation_test.dart (3 hunks)
  • modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/test/integration/email_accounts_admin_test.dart (5 hunks)
  • modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/test/integration/email_accounts_login_test.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/test/integration/email_accounts_password_reset_test.dart (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_account_not_found_exception.dart (1)
Learnt from: tp
PR: serverpod/serverpod#3666
File: modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts_admin.dart:157-163
Timestamp: 2025-06-17T11:39:51.491Z
Learning: In `EmailAccountsAdmin` class methods, it's appropriate to throw specific errors like `EmailAccountNotFound` when email accounts don't exist, since this is admin-only functionality marked as `@internal`. However, in non-admin/public-facing contexts, avoid exposing whether email accounts exist to prevent account enumeration attacks - use generic error messages instead.
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Migration e2e tests (3.32.1)
  • GitHub Check: Migration e2e tests (3.24.0)
  • GitHub Check: Serverpod E2E web tests (3.24.0)
  • GitHub Check: Serverpod E2E web tests (3.32.1)
  • GitHub Check: dart analyze downgrade (3.32.1, windows-latest)
🔇 Additional comments (17)
modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/test/integration/email_accounts_login_test.dart (1)

22-22: LGTM! Improved type safety by removing unnecessary null assertion.

The removal of the ! operator indicates that authUser.id is now guaranteed to be non-null, which eliminates potential runtime exceptions and improves code safety.

modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/test/integration/email_accounts_password_reset_test.dart (1)

52-52: LGTM! Consistent type safety improvements.

The removal of unnecessary null assertion operators across multiple test setup blocks improves code safety and follows the same positive pattern seen in other test files.

Also applies to: 138-138, 225-225

modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_account_secret_hash.dart (2)

12-13: LGTM! Documentation formatting follows established guidelines.

The line wrapping to comply with the 80 character limit improves code consistency as noted in previous reviews.

Also applies to: 20-21


66-71: Excellent performance optimization with clear documentation.

The early return for empty hashes is a smart optimization that avoids expensive hash computations when no password is set. The accompanying comment clearly explains the business logic, making the code self-documenting.

modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/test/integration/email_accounts_account_creation_test.dart (1)

232-232: LGTM! Consistent type safety improvements across test suite.

The systematic removal of unnecessary null assertion operators from authUser.id improves code safety and maintains consistency with similar changes in other test files.

Also applies to: 293-293, 320-320

modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/serverpod_auth_email_account_server.dart (1)

2-2: LGTM! Proper API exposure for new exception class.

The export correctly makes EmailAccountNotFoundException available to package consumers, which is essential for handling exceptions thrown by the new admin methods introduced in this PR.

modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/util/byte_data_extension.dart (1)

5-10: LGTM! Clean utility extension implementation.

The ByteDataAsUint8List extension provides a clean wrapper around Uint8List.sublistView() and properly uses the @internal annotation to restrict usage within the package. This is a good refactoring that centralizes byte data conversion utilities.

modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/util/uint8list_extension.dart (1)

5-10: LGTM! Complementary extension implementation.

The Uint8ListAsByteDataExtension provides the reverse conversion from Uint8List to ByteData using ByteData.sublistView(). This complements the ByteDataAsUint8List extension nicely, providing bidirectional conversion utilities that are properly marked as internal.

modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_account_not_found_exception.dart (1)

1-17: Well-designed exception class for admin use.

The EmailAccountNotFoundException is properly implemented with clear documentation emphasizing internal/admin-only usage. This aligns with security best practices to prevent account enumeration attacks in public-facing contexts while allowing specific error handling in administrative operations.

modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts.dart (3)

9-10: Good refactoring to use centralized utility extensions.

The import of the new utility extensions replaces local byte data conversion logic with centralized, reusable utilities. This improves code organization and maintainability.


24-25: Excellent documentation improvements.

The enhanced documentation comments throughout the file provide clearer explanations of:

  • Transaction behavior and rollback implications
  • Security considerations for preventing information leakage
  • Expected exceptions and error conditions
  • Method purposes and return values

These improvements significantly enhance code maintainability and developer understanding.

Also applies to: 72-94, 187-201, 323-325, 387-396, 510-511, 528-529, 592-593


57-58: Consistent adoption of new extension methods.

The usage of .asUint8List and .asByteData extension methods throughout the file demonstrates consistent refactoring from local byte data conversions to the centralized utility extensions. This maintains the same functionality while improving code organization.

Also applies to: 163-166, 244-245, 366-367, 447-448, 472-473

modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts_admin.dart (5)

1-1: LGTM: New imports properly support the extended functionality.

The added imports for dart:typed_data, internal business logic, and utility extensions are appropriately used throughout the new methods.

Also applies to: 7-7, 9-9


13-18: LGTM: Documentation improvements enhance clarity.

The documentation updates improve consistency and clarity in describing the cleanup methods' behavior with null parameters.

Also applies to: 69-71


88-116: LGTM: findAccount method is well-implemented.

The method correctly:

  • Normalizes email to lowercase for consistent lookups
  • Uses findFirstRow for efficient single record retrieval
  • Returns a properly structured record with auth user ID, email account ID, and password status
  • Handles the case where no account exists by returning null
  • Supports optional transaction context

The use of passwordHash.lengthInBytes > 0 to determine password presence is appropriate.


118-154: LGTM: createEmailAuthentication method handles all scenarios correctly.

The method properly:

  • Normalizes email input consistently
  • Handles optional password by creating empty byte arrays when null
  • Uses secure password hashing via EmailAccountSecretHash.createHash
  • Converts Uint8List to ByteData using the extension method
  • Supports transaction context
  • Returns the newly created account ID

The approach of storing empty byte arrays for passwordless accounts is clean and consistent with the password checking logic in findAccount.


156-194: LGTM: setPassword method implements proper security and error handling.

The method correctly:

  • Normalizes email input consistently
  • Throws EmailAccountNotFoundException when account doesn't exist
  • Uses secure password hashing
  • Updates the account with proper transaction support
  • Bypasses password policy validation as documented for admin use

The implementation follows the established patterns and provides appropriate administrative control.

@tp
tp requested a review from SandPod June 19, 2025 11:50

@SandPod SandPod left a comment

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.

LGTM! 🚀

@tp
tp merged commit b99eeaa into serverpod:main Jun 19, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants