Skip to content

Commit 8e8364f

Browse files
authored
PHPLIB-866: CSFLE prose test for on-demand AWS credentials (#1009)
1 parent 36223ef commit 8e8364f

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

.evergreen/config.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,18 @@ tasks:
598598
SKIP_CRYPT_SHARED: "yes"
599599
TESTS: "csfle"
600600

601+
- name: "test-without_aws_credentials"
602+
commands:
603+
- func: "bootstrap mongo-orchestration"
604+
vars:
605+
TOPOLOGY: "replica_set"
606+
- func: "start kms servers"
607+
- func: "run tests"
608+
vars:
609+
client_side_encryption_aws_access_key_id: ""
610+
client_side_encryption_aws_secret_access_key: ""
611+
TESTS: "csfle"
612+
601613
# }}}
602614

603615

@@ -863,3 +875,10 @@ buildvariants:
863875
display_name: "CSFLE skip_crypt_shared - ${mongodb-versions}"
864876
tasks:
865877
- name: "test-skip_crypt_shared"
878+
879+
# Run CSFLE tests without AWS credentials (for "On-demand AWS Credentials" prose test)
880+
- matrix_name: "test-csfle-without_aws_credentials"
881+
matrix_spec: { "os": "debian11", "mongodb-versions": "6.0", "php-edge-versions": "latest-stable", "driver-versions": "latest-stable" }
882+
display_name: "CSFLE without_aws_credentials - ${mongodb-versions}"
883+
tasks:
884+
- name: "test-without_aws_credentials"

tests/SpecTests/ClientSideEncryptionSpecTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,48 @@ static function (self $test, Client $setupClient, ClientEncryption $clientEncryp
16421642
];
16431643
}
16441644

1645+
/**
1646+
* Prose test 15: On-demand AWS Credentials
1647+
*
1648+
* @see https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#on-demand-aws-credentials
1649+
* @testWith [true]
1650+
* [false]
1651+
*/
1652+
public function testOnDemandAwsCredentials(bool $shouldSucceed): void
1653+
{
1654+
$hasCredentials = (getenv('AWS_ACCESS_KEY_ID') && getenv('AWS_SECRET_ACCESS_KEY'));
1655+
1656+
if ($hasCredentials !== $shouldSucceed) {
1657+
Assert::markTestSkipped(sprintf('AWS credentials %s available', $hasCredentials ? 'are' : 'are not'));
1658+
}
1659+
1660+
$keyVaultClient = static::createTestClient();
1661+
1662+
$clientEncryption = new ClientEncryption([
1663+
'keyVaultClient' => $keyVaultClient->getManager(),
1664+
'keyVaultNamespace' => 'keyvault.datakeys',
1665+
'kmsProviders' => ['aws' => (object) []],
1666+
]);
1667+
1668+
$dataKeyOpts = [
1669+
'masterKey' => [
1670+
'region' => 'us-east-1',
1671+
'key' => 'arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0',
1672+
],
1673+
];
1674+
1675+
if (! $shouldSucceed) {
1676+
$this->expectException(AuthenticationException::class);
1677+
}
1678+
1679+
$dataKeyId = $clientEncryption->createDataKey('aws', $dataKeyOpts);
1680+
1681+
if ($shouldSucceed) {
1682+
$this->assertInstanceOf(Binary::class, $dataKeyId);
1683+
$this->assertSame(Binary::TYPE_UUID, $dataKeyId->getType());
1684+
}
1685+
}
1686+
16451687
/**
16461688
* Prose test 16: RewrapManyDataKey
16471689
*

0 commit comments

Comments
 (0)