-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathWebhookTest.php
63 lines (52 loc) · 1.88 KB
/
WebhookTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace unit;
use PHPUnit\Framework\TestCase;
use Pusher\Pusher;
use Pusher\PusherException;
class WebhookTest extends TestCase
{
/**
* @var string
*/
private $auth_key;
/**
* @var Pusher
*/
private $pusher;
protected function setUp(): void
{
$this->auth_key = 'thisisaauthkey';
$this->pusher = new Pusher($this->auth_key, 'thisisasecret', 1);
}
public function testValidWebhookSignature(): void
{
$signature = '40e0ad3b9aa49529322879e84de1aaaf18bde1efe839ca263d540cc865510d25';
$body = '{"hello":"world"}';
$headers = [
'X-Pusher-Key' => $this->auth_key,
'X-Pusher-Signature' => $signature,
];
$this->pusher->ensure_valid_signature($headers, $body);
self::assertTrue(true);
}
public function testInvalidWebhookSignature(): void
{
$this->expectException(PusherException::class);
$signature = 'potato';
$body = '{"hello":"world"}';
$headers = [
'X-Pusher-Key' => $this->auth_key,
'X-Pusher-Signature' => $signature,
];
$this->pusher->ensure_valid_signature($headers, $body);
}
public function testDecodeWebhook(): void
{
$headers_json = '{"X-Pusher-Key":"' . $this->auth_key . '","X-Pusher-Signature":"a19cab2af3ca1029257570395e78d5d675e9e700ca676d18a375a7083178df1c"}';
$body = '{"time_ms":1530710011901,"events":[{"name":"client_event","channel":"private-my-channel","event":"client-event","data":"Unencrypted","socket_id":"240621.35780774"}]}';
$headers = json_decode($headers_json, true, 512, JSON_THROW_ON_ERROR);
$decodedWebhook = $this->pusher->webhook($headers, $body);
self::assertEquals(1530710011901, $decodedWebhook->get_time_ms());
self::assertCount(1, $decodedWebhook->get_events());
}
}