Skip to content

Send test SMS with the credentials entered in the console - #270

Merged
roncodes merged 1 commit into
mainfrom
fix/sms-test-uses-entered-credentials
Sep 25, 2026
Merged

roncodes merged 1 commit into
mainfrom
fix/sms-test-uses-entered-credentials

Conversation

@roncodes

Copy link
Copy Markdown
Member

Fixes fleetbase/fleetbase#680.

Why

In Admin → System Config → Services, Test SMS Provider failed with "Credentials are required to create a Client" even though a Twilio SID and token were filled in.

testSmsProviderConfig and testTwilioConfig do apply the entered credentials to config, but the Twilio client never used them:

  • The Twilio Manager copies its connection settings when it's built, and it's cached twice: as the twilio container singleton and in the facade's static cache.
  • Under Octane the facade cache outlives the request. The provider's singleton closure also reads the worker's base application config, not the request's copy.

A test send therefore used whatever client the worker built first. That meant empty credentials when none were saved yet (the reported error), or the saved credentials instead of the ones just entered, which makes the test report success for the wrong account.

What changed

  • After applying the entered credentials, both endpoints rebuild the manager from this request's config and clear the facade cache (refreshTwilioClient). A stand-in bound in place of the real manager is left alone.
  • When the test send is done, the facade cache is cleared again (releaseTwilioClient). The credentials under test then can't be reused by later requests in the same worker, such as verification codes or notifications.

Verification

  • Reproduced on the dev stack (Octane), sending to an invalid number so nothing is delivered. Before the fix, fake credentials were ignored and the saved ones were used. After the fix:
    • fake credentials get [HTTP 401] Authentication Error from Twilio every time;
    • a test with no credentials straight afterwards uses the saved ones again, so nothing lingers;
    • the older "Test Twilio" endpoint behaves the same way.
  • New tests:
    • A recording Manager bound like the provider's (closure over the config at boot, already resolved) is rebuilt with the entered credentials, for both endpoints.
    • A bound but not yet built manager is built from the current config.
    • A stand-in is left in place.
    • The facade cache is empty after a send.
    • The two send tests fail without the fix.
  • Full suite: 1,797 passing. SettingController is at 100% coverage. php-cs-fixer and the date-drift check are clean.

"Test SMS Provider" failed with "Credentials are required to create a
Client" even with a Twilio SID and token filled in (fleetbase/fleetbase#680).

The test endpoints apply the entered credentials to config, but the Twilio
manager copies its settings when it is built and is cached twice: as a
container singleton and in the facade's static cache. Under Octane that
facade cache outlives the request, and the provider's singleton closure
reads the worker's base config rather than the request's copy. So a test
send used whatever the worker first built: empty credentials when none were
saved (the reported error), or the saved ones instead of those just entered.

- After applying the entered credentials, both test endpoints rebuild the
  manager from this request's config and clear the facade cache. A stand-in
  bound in place of the real manager is left alone.
- Once the test send is done the facade cache is cleared again, so the
  credentials under test are not reused by later requests in the worker.

Fixes fleetbase/fleetbase#680
@roncodes roncodes mentioned this pull request Sep 25, 2026
@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3e1e14a) to head (916e70f).

Additional details and impacted files
@@             Coverage Diff             @@
##                main      #270   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity      7410      7417    +7     
===========================================
  Files            430       430           
  Lines          24357     24374   +17     
===========================================
+ Hits           24357     24374   +17     
Flag Coverage Δ
backend 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roncodes
roncodes merged commit 1b94796 into main Sep 25, 2026
7 checks passed
@roncodes
roncodes deleted the fix/sms-test-uses-entered-credentials branch September 25, 2026 10:11
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.

Unable to send test SMS

1 participant