10000 [Notifier] [OvhCloud] handle invalid receiver by seferov · Pull Request #49025 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Notifier] [OvhCloud] handle invalid receiver #49025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files. 8000
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ protected function doSend(MessageInterface $message): SentMessage

$success = $response->toArray(false);

if (!isset($success['ids'][0])) {
throw new TransportException(sprintf('Attempt to send the SMS to invalid receivers: "%s".', implode(',', $success['invalidReceivers'])), $response);
}

$sentMessage = new SentMessage($message, (string) $this);
$sentMessage->setMessageId($success['ids'][0]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransport;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
Expand Down Expand Up @@ -92,4 +93,26 @@ public function testValidSignature(string $message)
$toSign = 'applicationSecret+consumerKey+POST+'.$endpoint.'+'.$body.'+'.$time;
$this->assertSame('$1$'.sha1($toSign), $signature);
}

public function testInvalidReceiver()
{
$smsMessage = new SmsMessage('invalid_receiver', 'lorem ipsum');

$data = json_encode([
'totalCreditsRemoved' => '1',
'invalidReceivers' => ['invalid_receiver'],
'ids' => [],
'validReceivers' => [],
]);
$responses = [
new MockResponse((string) time()),
new MockResponse($data),
];

$transport = $this->createTransport(new MockHttpClient($responses));

$this->expectException(TransportException::class);
$this->expectExceptionMessage('Attempt to send the SMS to invalid receivers: "invalid_receiver"');
$transport->send($smsMessage);
}
}
0