Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

test(social): close coverage gaps for TokenRedactor and 429 handling

Paulo Castellanof975171a9a10
diff --git a/tests/Feature/Services/Social/ConnectionVerifierTest.php b/tests/Feature/Services/Social/ConnectionVerifierTest.php
index 8488a9723..34c94f92d 100644
--- a/tests/Feature/Services/Social/ConnectionVerifierTest.php
+++ b/tests/Feature/Services/Social/ConnectionVerifierTest.php
@@ -409,6 +409,21 @@ test('4xx during refresh keeps raising TokenExpiredException', function () {
expect(fn () => $verifier->refreshToken($account))->toThrow(TokenExpiredException::class);
});
+test('429 during refresh raises PlatformUnavailableException (rate limit is transient)', function () {
+ Http::fake([
+ 'api.x.com/2/oauth2/token' => Http::response(['error' => 'rate_limit_exceeded'], 429),
+ ]);
+
+ $account = SocialAccount::factory()->x()->create([
+ 'token_expires_at' => now()->subMinutes(5),
+ 'refresh_token' => 'old_refresh_token',
+ ]);
+
+ $verifier = new ConnectionVerifier;
+
+ expect(fn () => $verifier->refreshToken($account))->toThrow(PlatformUnavailableException::class);
+});
+
test('bluesky 5xx during refresh raises PlatformUnavailable even when password fallback is stored', function () {
Http::fake([
'bsky.social/xrpc/com.atproto.server.refreshSession' => Http::response('upstream timeout', 503),
diff --git a/tests/Unit/Services/Social/TokenRedactorTest.php b/tests/Unit/Services/Social/TokenRedactorTest.php
new file mode 100644
index 000000000..f3e4df092
--- /dev/null
+++ b/tests/Unit/Services/Social/TokenRedactorTest.php
@@ -0,0 +1,47 @@
+<?php
+
+declare(strict_types=1);
+
+use App\Services\Social\TokenRedactor;
+
+test('redact strips access_token in URL form', function () {
+ $input = 'POST https://api.example.com?access_token=abc123xyz&page=1';
+
+ expect(TokenRedactor::redact($input))->toBe('POST https://api.example.com?access_token=[REDACTED]&page=1');
+});
+
+test('redact strips access_token in JSON form', function () {
+ $input = '{"data":{"access_token":"abc123xyz","expires_in":3600}}';
+
+ expect(TokenRedactor::redact($input))->toBe('{"data":{"access_token":"[REDACTED]","expires_in":3600}}');
+});
+
+test('redact strips Bearer authorization header', function () {
+ $input = "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.payload.sig\n";
+
+ expect(TokenRedactor::redact($input))->toBe("Authorization: Bearer [REDACTED]\n");
+});
+
+test('redact strips "token" JSON field', function () {
+ $input = '{"token":"shhh-secret","other":"keep"}';
+
+ expect(TokenRedactor::redact($input))->toBe('{"token":"[REDACTED]","other":"keep"}');
+});
+
+test('redact handles multiple secrets in the same body', function () {
+ $input = 'access_token=one&refresh_token=two with Bearer xyz';
+ $output = TokenRedactor::redact($input);
+
+ expect($output)->toContain('access_token=[REDACTED]')
+ ->toContain('Bearer [REDACTED]');
+});
+
+test('redact returns null when input is null', function () {
+ expect(TokenRedactor::redact(null))->toBeNull();
+});
+
+test('redact returns the input unchanged when nothing matches', function () {
+ $input = 'plain log line with no secrets';
+
+ expect(TokenRedactor::redact($input))->toBe($input);
+});