@@ -552,59 +552,80 @@ public function testCorpus($schemaMap = true)
552
552
553
553
/**
554
554
* Prose test: Custom Endpoint
555
+ *
556
+ * @dataProvider customEndpointProvider
555
557
*/
556
- public function testCustomEndpoint ()
558
+ public function testCustomEndpoint (Closure $ test )
557
559
{
558
- // Test 1
559
560
$ client = new Client (static ::getUri ());
560
561
561
- $ encryptionOpts = [
562
+ $ clientEncryption = $ client -> createClientEncryption ( [
562
563
'keyVaultNamespace ' => 'keyvault.datakeys ' ,
563
564
'kmsProviders ' => [
564
565
'aws ' => Context::getAWSCredentials (),
566
+ 'azure ' => Context::getAzureCredentials () + ['identityPlatformEndpoint ' => 'login.microsoftonline.com:443 ' ],
567
+ 'gcp ' => Context::getGCPCredentials () + ['endpoint ' => 'oauth2.googleapis.com:443 ' ],
565
568
],
566
- ];
567
-
568
- $ clientEncryption = $ client ->createClientEncryption ($ encryptionOpts );
569
-
570
- // Test 2
571
- $ masterKeyConfig = ['region ' => 'us-east-1 ' , 'key ' => 'arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0 ' ];
572
- $ keyId = $ clientEncryption ->createDataKey ('aws ' , ['masterKey ' => $ masterKeyConfig ]);
573
- $ encrypted = $ clientEncryption ->encrypt ('test ' , ['algorithm ' => ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC , 'keyId ' => $ keyId ]);
574
- $ this ->assertSame ('test ' , $ clientEncryption ->decrypt ($ encrypted ));
575
-
576
- // Test 3
577
- $ keyId = $ clientEncryption ->createDataKey ('aws ' , ['masterKey ' => $ masterKeyConfig + ['endpoint ' => 'kms.us-east-1.amazonaws.com ' ]]);
578
- $ encrypted = $ clientEncryption ->encrypt ('test ' , ['algorithm ' => ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC , 'keyId ' => $ keyId ]);
579
- $ this ->assertSame ('test ' , $ clientEncryption ->decrypt ($ encrypted ));
569
+ ]);
580
570
581
- // Test 4
582
- $ keyId = $ clientEncryption ->createDataKey ('aws ' , ['masterKey ' => $ masterKeyConfig + [ 'endpoint ' => 'kms.us-east-1.amazonaws.com:443 ' ]]);
583
- $ encrypted = $ clientEncryption ->encrypt ('test ' , ['algorithm ' => ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC , 'keyId ' => $ keyId ]);
584
- $ this ->assertSame ('test ' , $ clientEncryption ->decrypt ($ encrypted ));
571
+ $ clientEncryptionInvalid = $ client ->createClientEncryption ([
572
+ 'keyVaultNamespace ' => 'keyvault.datakeys ' ,
573
+ 'kmsProviders ' => [
574
+ 'azure ' => Context::getAzureCredentials () + ['identityPlatformEndpoint ' => 'example.com:443 ' ],
575
+ 'gcp ' => Context::getGCPCredentials () + ['endpoint ' => 'example.com:443 ' ],
576
+ ],
577
+ ]);
585
578
586
- // Test 5
587
- try {
588
- $ clientEncryption ->createDataKey ('aws ' , ['masterKey ' => $ masterKeyConfig + [ 'endpoint ' => 'kms.us-east-1.amazonaws.com:12345 ' ]]);
589
- $ this ->fail ('Expected exception to be thrown ' );
590
- } catch (ConnectionException $ e ) {
591
- }
579
+ $ test ($ this , $ clientEncryption , $ clientEncryptionInvalid );
580
+ }
592
581
593
- // Test 6
594
- try {
595
- $ clientEncryption ->createDataKey ('aws ' , ['masterKey ' => $ masterKeyConfig + [ 'endpoint ' => 'kms.us-east-2.amazonaws.com ' ]]);
596
- $ this ->fail ('Expected exception to be thrown ' );
597
- } catch (RuntimeException $ e ) {
598
- $ this ->assertStringContainsString ('us-east-1 ' , $ e ->getMessage ());
599
- }
582
+ public static function customEndpointProvider ()
583
+ {
584
+ $ awsMasterKey = ['region ' => 'us-east-1 ' , 'key ' => 'arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0 ' ];
600
585
601
- // Test 7
602
- try {
603
- $ clientEncryption ->createDataKey ('aws ' , ['masterKey ' => $ masterKeyConfig + [ 'endpoint ' => 'example.com ' ]]);
604
- $ this ->fail ('Expected exception to be thrown ' );
605
- } catch (RuntimeException $ e ) {
606
- $ this ->assertStringContainsString ('parse error ' , $ e ->getMessage ());
607
- }
586
+ return [
587
+ 'Test 1 ' => [
588
+ static function (self $ test , ClientEncryption $ clientEncryption , ClientEncryption $ clientEncryptionInvalid ) use ($ awsMasterKey ) {
589
+ $ keyId = $ clientEncryption ->createDataKey ('aws ' , ['masterKey ' => $ awsMasterKey ]);
590
+ $ encrypted = $ clientEncryption ->encrypt ('test ' , ['algorithm ' => ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC , 'keyId ' => $ keyId ]);
591
+ $ test ->assertSame ('test ' , $ clientEncryption ->decrypt ($ encrypted ));
592
+ },
593
+ ],
594
+ 'Test 2 ' => [
595
+ static function (self $ test , ClientEncryption $ clientEncryption , ClientEncryption $ clientEncryptionInvalid ) use ($ awsMasterKey ) {
596
+ $ keyId = $ clientEncryption ->createDataKey ('aws ' , ['masterKey ' => $ awsMasterKey + ['endpoint ' => 'kms.us-east-1.amazonaws.com ' ]]);
597
+ $ encrypted = $ clientEncryption ->encrypt ('test ' , ['algorithm ' => ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC , 'keyId ' => $ keyId ]);
598
+ $ test ->assertSame ('test ' , $ clientEncryption ->decrypt ($ encrypted ));
599
+ },
600
+ ],
601
+ 'Test 3 ' => [
602
+ static function (self $ test , ClientEncryption $ clientEncryption , ClientEncryption $ clientEncryptionInvalid ) use ($ awsMasterKey ) {
603
+ $ keyId = $ clientEncryption ->createDataKey ('aws ' , ['masterKey ' => $ awsMasterKey + [ 'endpoint ' => 'kms.us-east-1.amazonaws.com:443 ' ]]);
604
+ $ encrypted = $ clientEncryption ->encrypt ('test ' , ['algorithm ' => ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC , 'keyId ' => $ keyId ]);
605
+ $ test ->assertSame ('test ' , $ clientEncryption ->decrypt ($ encrypted ));
606
+ },
607
+ ],
608
+ 'Test 4 ' => [
609
+ static function (self $ test , ClientEncryption $ clientEncryption , ClientEncryption $ clientEncryptionInvalid ) use ($ awsMasterKey ) {
610
+ $ test ->expectException (ConnectionException::class);
611
+ $ clientEncryption ->createDataKey ('aws ' , ['masterKey ' => $ awsMasterKey + ['endpoint ' => 'kms.us-east-1.amazonaws.com:12345 ' ]]);
612
+ },
613
+ ],
614
+ 'Test 5 ' => [
615
+ static function (self $ test , ClientEncryption $ clientEncryption , ClientEncryption $ clientEncryptionInvalid ) use ($ awsMasterKey ) {
616
+ $ test ->expectException (RuntimeException::class);
617
+ $ test ->expectExceptionMessageMatches ('#us-east-1# ' );
618
+ $ clientEncryption ->createDataKey ('aws ' , ['masterKey ' => $ awsMasterKey + ['endpoint ' => 'kms.us-east-2.amazonaws.com ' ]]);
619
+ },
620
+ ],
621
+ 'Test 6 ' => [
622
+ static function (self $ test , ClientEncryption $ clientEncryption , ClientEncryption $ clientEncryptionInvalid ) use ($ awsMasterKey ) {
623
+ $ test ->expectException (RuntimeException::class);
624
+ $ test ->expectExceptionMessageMatches ('#parse error# ' );
625
+ $ clientEncryption ->createDataKey ('aws ' , ['masterKey ' => $ awsMasterKey + ['endpoint ' => 'example.com ' ]]);
626
+ },
627
+ ],
628
+ ];
608
629
}
609
630
610
631
/**
0 commit comments