22declare (strict_types=1 );
33namespace FediE2EE \PKDServer \Tests ;
44
5+ use DateMalformedStringException ;
56use FediE2EE \PKD \Crypto \AttributeEncryption \AttributeKeyMap ;
67use FediE2EE \PKD \Crypto \Exceptions \{
8+ BundleException ,
79 CryptoException ,
10+ InputException ,
811 JsonException ,
9- NotImplementedException ,
10- ParserException
12+ NetworkException ,
13+ NotImplementedException
1114};
1215use FediE2EE \PKD \Crypto \Merkle \IncrementalTree ;
1316use FediE2EE \PKD \Crypto \Protocol \{
1417 Actions \AddKey ,
1518 Handler
1619};
20+ use GuzzleHttp \Exception \ConnectException ;
21+ use GuzzleHttp \Exception \GuzzleException ;
22+ use GuzzleHttp \Exception \ServerException ;
1723use ParagonIE \Certainty \Fetch ;
1824use ParagonIE \Certainty \RemoteFetch ;
1925use ParagonIE \HPKE \KEM \PQKEM \EncapsKey ;
26+ use ParagonIE \PQCrypto \Exception \MLDSAInternalException ;
27+ use ParagonIE \PQCrypto \Exception \PQCryptoCompatException ;
2028use FediE2EE \PKD \Crypto \{
2129 SecretKey ,
2230 SymmetricKey
2331};
2432use FediE2EE \PKDServer \Exceptions \{
2533 CacheException ,
34+ ConcurrentException ,
2635 DependencyException ,
2736 ProtocolException ,
2837 TableException
@@ -141,13 +150,14 @@ public function makeDummyActor(string $domain = 'example.com'): array
141150 if (file_exists (PKD_SERVER_ROOT . '/tmp/ca-certs.json ' )) {
142151 $ fetch = new Fetch (PKD_SERVER_ROOT . '/tmp ' );
143152 } else {
144-
145153 $ fetch = new RemoteFetch (PKD_SERVER_ROOT . '/tmp ' );
146154 }
147155 $ wf = new WebFinger (
148156 $ this ->getConfig (),
149157 new Client ([
150- 'verify ' => $ fetch ->getLatestBundle (false , false )->getFilePath ()
158+ 'verify ' => $ fetch
159+ ->getLatestBundle (false , false )
160+ ->getFilePath ()
151161 ]),
152162 $ fetch
153163 );
@@ -307,14 +317,27 @@ public function createWebFingerMock(
307317 /**
308318 * Add a key for an actor via the Protocol class.
309319 *
320+ * @param string $canonical
321+ * @param SecretKey $keypair
322+ * @param Protocol $protocol
323+ * @param ServerConfig $config
324+ * @return ActorKey
325+ * @throws BundleException
310326 * @throws CacheException
327+ * @throws ConcurrentException
311328 * @throws CryptoException
329+ * @throws DateMalformedStringException
312330 * @throws DependencyException
331+ * @throws GuzzleException
313332 * @throws HPKEException
333+ * @throws InputException
314334 * @throws JsonException
335+ * @throws MLDSAInternalException
336+ * @throws NetworkException
315337 * @throws NotImplementedException
316- * @throws ParserException
338+ * @throws PQCryptoCompatException
317339 * @throws ProtocolException
340+ * @throws RandomException
318341 * @throws SodiumException
319342 * @throws TableException
320343 */
@@ -331,14 +354,20 @@ public function addKeyForActor(
331354 $ serverHpke = $ config ->getHPKE ();
332355 $ handler = new Handler ();
333356
334- $ addKey = new AddKey ($ canonical , $ keypair ->getPublicKey ());
357+ try {
358+ $ addKey = new AddKey ($ canonical , $ keypair ->getPublicKey ());
359+ } catch (ServerException |ConnectException $ e ) {
360+ $ this ->markTestSkipped ($ e ->getMessage ());
361+ }
335362 $ akm = new AttributeKeyMap ();
336363 $ akm ->addKey ('actor ' , SymmetricKey::generate ());
337364 $ akm ->addKey ('public-key ' , SymmetricKey::generate ());
338365
339366 $ bundle = $ handler ->handle ($ addKey ->encrypt ($ akm , $ latestRoot ), $ keypair , $ akm , $ latestRoot );
340367 $ this ->assertInstanceOf (EncapsKey::class, $ serverHpke ->encapsKey );
341- $ encrypted = $ handler ->hpkeEncrypt ($ bundle , $ serverHpke ->encapsKey , $ serverHpke ->cs );
368+ /** @var EncapsKey $encapsKey */
369+ $ encapsKey = $ serverHpke ->encapsKey ;
370+ $ encrypted = $ handler ->hpkeEncrypt ($ bundle , $ encapsKey , $ serverHpke ->cs );
342371
343372 return $ protocol ->addKey ($ encrypted , $ canonical );
344373 }
0 commit comments