Skip to content

Commit 0fca601

Browse files
feat(api): api update
1 parent 15c6c99 commit 0fca601

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 234
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/increase%2Fincrease-dd0c83cac837fbe98857fa997663b0d0469344a7564bd4fe506e6c71d1d6af73.yml
33
openapi_spec_hash: 2352f37602105b164533038199b21804
4-
config_hash: 890ca5fa6b8209d4eaac90550c7dc62c
4+
config_hash: b7ec7f54fa76c1f8bde7a548710a1d38

src/Services/EventsService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function unwrap(
121121

122122
try {
123123
$flatHeaders = array_map(fn (string|array $v): string => is_array($v) ? $v[0] : $v, $headers);
124-
$webhook = new Webhook($secret);
124+
$webhook = new Webhook('whsec_'.base64_encode($secret));
125125
$webhook->verify($body, $flatHeaders);
126126
} catch (WebhookVerificationException $e) {
127127
throw new WebhookException('Could not verify webhook event signature', previous: $e);

tests/Services/EventsTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function testUnwrapWithVerification(): void
7878
{
7979
$payload = '{"id":"event_001dzz0r20rzr4zrhrr1364hy80","associated_object_id":"account_in71c4amph0vgo2qllky","associated_object_type":"account","category":"account.created","created_at":"2020-01-31T23:59:59Z","type":"event"}';
8080
$secret = 'whsec_c2VjcmV0Cg==';
81+
$rawSecret = "secret\n";
8182
$webhook = new Webhook($secret);
8283
$messageId = '1';
8384
$timestamp = time();
@@ -89,7 +90,7 @@ public function testUnwrapWithVerification(): void
8990
'webhook-id' => [$messageId],
9091
'webhook-timestamp' => [(string) $timestamp],
9192
];
92-
$this->client->events->unwrap($payload, $headers, $secret);
93+
$this->client->events->unwrap($payload, $headers, $rawSecret);
9394
// unwrap successful if not error thrown, increment assertion count to avoid risky test warning
9495
$this->addToAssertionCount(1);
9596
}
@@ -101,6 +102,7 @@ public function testUnwrapWrongKey(): void
101102

102103
$payload = '{"id":"event_001dzz0r20rzr4zrhrr1364hy80","associated_object_id":"account_in71c4amph0vgo2qllky","associated_object_type":"account","category":"account.created","created_at":"2020-01-31T23:59:59Z","type":"event"}';
103104
$secret = 'whsec_c2VjcmV0Cg==';
105+
$rawSecret = "secret\n";
104106
$webhook = new Webhook($secret);
105107
$messageId = '1';
106108
$timestamp = time();
@@ -123,6 +125,7 @@ public function testUnwrapBadSignature(): void
123125

124126
$payload = '{"id":"event_001dzz0r20rzr4zrhrr1364hy80","associated_object_id":"account_in71c4amph0vgo2qllky","associated_object_type":"account","category":"account.created","created_at":"2020-01-31T23:59:59Z","type":"event"}';
125127
$secret = 'whsec_c2VjcmV0Cg==';
128+
$rawSecret = "secret\n";
126129
$webhook = new Webhook($secret);
127130
$messageId = '1';
128131
$timestamp = time();
@@ -134,7 +137,7 @@ public function testUnwrapBadSignature(): void
134137
'webhook-id' => [$messageId],
135138
'webhook-timestamp' => [(string) $timestamp],
136139
];
137-
$this->client->events->unwrap($payload, $headers, $secret);
140+
$this->client->events->unwrap($payload, $headers, $rawSecret);
138141
}
139142

140143
#[Test]
@@ -144,6 +147,7 @@ public function testUnwrapOldTimestamp(): void
144147

145148
$payload = '{"id":"event_001dzz0r20rzr4zrhrr1364hy80","associated_object_id":"account_in71c4amph0vgo2qllky","associated_object_type":"account","category":"account.created","created_at":"2020-01-31T23:59:59Z","type":"event"}';
146149
$secret = 'whsec_c2VjcmV0Cg==';
150+
$rawSecret = "secret\n";
147151
$webhook = new Webhook($secret);
148152
$messageId = '1';
149153
$timestamp = time();
@@ -155,7 +159,7 @@ public function testUnwrapOldTimestamp(): void
155159
'webhook-id' => [$messageId],
156160
'webhook-timestamp' => ['5'],
157161
];
158-
$this->client->events->unwrap($payload, $headers, $secret);
162+
$this->client->events->unwrap($payload, $headers, $rawSecret);
159163
}
160164

161165
#[Test]
@@ -165,6 +169,7 @@ public function testUnwrapWrongMessageID(): void
165169

166170
$payload = '{"id":"event_001dzz0r20rzr4zrhrr1364hy80","associated_object_id":"account_in71c4amph0vgo2qllky","associated_object_type":"account","category":"account.created","created_at":"2020-01-31T23:59:59Z","type":"event"}';
167171
$secret = 'whsec_c2VjcmV0Cg==';
172+
$rawSecret = "secret\n";
168173
$webhook = new Webhook($secret);
169174
$messageId = '1';
170175
$timestamp = time();
@@ -176,6 +181,6 @@ public function testUnwrapWrongMessageID(): void
176181
'webhook-id' => ['wrong'],
177182
'webhook-timestamp' => [(string) $timestamp],
178183
];
179-
$this->client->events->unwrap($payload, $headers, $secret);
184+
$this->client->events->unwrap($payload, $headers, $rawSecret);
180185
}
181186
}

0 commit comments

Comments
 (0)