Skip to content

PHPC-2395: Fetch Atlas connectivity URIs from AWS Secrets Manager #1579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .evergreen/config/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ functions:
params:
include_expansions_in_env:
- API_VERSION
- ATLAS_CONNECTIVITY_URIS
- CRYPT_SHARED_LIB_PATH
- MONGODB_URI
- APPEND_URI
Expand Down
8 changes: 8 additions & 0 deletions .evergreen/config/test-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ tasks:
- name: "test-atlas-connectivity"
tags: ["atlas", "nodb"]
commands:
# This creates secrets-export.sh, which is later sourced by run-tests.sh
- command: subprocess.exec
params:
working_dir: "src"
binary: bash
args:
- -c
- ${DRIVERS_TOOLS}/.evergreen/secrets_handling/setup-secrets.sh drivers/atlas_connect
- func: "run tests"
vars:
TESTS: "tests/atlas.phpt"
Expand Down
5 changes: 5 additions & 0 deletions .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ else
echo "crypt_shared library will be loaded from path: $CRYPT_SHARED_LIB_PATH"
fi

# Conditionally source setup-secrets.sh created by drivers-evergreen-tools
if [ -f "${PROJECT_DIRECTORY}/secrets-export.sh" ]; then
source ${PROJECT_DIRECTORY}/secrets-export.sh
fi

echo "Running tests with URI: $MONGODB_URI"

# Run the tests, and store the results in a junit result file
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ mongodb-*tgz

# Coverage files
coverage*

# drivers-evergreen-tools secrets handling
secrets-export.sh
60 changes: 34 additions & 26 deletions tests/atlas.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,40 @@
Atlas Connectivity Tests
--SKIPIF--
<?php require __DIR__ . "/utils/basic-skipif.inc"; ?>
<?php skip_if_no_atlas_connectivity_urls(); ?>
<?php if (getenv('TESTS') !== 'tests/atlas.phpt') { die('skip Atlas tests not wanted'); } ?>
--FILE--
<?php
require_once __DIR__ . "/utils/basic.inc";

$envs = [
'ATLAS_SERVERLESS',
'ATLAS_SRV_SERVERLESS',
'ATLAS_FREE',
'ATLAS_SRV_FREE',
'ATLAS_REPL',
'ATLAS_SRV_REPL',
'ATLAS_SHRD',
'ATLAS_SRV_SHRD',
'ATLAS_TLS11',
'ATLAS_SRV_TLS11',
'ATLAS_TLS12',
'ATLAS_SRV_TLS12',
];

$command = new \MongoDB\Driver\Command(['ping' => 1]);
$query = new \MongoDB\Driver\Query([]);

foreach (getAtlasConnectivityUrls() as $url) {
if (strpos($url, '#') === 0) {
echo trim(substr($url, 1)), "\n";
foreach ($envs as $env) {
echo $env, ': ';
$uri = getenv($env);

if (! is_string($uri)) {
echo "FAIL: env var is undefined\n";
continue;
}

try {
$m = new \MongoDB\Driver\Manager($url);
$m = new \MongoDB\Driver\Manager($uri);
$m->executeCommand('admin', $command);
iterator_to_array($m->executeQuery('test.test', $query));
echo "PASS\n";
Expand All @@ -30,25 +47,16 @@ foreach (getAtlasConnectivityUrls() as $url) {
===DONE===
<?php exit(0); ?>
--EXPECTF--
Atlas Serverless
PASS
PASS
Atlas replica set (4.0)
PASS
PASS
Atlas sharded cluster (4.0)
PASS
PASS
Atlas free tier replica set
PASS
PASS
Atlas with only TLSv1.1 enabled (4.0)
PASS
PASS
Atlas with only TLSv1.2 enabled (4.0)
PASS
PASS
Atlas with only TLSv1.2 enabled (4.0) and bad credentials
FAIL: %s
FAIL: %s
ATLAS_SERVERLESS: PASS
ATLAS_SRV_SERVERLESS: PASS
ATLAS_FREE: PASS
ATLAS_SRV_FREE: PASS
ATLAS_REPL: PASS
ATLAS_SRV_REPL: PASS
ATLAS_SHRD: PASS
ATLAS_SRV_SHRD: PASS
ATLAS_TLS11: PASS
ATLAS_SRV_TLS11: PASS
ATLAS_TLS12: PASS
ATLAS_SRV_TLS12: PASS
===DONE===
7 changes: 0 additions & 7 deletions tests/utils/skipif.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,3 @@ function skip_if_no_crypt_shared()
exit('skip crypt_shared is not available');
}
}

function skip_if_no_atlas_connectivity_urls()
{
if (getAtlasConnectivityUrls() === []) {
exit('skip No Atlas URIs found');
}
}
23 changes: 0 additions & 23 deletions tests/utils/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -847,26 +847,3 @@ function failGetMore(Manager $manager)

throw new Exception("Trying to configure a getMore fail point for a server version ($version) that doesn't support it");
}

function getAtlasConnectivityUrls(): array
{
$atlasUriString = getenv('ATLAS_CONNECTIVITY_URIS') ?: '';
if (!$atlasUriString) {
return [];
}

$rawUrls = explode("\n", $atlasUriString);

$urls = [];
foreach ($rawUrls as $url) {
$url = trim($url);

if ($url == '') {
continue;
}

$urls[] = $url;
}

return $urls;
}
Loading