-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathControllerTest.php
More file actions
76 lines (62 loc) · 4.13 KB
/
ControllerTest.php
File metadata and controls
76 lines (62 loc) · 4.13 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
namespace Mcfedr\QueueManagerBundle\Tests\Controller;
use Google\Auth\AccessToken;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* @internal
*/
final class ControllerTest extends WebTestCase
{
/** @var KernelBrowser */
protected $client;
protected function setUp(): void
{
self::ensureKernelShutdown();
$this->client = static::createClient([], ['HTTPS' => true]);
$this->client->followRedirects(false);
}
/**
* @dataProvider queueDataProvider()
*/
public function testController($queue, $audience): void
{
$accessTokenMock = $this->getMockBuilder(AccessToken::class)->onlyMethods(['verify'])->getMock();
$accessTokenMock->method('verify')->willReturn(['aud' => $audience]);
static::$container->set(AccessToken::class, $accessTokenMock);
$this->client->request('POST', "/pubsub/{$queue}", [], [], ['HTTP_AUTHORIZATION' => 'Bearer token'], '{"message":{"data":"eyJuYW1lIjoid29ya2VyX3dpdGhfYV9uYW1lIiwiYXJndW1lbnRzIjpbeyJmb28iOiAiYmFyIn1dLCJyZXRyeUNvdW50IjowfQ==","messageId":"1748167746376305","message_id":"1748167746376305","publishTime":"2020-11-19T15:10:18.439Z","publish_time":"2020-11-19T15:10:18.439Z"},"subscription":"projects/project/subscriptions/subscriptions"}');
static::assertEquals(200, $this->client->getResponse()->getStatusCode());
}
public function testControllerBadAudience(): void
{
$accessTokenMock = $this->getMockBuilder(AccessToken::class)->onlyMethods(['verify'])->getMock();
$accessTokenMock->method('verify')->willReturn(['aud' => 'audience1']);
static::$container->set(AccessToken::class, $accessTokenMock);
$this->client->request('POST', '/pubsub/default', [], [], ['HTTP_AUTHORIZATION' => 'Bearer token'], '{"message":{"data":"eyJuYW1lIjoid29ya2VyX3dpdGhfYV9uYW1lIiwiYXJndW1lbnRzIjpbeyJmb28iOiAiYmFyIn1dLCJyZXRyeUNvdW50IjowfQ==","messageId":"1748167746376305","message_id":"1748167746376305","publishTime":"2020-11-19T15:10:18.439Z","publish_time":"2020-11-19T15:10:18.439Z"},"subscription":"projects/project/subscriptions/subscriptions"}');
static::assertEquals(403, $this->client->getResponse()->getStatusCode());
}
public function testControllerNoAudienceConfigured(): void
{
$accessTokenMock = $this->getMockBuilder(AccessToken::class)->onlyMethods(['verify'])->getMock();
$accessTokenMock->method('verify')->willReturn(['aud' => 'audience1']);
static::$container->set(AccessToken::class, $accessTokenMock);
$this->client->request('POST', '/pubsub/no_audience_queue', [], [], ['HTTP_AUTHORIZATION' => 'Bearer token'], '{"message":{"data":"eyJuYW1lIjoid29ya2VyX3dpdGhfYV9uYW1lIiwiYXJndW1lbnRzIjpbeyJmb28iOiAiYmFyIn1dLCJyZXRyeUNvdW50IjowfQ==","messageId":"1748167746376305","message_id":"1748167746376305","publishTime":"2020-11-19T15:10:18.439Z","publish_time":"2020-11-19T15:10:18.439Z"},"subscription":"projects/project/subscriptions/subscriptions"}');
static::assertEquals(200, $this->client->getResponse()->getStatusCode());
}
public function testControllerNoAudienceFromPubSub(): void
{
$accessTokenMock = $this->getMockBuilder(AccessToken::class)->onlyMethods(['verify'])->getMock();
$accessTokenMock->method('verify')->willReturn(['aud' => 'https://example.com']);
static::$container->set(AccessToken::class, $accessTokenMock);
$this->client->request('POST', '/pubsub/no_audience_queue', [], [], ['HTTP_AUTHORIZATION' => 'Bearer token'], '{"message":{"data":"eyJuYW1lIjoid29ya2VyX3dpdGhfYV9uYW1lIiwiYXJndW1lbnRzIjpbeyJmb28iOiAiYmFyIn1dLCJyZXRyeUNvdW50IjowfQ==","messageId":"1748167746376305","message_id":"1748167746376305","publishTime":"2020-11-19T15:10:18.439Z","publish_time":"2020-11-19T15:10:18.439Z"},"subscription":"projects/project/subscriptions/subscriptions"}');
static::assertEquals(200, $this->client->getResponse()->getStatusCode());
}
public function queueDataProvider()
{
return [
['default', 'audience'],
['other_queue', 'audience1'],
];
}
}