Skip to content

Commit eab3ce3

Browse files
committed
Client: throw Exception if empty auth is set
1 parent 40cd184 commit eab3ce3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/HttpClient/Plugin/RequestSignature.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class RequestSignature implements Plugin
2727
*/
2828
public function __construct($token, $secret)
2929
{
30+
if (!$token || !$secret) {
31+
throw new \InvalidArgumentException('$token and $secret must be set');
32+
}
33+
3034
$this->token = $token;
3135
$this->secret = $secret;
3236
}

tests/HttpClient/Plugin/RequestSignatureTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,23 @@ public function testPrefixRequestPathSmoke()
6565

6666
$this->assertNotNull($promise->wait(true)->getHeader('Authorization')[0]);
6767
}
68+
69+
/**
70+
* @dataProvider tokenSecretProvider
71+
*/
72+
public function testMissingTokenOrSecret(string $token, string $secret): void
73+
{
74+
$this->expectException(\InvalidArgumentException::class);
75+
76+
new RequestSignature($token, $secret);
77+
}
78+
79+
public function tokenSecretProvider(): array
80+
{
81+
return [
82+
['', ''],
83+
['token', ''],
84+
['', 'secret'],
85+
];
86+
}
6887
}

0 commit comments

Comments
 (0)