bitwarden / passwordless-dotnet

Bitwarden Passwordless.dev .NET SDK.
https://bitwarden.com/
Apache License 2.0
36 stars 11 forks source link

PAS-542 | Delay and consolidate coercion and validation of `PasswordlessOptions` #143

Closed Tyrrrz closed 3 months ago

Tyrrrz commented 3 months ago

This PR does the following:

  1. Moves the validation of ApiSecret from service registration (eager) to when the API requests are actually sent (lazy).
    • This makes it possible to register a Passwordless client with invalid ApiSecret and have it fail only when the client is actually used.
    • It prevents an issue in a DI scenario where a service may depend on Passwordless client, but not rely on it when the secret is not provided (think the initialization flow in the Admin Console). Previously, the validation would prevent the service from being created entirely. Now it will only fail when any of the methods on the client are called.
  2. Moves the coercion of the ApiUrl (defaulting to CloudApiUrl when not set) from service registration to client initialization.
    • This makes it so that PasswordlessClient can be initialized with a null value of ApiUrl, even without DI, resulting in a more uniform behavior.
    • This makes the nullability annotations more reasonable, as previously we used ApiUrl ??= CloudApiUrl even though the former can never be null in our type model.

Both of these changes also significantly simplify the service registration code, while making all initialization routes (DI or non-DI) work the same way.

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 86.27451% with 7 lines in your changes missing coverage. Please review.

Project coverage is 61.39%. Comparing base (a1bc696) to head (7b6a392).

Files Patch % Lines
src/Passwordless/PasswordlessClient.cs 87.50% 5 Missing and 1 partial :warning:
src/Passwordless/ServiceCollectionExtensions.cs 50.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #143 +/- ## ========================================== + Coverage 60.31% 61.39% +1.08% ========================================== Files 43 43 Lines 640 658 +18 Branches 55 56 +1 ========================================== + Hits 386 404 +18 - Misses 249 250 +1 + Partials 5 4 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.