Skip to content

Commit

Permalink
Remove old properties from gateway payload as well as authentication …
Browse files Browse the repository at this point in the history
…when getting the gateway address
  • Loading branch information
codyphobe committed Jun 9, 2019
1 parent a691cf4 commit 586e3bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
10 changes: 1 addition & 9 deletions src/Commands/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,10 @@ public function handle()
'op' => 2,
'd' => [
'token' => $this->token,
'v' => 3,
'compress' => false,
'properties' => [
'$os' => PHP_OS,
'$browser' => 'laravel-notification-channels-discord',
'$device' => 'laravel-notification-channels-discord',
'$referrer' => '',
'$referring_domain' => '',
],
],
]));
Expand Down Expand Up @@ -132,11 +128,7 @@ public function getGateway()
$gateway = $this->gateway;

try {
$response = $this->guzzle->get('https://discordapp.com/api/gateway', [
'headers' => [
'Authorization' => 'Bot '.$this->token,
],
]);
$response = $this->guzzle->get('https://discordapp.com/api/gateway');

$gateway = Arr::get(json_decode($response->getBody(), true), 'url', $gateway);
} catch (Exception $e) {
Expand Down
20 changes: 2 additions & 18 deletions tests/SetupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ public function it_fetches_the_websocket_gateway_url()
{
$http = Mockery::mock(HttpClient::class);

$http->shouldReceive('get')->with('https://discordapp.com/api/gateway', [
'headers' => [
'Authorization' => 'Bot my-token',
],
])->once()->andReturn(new Response(200, [], json_encode(['url' => 'wss://test-gateway.discord.gg'])));
$http->shouldReceive('get')->with('https://discordapp.com/api/gateway')->once()->andReturn(new Response(200, [], json_encode(['url' => 'wss://test-gateway.discord.gg'])));

$command = new SetupCommand($http, 'my-token');

Expand All @@ -77,11 +73,7 @@ public function it_returns_a_default_websocket_gateway_url()
{
$http = Mockery::mock(HttpClient::class);

$http->shouldReceive('get')->with('https://discordapp.com/api/gateway', [
'headers' => [
'Authorization' => 'Bot my-token',
],
])->once()->andThrow(new RequestException('Not found', Mockery::mock(Request::class), new Response(404, [], json_encode(['message' => 'Not found']))));
$http->shouldReceive('get')->with('https://discordapp.com/api/gateway')->once()->andThrow(new RequestException('Not found', Mockery::mock(Request::class), new Response(404, [], json_encode(['message' => 'Not found']))));

$command = Mockery::mock(SetupCommand::class.'[warn]', [$http, 'my-token']);

Expand All @@ -102,14 +94,10 @@ public function it_connects_to_the_discord_gateway()
'op' => 2,
'd' => [
'token' => 'my-token',
'v' => 3,
'compress' => false,
'properties' => [
'$os' => PHP_OS,
'$browser' => 'laravel-notification-channels-discord',
'$device' => 'laravel-notification-channels-discord',
'$referrer' => '',
'$referring_domain' => '',
],
],
]))->once();
Expand Down Expand Up @@ -137,14 +125,10 @@ public function it_notifies_the_user_of_a_failed_identification_attempt()
'op' => 2,
'd' => [
'token' => 'my-token',
'v' => 3,
'compress' => false,
'properties' => [
'$os' => PHP_OS,
'$browser' => 'laravel-notification-channels-discord',
'$device' => 'laravel-notification-channels-discord',
'$referrer' => '',
'$referring_domain' => '',
],
],
]))->once();
Expand Down

0 comments on commit 586e3bb

Please sign in to comment.