Skip to content

Commit 3050417

Browse files
committed
WIP
Signed-off-by: Nguyen Van Nguyen <[email protected]>
1 parent 0303656 commit 3050417

File tree

2 files changed

+56
-47
lines changed

2 files changed

+56
-47
lines changed

src/Command/SyncKeyCommand.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
)]
4040
final class SyncKeyCommand extends Command
4141
{
42-
const EMAIL_PATTERN = '/([A-Z0-9._%+-])+@[A-Z0-9.-]+\.[A-Z]{2,}/i';
4342
const CONTENT_TYPE = 'application/json; charset=utf-8';
4443
const HTTP_USER_AGENT = 'Webkey-Directory-Client';
4544
const REQUEST_METHOD = 'GET';
@@ -59,14 +58,6 @@ public function __construct(
5958
parent::__construct();
6059
}
6160

62-
public static function extractEmail(string $userId): string
63-
{
64-
if (preg_match(self::EMAIL_PATTERN, $userId, $matches)) {
65-
return $matches[0];
66-
};
67-
return '';
68-
}
69-
7061
/**
7162
* {@inheritdoc}
7263
*/

tests/CommandsTest.php

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,45 +48,63 @@ public function testSynKey()
4848
'Web keys successfully synchronized!', $tester->getDisplay()
4949
);
5050

51-
// $certs = json_decode(file_get_contents($url));
52-
// $fpStorage = $this->container->get('vks.storage.fingerprint');
53-
// $keyidStorage = $this->container->get('vks.storage.keyid');
54-
// $emailStorage = $this->container->get('vks.storage.email');
55-
// $wkdStorage = $this->container->get('wkd.storage');
56-
// foreach ($certs as $cert) {
57-
// $this->assertTrue(
58-
// file_exists(implode([
59-
// $fpStorage,
60-
// DIRECTORY_SEPARATOR,
61-
// strtolower($cert->fingerprint),
62-
// ]))
63-
// );
64-
// $this->assertTrue(
65-
// file_exists(implode([
66-
// $keyidStorage,
67-
// DIRECTORY_SEPARATOR,
68-
// strtolower($cert->key_id),
69-
// ]))
70-
// );
71-
// $this->assertTrue(
72-
// file_exists(implode([
73-
// $wkdStorage,
74-
// DIRECTORY_SEPARATOR,
75-
// $cert->domain,
76-
// DIRECTORY_SEPARATOR,
77-
// $cert->wkd_hash,
78-
// ]))
79-
// );
51+
if ($directory = json_decode(file_get_contents($url), true)) {
52+
if (!empty($byFingerprints = $directory['fingerprint'] ?? [])) {
53+
$storage = $this->container->get('vks.storage.fingerprint');
54+
foreach ($byFingerprints as $fingerprint => $keyData) {
55+
$this->assertTrue(
56+
file_exists(implode([
57+
$storage,
58+
DIRECTORY_SEPARATOR,
59+
strtolower($fingerprint),
60+
]))
61+
);
62+
}
63+
}
8064

81-
// $email = SyncKeyCommand::extractEmail($cert->primary_user);
82-
// $this->assertTrue(
83-
// file_exists(implode([
84-
// $emailStorage,
85-
// DIRECTORY_SEPARATOR,
86-
// $email,
87-
// ]))
88-
// );
89-
// }
65+
if (!empty($byKeyIDs = $directory['keyid'] ?? [])) {
66+
$storage = $this->container->get('vks.storage.keyid');
67+
foreach ($byKeyIDs as $keyID => $keyData) {
68+
$this->assertTrue(
69+
file_exists(implode([
70+
$storage,
71+
DIRECTORY_SEPARATOR,
72+
strtolower($keyID),
73+
]))
74+
);
75+
}
76+
}
77+
78+
if (!empty($byEmails = $directory['email'] ?? [])) {
79+
$storage = $this->container->get('vks.storage.email');
80+
foreach ($byEmails as $email => $keyData) {
81+
$this->assertTrue(
82+
file_exists(implode([
83+
$storage,
84+
DIRECTORY_SEPARATOR,
85+
$email,
86+
]))
87+
);
88+
}
89+
}
90+
91+
if (!empty($byDomains = $directory['domain'] ?? [])) {
92+
$storage = $this->container->get('wkd.storage');
93+
foreach ($byDomains as $domain => $wkdHashs) {
94+
foreach ($wkdHashs as $hash => $keyData) {
95+
$this->assertTrue(
96+
file_exists(implode([
97+
$storage,
98+
DIRECTORY_SEPARATOR,
99+
$domain,
100+
DIRECTORY_SEPARATOR,
101+
$hash,
102+
]))
103+
);
104+
}
105+
}
106+
}
107+
}
90108

91109
$server->stop();
92110
}

0 commit comments

Comments
 (0)