Skip to content

Commit 06881ff

Browse files
committed
Corrections on hooks
1 parent 721420c commit 06881ff

File tree

5 files changed

+55
-33
lines changed

5 files changed

+55
-33
lines changed

src/Parameters/HooksDestroyParameters.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222

2323
class HooksDestroyParameters extends BaseParameters
2424
{
25-
private ?string $hookId = null;
25+
private int $hookId;
2626

27-
public function __construct(string $hookId = null)
27+
public function __construct(int $hookId)
2828
{
2929
$this->hookId = $hookId;
3030
}
3131

32-
public function getHookId(): ?string
32+
public function getHookId(): int
3333
{
3434
return $this->hookId;
3535
}
3636

37-
public function setHookId(string $hookId): self
37+
public function setHookId(int $hookId): self
3838
{
3939
$this->hookId = $hookId;
4040

src/Responses/HooksCreateResponse.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
*/
2626
class HooksCreateResponse extends BaseResponse
2727
{
28+
/**
29+
* According to documentation the hookId that needs to be used in the "destroy" command musst be of type number.
30+
* That is why the return here must be a number (= integer) too.
31+
*
32+
* But in the same time this property could be not part of the API-response in case the response failed. So it has
33+
* to return NULL as well.
34+
*
35+
* @see https://docs.bigbluebutton.org/development/webhooks/#hooksdestroy
36+
*/
2837
public function getHookId(): ?int
2938
{
3039
if (!$this->rawXml->hookID) {

src/Util/UrlBuilder.php

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,11 @@ class UrlBuilder
4848

4949
private string $bbbServerBaseUrl;
5050

51-
/** @deprecated This property will disappear after a while */
52-
private string $hashAlgoForHooks;
53-
5451
public function __construct(string $secret, string $serverBaseUrl, string $hashingAlgorithm)
5552
{
5653
$this->securitySalt = $secret;
5754
$this->bbbServerBaseUrl = $serverBaseUrl;
5855
$this->hashingAlgorithm = $hashingAlgorithm;
59-
60-
$this->initiateAlgorithmForHooks();
6156
}
6257

6358
/**
@@ -163,14 +158,17 @@ public function getPutRecordingTextTrackUrl(PutRecordingTextTrackParameters $put
163158
*/
164159
public function getHooksCreateUrl(HooksCreateParameters $hookCreateParams): string
165160
{
161+
// store current hashing algorithm
162+
$hashingAlgorithm = $this->getHashingAlgorithm();
163+
166164
// change hashing algorithm for hooks
167-
$this->setHashingAlgorithm($this->hashAlgoForHooks);
165+
$this->setHashingAlgorithm($this->getHashingAlgorithmForHooks());
168166

169167
// build URL
170168
$url = $this->buildUrl(ApiMethod::HOOKS_CREATE, $hookCreateParams->getHTTPQuery());
171169

172170
// reset to 'normal' hashing algorithm
173-
$this->setHashingAlgorithm($this->getHashingAlgorithm());
171+
$this->setHashingAlgorithm($hashingAlgorithm);
174172

175173
return $url;
176174
}
@@ -183,14 +181,17 @@ public function getHooksCreateUrl(HooksCreateParameters $hookCreateParams): stri
183181
*/
184182
public function getHooksListUrl(): string
185183
{
184+
// store current hashing algorithm
185+
$hashingAlgorithm = $this->getHashingAlgorithm();
186+
186187
// change hashing algorithm for hooks
187-
$this->setHashingAlgorithm($this->hashAlgoForHooks);
188+
$this->setHashingAlgorithm($this->getHashingAlgorithmForHooks());
188189

189190
// build URL
190191
$url = $this->buildUrl(ApiMethod::HOOKS_LIST);
191192

192193
// reset to 'normal' hashing algorithm
193-
$this->setHashingAlgorithm($this->getHashingAlgorithm());
194+
$this->setHashingAlgorithm($hashingAlgorithm);
194195

195196
return $url;
196197
}
@@ -203,46 +204,56 @@ public function getHooksListUrl(): string
203204
*/
204205
public function getHooksDestroyUrl(HooksDestroyParameters $hooksDestroyParams): string
205206
{
207+
// store current hashing algorithm
208+
$hashingAlgorithm = $this->getHashingAlgorithm();
209+
206210
// change hashing algorithm for hooks
207-
$this->setHashingAlgorithm($this->hashAlgoForHooks);
211+
$this->setHashingAlgorithm($this->getHashingAlgorithmForHooks());
208212

209213
// build URL
210214
$url = $this->buildUrl(ApiMethod::HOOKS_DESTROY, $hooksDestroyParams->getHTTPQuery());
211215

212216
// reset to 'normal' hashing algorithm
213-
$this->setHashingAlgorithm($this->getHashingAlgorithm());
217+
$this->setHashingAlgorithm($hashingAlgorithm);
214218

215219
return $url;
216220
}
217221

218222
/**
219-
* Defines the algorithm to be used for hooks.
220-
*
221-
* Background: BBB-Server below 3.0 are using SHA1-algorithm for hooks. The current planning for
222-
* BBB-Server 3.0 (and on) is to align the hashing algorithm for hooks with the rest
223-
* of the system. Having this in mind the two situations need to be covered:
224-
* - BBB-Server < 3.0 ==> SHA1 is default for hooks (even rest is using other algorithm)
225-
* - BBB-Server >= 3.0 ==> same algorithm everywhere (according to planning).
223+
* This function defines the algorithm to be used for hooks.
226224
*
227225
* This function will evolve in phases:
228-
* - Phase 1: SHA1 as default (or superseded by environment-variable HASH_ALGO_FOR_HOOKS).
229-
* - Phase 2: same algo everywhere as default (or superseded by environment-variable HASH_ALGO_FOR_HOOKS and which will trigger in this case a deprecation-warning).
230-
* - Phase 3: removal of this function, the class-property '$hashAlgoForHooks' and the use of env-variable HASH_ALGO_FOR_HOOKS.
226+
* - Phase 1: SHA1 as default (or superseded by environment-variable HASH_ALGO_FOR_HOOKS).
227+
* - Phase 2: same algo everywhere as default (or superseded by environment-variable HASH_ALGO_FOR_HOOKS and which will trigger in this case a deprecation-warning).
228+
* - Phase 3: removal of this function, adaptation of the other hook-functions in this class and remove the use of env-variable HASH_ALGO_FOR_HOOKS.
229+
*
230+
* Background:
231+
* BB-Server below 3.0 are using SHA1-algorithm for hooks only, but allow higher algorithms for
232+
* other APIs. This is creating issues since the algorithm of choice is used in the urlBuilder-class
233+
* for the hashing of the checksum. This is resulting in denied requests for hooks if the algorithm
234+
* of choice is not SHA1.
235+
* The current planning for BBB-Server 3.0 (and on) is to align the hashing algorithm for hooks with
236+
* the rest of the system. Having this in mind two situations need to be covered:
237+
* - BBB-Server < 3.0 ==> SHA1 is default for hooks (even rest is using other algorithm)
238+
* - BBB-Server >= 3.0 ==> same algorithm everywhere (according to planning).
231239
*
232240
* @deprecated This function will evolve in phases and will later disappear
233241
*/
234-
private function initiateAlgorithmForHooks(): void
242+
private function getHashingAlgorithmForHooks(): string
235243
{
244+
// ---------------------------------- phase 1 ----------------------------------
236245
// in case this env-variable is not set, SHA1 shall be used as default (phase 1)
237-
$this->hashAlgoForHooks = getenv('HASH_ALGO_FOR_HOOKS') ?: HashingAlgorithm::SHA_1;
246+
return getenv('HASH_ALGO_FOR_HOOKS') ?: HashingAlgorithm::SHA_1;
247+
// ---------------------------------- phase 1 ----------------------------------
238248

239249
/* ---------------------------------- phase 2 ----------------------------------
240-
* // in case this env-variable is not set, the 'normal' algorithm shall be used as default (phase 2)
241-
* $this->hashAlgoForHooks = getenv('HASH_ALGO_FOR_HOOKS') ?: $this->getHashingAlgorithm();
242-
*
243250
* if (getenv('HASH_ALGO_FOR_HOOKS')) {
244251
* trigger_error('The environment variable HASH_ALGO_FOR_HOOKS will be removed soon. This will require you to run a BBB-Server 3.0 or higher!', E_USER_DEPRECATED);
245252
* }
253+
*
254+
* // in case this env-variable is not set, the 'normal' algorithm shall be used as default (phase 2)
255+
* return getenv('HASH_ALGO_FOR_HOOKS') ?: $this->getHashingAlgorithm();
256+
*
246257
* ---------------------------------- phase 2 ---------------------------------- */
247258
}
248259
}

tests/BigBlueButtonTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,16 @@ public function testHooksDestroy(): void
408408
$hooksCreateParameters = new HooksCreateParameters($this->faker->url);
409409
$hooksCreateResponse = $this->bbb->hooksCreate($hooksCreateParameters);
410410
$this->assertTrue($hooksCreateResponse->success(), $hooksCreateResponse->getMessage());
411+
$hookId = $hooksCreateResponse->getHookId();
412+
$this->assertNotNull($hookId);
411413

412414
// destroy existing hook
413-
$hooksDestroyParameters = new HooksDestroyParameters($hooksCreateResponse->getHookId());
415+
$hooksDestroyParameters = new HooksDestroyParameters($hookId);
414416
$hooksCreateResponse = $this->bbb->hooksDestroy($hooksDestroyParameters);
415417
$this->assertTrue($hooksCreateResponse->success(), $hooksCreateResponse->getMessage());
416418

417419
// destroy non-existing hook
418-
$hooksDestroyParameters = new HooksDestroyParameters($this->faker->uuid);
420+
$hooksDestroyParameters = new HooksDestroyParameters($this->faker->numberBetween(10000, 99999));
419421
$hooksCreateResponse = $this->bbb->hooksDestroy($hooksDestroyParameters);
420422
$this->assertFalse($hooksCreateResponse->success(), $hooksCreateResponse->getMessage());
421423
}

tests/Parameters/HooksDestroyParametersTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class HooksDestroyParametersTest extends TestCase
3131
{
3232
public function testHooksDestroyParameters(): void
3333
{
34-
$hookId = (string) $this->faker->numberBetween(1, 50);
34+
$hookId = $this->faker->numberBetween(1, 50);
3535

3636
$hooksDestroyParameters = new HooksDestroyParameters($hookId);
3737

0 commit comments

Comments
 (0)