Skip to content

Commit 586e3bb

Browse files
committed
Remove old properties from gateway payload as well as authentication when getting the gateway address
1 parent a691cf4 commit 586e3bb

File tree

2 files changed

+3
-27
lines changed

2 files changed

+3
-27
lines changed

src/Commands/SetupCommand.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,10 @@ public function handle()
8686
'op' => 2,
8787
'd' => [
8888
'token' => $this->token,
89-
'v' => 3,
90-
'compress' => false,
9189
'properties' => [
9290
'$os' => PHP_OS,
9391
'$browser' => 'laravel-notification-channels-discord',
9492
'$device' => 'laravel-notification-channels-discord',
95-
'$referrer' => '',
96-
'$referring_domain' => '',
9793
],
9894
],
9995
]));
@@ -132,11 +128,7 @@ public function getGateway()
132128
$gateway = $this->gateway;
133129

134130
try {
135-
$response = $this->guzzle->get('https://discordapp.com/api/gateway', [
136-
'headers' => [
137-
'Authorization' => 'Bot '.$this->token,
138-
],
139-
]);
131+
$response = $this->guzzle->get('https://discordapp.com/api/gateway');
140132

141133
$gateway = Arr::get(json_decode($response->getBody(), true), 'url', $gateway);
142134
} catch (Exception $e) {

tests/SetupCommandTest.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ public function it_fetches_the_websocket_gateway_url()
5959
{
6060
$http = Mockery::mock(HttpClient::class);
6161

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

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

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

80-
$http->shouldReceive('get')->with('https://discordapp.com/api/gateway', [
81-
'headers' => [
82-
'Authorization' => 'Bot my-token',
83-
],
84-
])->once()->andThrow(new RequestException('Not found', Mockery::mock(Request::class), new Response(404, [], json_encode(['message' => 'Not found']))));
76+
$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']))));
8577

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

@@ -102,14 +94,10 @@ public function it_connects_to_the_discord_gateway()
10294
'op' => 2,
10395
'd' => [
10496
'token' => 'my-token',
105-
'v' => 3,
106-
'compress' => false,
10797
'properties' => [
10898
'$os' => PHP_OS,
10999
'$browser' => 'laravel-notification-channels-discord',
110100
'$device' => 'laravel-notification-channels-discord',
111-
'$referrer' => '',
112-
'$referring_domain' => '',
113101
],
114102
],
115103
]))->once();
@@ -137,14 +125,10 @@ public function it_notifies_the_user_of_a_failed_identification_attempt()
137125
'op' => 2,
138126
'd' => [
139127
'token' => 'my-token',
140-
'v' => 3,
141-
'compress' => false,
142128
'properties' => [
143129
'$os' => PHP_OS,
144130
'$browser' => 'laravel-notification-channels-discord',
145131
'$device' => 'laravel-notification-channels-discord',
146-
'$referrer' => '',
147-
'$referring_domain' => '',
148132
],
149133
],
150134
]))->once();

0 commit comments

Comments
 (0)