Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3bd051f

Browse filesBrowse files
committed
bug #49025 [Notifier] [OvhCloud] handle invalid receiver (seferov)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Notifier] [OvhCloud] handle invalid receiver | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT Fix `Undefined offset: 0` error when invalid receiver is provided Commits ------- d41f0bf [Notifier] [OvhCloud] handle invalid receiver
2 parents bf901b8 + d41f0bf commit 3bd051f
Copy full SHA for 3bd051f

File tree

2 files changed

+27
-0
lines changed
Filter options

2 files changed

+27
-0
lines changed

‎src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransport.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ protected function doSend(MessageInterface $message): SentMessage
121121

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

124+
if (!isset($success['ids'][0])) {
125+
throw new TransportException(sprintf('Attempt to send the SMS to invalid receivers: "%s".', implode(',', $success['invalidReceivers'])), $response);
126+
}
127+
124128
$sentMessage = new SentMessage($message, (string) $this);
125129
$sentMessage->setMessageId($success['ids'][0]);
126130

‎src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportTest.php
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\HttpClient\MockHttpClient;
1515
use Symfony\Component\HttpClient\Response\MockResponse;
1616
use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransport;
17+
use Symfony\Component\Notifier\Exception\TransportException;
1718
use Symfony\Component\Notifier\Message\ChatMessage;
1819
use Symfony\Component\Notifier\Message\MessageInterface;
1920
use Symfony\Component\Notifier\Message\SmsMessage;
@@ -92,4 +93,26 @@ public function testValidSignature(string $message)
9293
$toSign = 'applicationSecret+consumerKey+POST+'.$endpoint.'+'.$body.'+'.$time;
9394
$this->assertSame('$1$'.sha1($toSign), $signature);
9495
}
96+
97+
public function testInvalidReceiver()
98+
{
99+
$smsMessage = new SmsMessage('invalid_receiver', 'lorem ipsum');
100+
101+
$data = json_encode([
102+
'totalCreditsRemoved' => '1',
103+
'invalidReceivers' => ['invalid_receiver'],
104+
'ids' => [],
105+
'validReceivers' => [],
106+
]);
107+
$responses = [
108+
new MockResponse((string) time()),
109+
new MockResponse($data),
110+
];
111+
112+
$transport = $this->createTransport(new MockHttpClient($responses));
113+
114+
$this->expectException(TransportException::class);
115+
$this->expectExceptionMessage('Attempt to send the SMS to invalid receivers: "invalid_receiver"');
116+
$transport->send($smsMessage);
117+
}
95118
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.