Skip to content

Commit

Permalink
Add support for custom CA's
Browse files Browse the repository at this point in the history
  • Loading branch information
jonerickson committed Nov 17, 2023
1 parent 7d2bd74 commit 9fd4678
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ Mutual TLS authentication serves as a robust method for this purpose. Contrary t
mutual TLS requires both the webhook endpoint (acting as the client) and the webhook provider (acting as the server) to authenticate each other.
This is achieved through an exchange of certificates during the TLS handshake, ensuring that both parties confirm each other's identity.

> Note: If you need to include your own certificate authority, pass the certificate path to the `verifySsl()` method.
```php
WebhookCall::create()
->mutualTls(
Expand Down
2 changes: 1 addition & 1 deletion src/CallWebhookJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CallWebhookJob implements ShouldQueue

public array $headers = [];

public bool $verifySsl;
public string|bool $verifySsl;

public bool $throwExceptionOnFailure;

Expand Down
2 changes: 1 addition & 1 deletion src/WebhookCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function withHeaders(array $headers): self
return $this;
}

public function verifySsl(bool $verifySsl = true): self
public function verifySsl(bool|string $verifySsl = true): self
{
$this->callWebhookJob->verifySsl = $verifySsl;

Expand Down
19 changes: 19 additions & 0 deletions tests/CallWebhookJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,25 @@ function baseGetRequest(array $overrides = []): array
->assertRequestsMade([$baseRequest]);
});

it('will use mutual TLS with certificate authority', function () {
baseWebhook()
->mutualTls('foobar', 'barfoo')
->verifySsl('foofoo')
->dispatch();

$baseRequest = baseRequest();

$baseRequest['options']['cert'] = ['foobar', null];
$baseRequest['options']['ssl_key'] = ['barfoo', null];
$baseRequest['options']['verify'] = 'foofoo';

artisan('queue:work --once');

$this
->testClient
->assertRequestsMade([$baseRequest]);
});

it('will use a proxy', function () {
baseWebhook()
->useProxy('https://proxy.test')
Expand Down

0 comments on commit 9fd4678

Please sign in to comment.