10000 fix · symfony/symfony@70f5afd · GitHub
[go: up one dir, main page]

Skip to content

Commit 70f5afd

Browse files
committed
fix
1 parent 86e80f0 commit 70f5afd

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/Symfony/Component/Notifier/Bridge/Slack/SlackTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ final class SlackTransport extends AbstractTransport
3636

3737
public function __construct(string $accessToken, string $channel = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
3838
{
39-
if (0 !== strpos($accessToken, 'xox')) {
40-
throw new InvalidArgumentException('A valid Slack token needs to start with "xox". See https://api.slack.com/authentication/token-types for further information.');
39+
if (!\in_array(substr($accessToken, 0, 6), ['xoxb-', 'xoxop-'], true) && 0 !== strpos($accessToken, 'xoxoa-3')) {
40+
throw new InvalidArgumentException('A valid Slack token needs to start with "xoxb-", "xoxp-" or "xoxa-2". See https://api.slack.com/authentication/token-types for further information.');
4141
}
4242

4343
$this->accessToken = $accessToken;

src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testCreateWithDsn()
2424
{
2525
$factory = $this->createFactory();
2626

27-
$transport = $factory->create(Dsn::fromString('slack://xoxTestUser@host.test/?channel=testChannel'));
27+
$transport = $factory->create(Dsn::fromString('slack://xoxb-TestUser@host.test/?channel=testChannel'));
2828

2929
$this->assertSame('slack://host.test?channel=testChannel', (string) $transport);
3030
}
@@ -33,7 +33,7 @@ public function testCreateWithDsnWithoutPath()
3333
{
3434
$factory = $this->createFactory();
3535

36-
$transport = $factory->create(Dsn::fromString('slack://xoxTestUser@host.test?channel=testChannel'));
36+
$transport = $factory->create(Dsn::fromString('slack://xoxb-TestUser@host.test?channel=testChannel'));
3737

3838
$this->assertSame('slack://host.test?channel=testChannel', (string) $transport);
3939
}

src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testToStringContainsProperties()
3232
{
3333
$channel = 'test Channel'; // invalid channel name to test url encoding of the channel
3434

35-
$transport = new SlackTransport('xoxTestToken', $channel, $this->createMock(HttpClientInterface::class));
35+
$transport = new SlackTransport('xoxb-TestToken', $channel, $this->createMock(HttpClientInterface::class));
3636
$transport->setHost('host.test');
3737

3838
$this->assertSame('slack://host.test?channel=test+Channel', (string) $transport);
@@ -41,22 +41,22 @@ public function testToStringContainsProperties()
4141
public function testInstatiatingWithAnInvalidSlackTokenThrowsInvalidArgumentException()
4242
{
4343
$this->expectException(InvalidArgumentException::class);
44-
$this->expectExceptionMessage('A valid Slack token needs to start with "xox". See https://api.slack.com/authentication/token-types for further information.');
44+
$this->expectExceptionMessage('A valid Slack token needs to start with "xoxb-", "xoxp-" or "xoxa-2". See https://api.slack.com/authentication/token-types for further information.');
4545

4646
new SlackTransport('token', 'testChannel', $this->createMock(HttpClientInterface::class));
4747
}
4848

4949
public function testSupportsChatMessage()
5050
{
51-
$transport = new SlackTransport('xoxTestToken', 'testChannel', $this->createMock(HttpClientInterface::class));
51+
$transport = new SlackTransport('xoxb-TestToken', 'testChannel', $this->createMock(HttpClientInterface::class));
5252

5353
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
5454
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
5555
}
5656

5757
public function testSendNonChatMessageThrowsLogicException()
5858
{
59-
$transport = new SlackTransport('xoxTestToken', 'testChannel', $this->createMock(HttpClientInterface::class));
59+
$transport = new SlackTransport('xoxb-TestToken', 'testChannel', $this->createMock(HttpClientInterface::class));
6060

6161
$this->expectException(UnsupportedMessageTypeException::class);
6262

@@ -79,7 +79,7 @@ public function testSendWithEmptyArrayResponseThrows()
7979
return $response;
8080
});
8181

82-
$transport = new SlackTransport('xoxTestToken', 'testChannel', $client);
82+
$transport = new SlackTransport('xoxb-TestToken', 'testChannel', $client);
8383

8484
$transport->send(new ChatMessage('testMessage'));
8585
}
@@ -102,14 +102,14 @@ public function testSendWithErrorResponseThrows()
102102
return $response;
103103
});
104104

105-
$transport = new SlackTransport('xoxTestToken', 'testChannel', $client);
105+
$transport = new SlackTransport('xoxb-TestToken', 'testChannel', $client);
106106

107107
$transport->send(new ChatMessage('testMessage'));
108108
}
109109

110110
public function testSendWithOptions()
111111
{
112-
$token = 'xoxTestToken';
112+
$token = 'xoxb-TestToken';
113113
$channel = 'testChannel';
114114
$message = 'testMessage';
115115

@@ -138,7 +138,7 @@ public function testSendWithOptions()
138138

139139
public function testSendWithNotification()
140140
{
141-
$token = 'xoxTestToken';
141+
$token = 'xoxb-TestToken';
142142
$channel = 'testChannel';
143143
$message = 'testMessage';
144144

@@ -181,14 +181,14 @@ public function testSendWithInvalidOptions()
181181
return $this->createMock(ResponseInterface::class);
182182
});
183183

184-
$transport = new SlackTransport('xoxTestToken', 'testChannel', $client);
184+
$transport = new SlackTransport('xoxb-TestToken', 'testChannel', $client);
185185

186186
$transport->send(new ChatMessage('testMessage', $this->createMock(MessageOptionsInterface::class)));
187187
}
188188

189189
public function testSendWith200ResponseButNotOk()
190190
{
191-
$token = 'xoxTestToken';
191+
$token = 'xoxb-TestToken';
192192
$channel = 'testChannel';
193193
$message = 'testMessage';
194194

0 commit comments

Comments
 (0)
0