8000 [Notifier] [OvhCloud] “Invalid signature” for message with slashes · symfony/symfony@9f01fb8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9f01fb8

Browse files
OneT0uchOskarStark
authored andcommitted
[Notifier] [OvhCloud] “Invalid signature” for message with slashes
1 parent 6928dde commit 9f01fb8

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,16 @@ protected function doSend(MessageInterface $message): void
7575
$now = time() + $this->calculateTimeDelta();
7676
$headers['X-Ovh-Application'] = $this->applicationKey;
7777
$headers['X-Ovh-Timestamp'] = $now;
78+
$headers['Content-Type'] = 'application/json';
7879

79-
$toSign = $this->applicationSecret.'+'.$this->consumerKey.'+POST+'.$endpoint.'+'.json_encode($content, \JSON_UNESCAPED_SLASHES).'+'.$now;
80+
$body = json_encode($content, \JSON_UNESCAPED_SLASHES);
81+
$toSign = $this->applicationSecret.'+'.$this->consumerKey.'+POST+'.$endpoint.'+'.$body.'+'.$now;
8082
$headers['X-Ovh-Consumer'] = $this->consumerKey;
8183
$headers['X-Ovh-Signature'] = '$1$'.sha1($toSign);
8284

8385
$response = $this->client->request('POST', $endpoint, [
8486
'headers' => $headers,
85-
'json' => $content,
87+
'body' => $body,
8688
]);
8789

8890
if (200 !== $response->getStatusCode()) {

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\OvhCloud\Tests;
1313

14+
use Symfony\Component\HttpClient\MockHttpClient;
15+
use Symfony\Component\HttpClient\Response\MockResponse;
1416
use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransport;
1517
use Symfony\Component\Notifier\Message\ChatMessage;
1618
use Symfony\Component\Notifier\Message\MessageInterface;
@@ -44,4 +46,39 @@ public function unsupportedMessagesProvider(): iterable
4446
yield [new ChatMessage('Hello!')];
4547
yield [$this->createMock(MessageInterface::class)];
4648
}
49+
50+
public function validMessagesProvider(): iterable
51+
{
52+
yield 'without a slash' => ['hello'];
53+
yield 'including a slash' => ['hel/lo'];
54+
}
55+
56+
/**
57+
* @group time-sensitive
58+
*
59+
* @dataProvider validMessagesProvider
60+
*/
61+
public function testValidSignature(string $message)
62+
{
63+
$smsMessage = new SmsMessage('0611223344', $message);
64+
65+
$time = time();
66+
67+
$lastResponse = new MockResponse();
68+
$responses = [
69+
new MockResponse((string) $time),
70+
$lastResponse,
71+
];
72+
73+
$transport = $this->createTransport(new MockHttpClient($responses));
74+
$transport->send($smsMessage);
75+
76+
$body = $lastResponse->getRequestOptions()['body'];
77+
$headers = $lastResponse->getRequestOptions()['headers'];
78+
$signature = explode(': ', $headers[4])[1];
79+
80+
$endpoint = 'https://eu.api.ovh.com/1.0/sms/serviceName/jobs';
81+
$toSign = 'applicationSecret+consumerKey+POST+'.$endpoint.'+'.$body.'+'.$time;
82+
$this->assertSame('$1$'.sha1($toSign), $signature);
83+
}
4784
}

0 commit comments

Comments
 (0)
0