feat(customers): add a non-production verification-code bypass - #294
Merged
Conversation
Signing up a customer locally means waiting on a real email or paying for a real SMS, because the three code-checking endpoints (POST /v1/customers, /customers/verify-code, /customers/reset-password) match against real VerificationCode rows and there is no way to short-circuit them. Navigator already has fleetops.navigator.bypass_verification_code for exactly this need on the driver side; this is the customer equivalent. Adds fleetops.customers.verification_bypass_code, read from FLEETOPS_CUSTOMER_VERIFICATION_BYPASS_CODE, guarded by the same three conditions the console uses in AuthController::authenticateWithVerificationCode: a code must be configured, the app must not be in production, and the comparison is constant-time. With the variable unset -- the default -- the bypass cannot fire, and config/app.php resolves `env` to production when neither APP_ENV nor ENVIRONMENT is set, so it fails safe. Deliberately a distinct env var, not SMS_AUTH_BYPASS_CODE: that one already gates operator console login and driver login, and sharing it would make a single leaked value unlock three privilege tiers. The guard is intentionally NOT folded into verificationCodeExists() / findVerificationCode(). Those are test seams the controller contract tests override, so a policy living inside them would be stubbed away precisely where it needs asserting. CreateCustomerRequest's `code` rule is relaxed from `exists:verification_codes,code` to `required|string`. This is not a weakening: the controller matches code + for + meta->identity, whereas the `exists` rule accepts any live code issued for any purpose to any user. The rule is also already unenforced on the proxy path, since verifyCode() with for=fleetops_create_customer calls create(CreateCustomerRequest::createFrom()), which never runs validateResolved(). Left in place it would block the bypass before the controller ever sees the request. Tests cover: inert when unset and when empty; accepted for all three endpoints when configured and matching; a non-matching code still rejected while the bypass is live; rejected in production even when configured; and resetPassword surviving the null VerificationCode on the bypass path while still revoking sessions. 10/10 in ApiCustomerControllerContractsTest, 21/21 in RequestContractsTest. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Open
CustomerEndpointTest matches against the literal source text of CreateCustomerRequest, so relaxing the `code` rule from `required|exists:verification_codes,code` to `required|string` failed the suite even though the behaviour under test was unchanged: Test Failed (CustomerEndpointTest::__pest_evaluable_FormRequest_validators _are_present_and_authorize_via_api_credential) Update the expected string and note the coupling, so the next rule change tells the reader why this file has to move with it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #294 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 9766 9774 +8
===========================================
Files 521 521
Lines 37762 37769 +7
===========================================
+ Hits 37762 37769 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Signing up a customer locally means waiting on a real email or paying for a real SMS: the three code-checking endpoints (
POST /v1/customers,/customers/verify-code,/customers/reset-password) match against realVerificationCoderows with no way to short-circuit them.Navigator already has
fleetops.navigator.bypass_verification_codefor exactly this need on the driver side. This is the customer equivalent, for local development and staging QA.This is optional. It is not needed for the API-contract run — that seeds real verification codes instead (fleetbase/fleetbase#581), deliberately, so CI needs no production diff. Review this on its own merits.
The guard
Adds
fleetops.customers.verification_bypass_code, read fromFLEETOPS_CUSTOMER_VERIFICATION_BYPASS_CODE, with the same three conditions the console uses inAuthController::authenticateWithVerificationCode:Fails safe:
config/app.phpresolvesenvtoproductionwhen neitherAPP_ENVnorENVIRONMENTis set, so an unconfigured install cannot be bypassed even accidentally.Deliberately a distinct env var, not
SMS_AUTH_BYPASS_CODE— that one already gates operator console login and driver login, and sharing it would make a single leaked value unlock three privilege tiers. No fallback chain, for the same reason.!== null && !== ''rather than!empty(), so a configured code of"0"still works.Two deliberate choices worth reviewing
The guard is not folded into
verificationCodeExists()/findVerificationCode(). Those are test seams the controller contract tests override on a subclass — a policy living inside them would be stubbed away precisely where it needs asserting. AndfindVerificationCode()must return a model (resetPasswordcalls->delete()on it), so there is no honest "bypassed" return value.CreateCustomerRequest'scoderule is relaxed fromexists:verification_codes,codetorequired|string. This is the part most likely to draw fire, so to be explicit — it is not a weakening:code+for+meta->identity, whereasexists:verification_codes,codeaccepts any live code issued for any purpose to any user;verifyCode()withfor=fleetops_create_customercallscreate(CreateCustomerRequest::createFrom($request)), which never runsvalidateResolved();Tests
ApiCustomerControllerContractsTest10/10,RequestContractsTest21/21. New coverage:resetPasswordsurviving the nullVerificationCodeon the bypass path while still revoking sessions.The harness binds a bare
Illuminate\Container\Containerwith noenvironment(), so the tests swap in a container subclass — same pattern asfleetOpsNotificationWithEnvironment()inNotificationAndMailContractsTest, extended to carry all bindings across.🤖 Generated with Claude Code