Skip to content

Commit 6315335

Browse files
committed
Adds support for mutual TLS
1 parent 275cae5 commit 6315335

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

src/CallWebhookJob.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ class CallWebhookJob implements ShouldQueue
3333

3434
public int $requestTimeout;
3535

36+
public ?string $cert = null;
37+
38+
public ?string $certPassword = null;
39+
40+
public ?string $sslKey = null;
41+
42+
public ?string $sslKeyPassword = null;
43+
3644
public string $backoffStrategyClass;
3745

3846
public ?string $signerClass = null;
@@ -132,14 +140,20 @@ protected function createRequest(array $body): Response
132140
{
133141
$client = $this->getClient();
134142

135-
return $client->request($this->httpVerb, $this->webhookUrl, array_merge([
143+
return $client->request($this->httpVerb, $this->webhookUrl, array_merge(
144+
[
136145
'timeout' => $this->requestTimeout,
137146
'verify' => $this->verifySsl,
138147
'headers' => $this->headers,
139148
'on_stats' => function (TransferStats $stats) {
140149
$this->transferStats = $stats;
141150
},
142-
], $body, is_null($this->proxy) ? [] : ['proxy' => $this->proxy]));
151+
],
152+
$body,
153+
is_null($this->proxy) ? [] : ['proxy' => $this->proxy],
154+
is_null($this->cert) ? [] : ['cert' => [$this->cert, $this->certPassword]],
155+
is_null($this->sslKey) ? [] : ['ssl_key' => [$this->sslKey, $this->sslKeyPassword]]
156+
));
143157
}
144158

145159
protected function shouldBeRemovedFromQueue(): bool

src/WebhookCall.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ public function maximumTries(int $tries): self
117117
return $this;
118118
}
119119

120+
public function mutualTls(string $cert, string $sslKey, ?string $certPassword = null, ?string $sslKeyPassword = null): self
121+
{
122+
$this->callWebhookJob->cert = $cert;
123+
$this->callWebhookJob->certPassword = $certPassword;
124+
$this->callWebhookJob->sslKey = $sslKey;
125+
$this->callWebhookJob->sslKeyPassword = $sslKeyPassword;
126+
127+
return $this;
128+
}
129+
120130
public function useBackoffStrategy(string $backoffStrategyClass): self
121131
{
122132
if (! is_subclass_of($backoffStrategyClass, BackoffStrategy::class)) {

tests/CallWebhookJobTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,40 @@ function baseGetRequest(array $overrides = []): array
184184
->assertRequestsMade([$baseRequest]);
185185
});
186186

187+
it('will use mutual TLS without passphrases', function () {
188+
baseWebhook()
189+
->mutualTls('foobar', 'barfoo')
190+
->dispatch();
191+
192+
$baseRequest = baseRequest();
193+
194+
$baseRequest['options']['cert'] = ['foobar', null];
195+
$baseRequest['options']['ssl_key'] = ['barfoo', null];
196+
197+
artisan('queue:work --once');
198+
199+
$this
200+
->testClient
201+
->assertRequestsMade([$baseRequest]);
202+
});
203+
204+
it('will use mutual TLS with passphrases', function () {
205+
baseWebhook()
206+
->mutualTls('foobar', 'barfoo', 'foobarpassword', 'barfoopassword')
207+
->dispatch();
208+
209+
$baseRequest = baseRequest();
210+
211+
$baseRequest['options']['cert'] = ['foobar', 'foobarpassword'];
212+
$baseRequest['options']['ssl_key'] = ['barfoo', 'barfoopassword'];
213+
214+
artisan('queue:work --once');
215+
216+
$this
217+
->testClient
218+
->assertRequestsMade([$baseRequest]);
219+
});
220+
187221
it('will use a proxy', function () {
188222
baseWebhook()
189223
->useProxy('https://proxy.test')

0 commit comments

Comments
 (0)