|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Notifier\Bridge\OvhCloud\Tests;
|
13 | 13 |
|
| 14 | +use Symfony\Component\HttpClient\MockHttpClient; |
| 15 | +use Symfony\Component\HttpClient\Response\MockResponse; |
14 | 16 | use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransport;
|
15 | 17 | use Symfony\Component\Notifier\Message\ChatMessage;
|
16 | 18 | use Symfony\Component\Notifier\Message\MessageInterface;
|
@@ -44,4 +46,39 @@ public function unsupportedMessagesProvider(): iterable
|
44 | 46 | yield [new ChatMessage('Hello!')];
|
45 | 47 | yield [$this->createMock(MessageInterface::class)];
|
46 | 48 | }
|
| 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 | + } |
47 | 84 | }
|
0 commit comments