-
Notifications
You must be signed in to change notification settings - Fork 29
/
exercise-signing-keys.php
56 lines (49 loc) · 2.21 KB
/
exercise-signing-keys.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
require_once(__DIR__ . '/../assert.php');
require_once 'vendor/autoload.php';
// Exercises all signing key operations.
// Authentication Setup
$config = MuxPhp\Configuration::getDefaultConfiguration()
->setUsername(getenv('MUX_TOKEN_ID'))
->setPassword(getenv('MUX_TOKEN_SECRET'));
// API Client Initialization
$keysApi = new MuxPhp\Api\URLSigningKeysApi(
new GuzzleHttp\Client(),
$config
);
// ========== create-url-signing-key ==========
$createKeyResponse = $keysApi->createUrlSigningKey();
assert($createKeyResponse->getData()->getId() !== null);
assert($createKeyResponse->getData()->getPrivateKey() !== null);
print("create-url-signing-key OK ✅\n");
// ========== list-url-signing-keys ==========
$keys = $keysApi->listUrlSigningKeys();
$list = $keys->getData();
$last = end($list);
assert($last->getId() !== null);
assert($last->getId() === $createKeyResponse->getData()->getId());
assert($last->getPrivateKey() === null);
print("list-url-signing-keys OK ✅\n");
// ========== get-url-signing-key ==========
$key = $keysApi->getUrlSigningKey($createKeyResponse->getData()->getId());
assert($key->getData()->getId() !== null);
assert($key->getData()->getId() === $createKeyResponse->getData()->getId());
assert($key->getData()->getPrivateKey() === null);
print("get-url-signing-key OK ✅\n");
// ========== delete-url-signing-key ==========
$keysApi->deleteUrlSigningKey($createKeyResponse->getData()->getId());
try {
print("Sleeping for 60 seconds to ensure key cache is invalidated ⏳");
for ($remaining=60;$remaining>0;--$remaining) {
print("\r");
print(sprintf("%2d seconds remaining. ",$remaining));
flush();
sleep(1);
}
print("\rSleep complete! ⏳ \n");
$result = $keysApi->getUrlSigningKey($createKeyResponse->getData()->getId());
print("Should have 404'd when getting deleted signing key ❌ \n");
exit(1);
} catch (Exception $e) {
print("delete-url-signing-key OK ✅\n");
}