Skip to content

Commit 0e16c7c

Browse files
test(NODE-6941): run x509 tests against cloud-dev (#4568)
1 parent 4c1fa54 commit 0e16c7c

File tree

5 files changed

+30
-86
lines changed

5 files changed

+30
-86
lines changed

.evergreen/config.in.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,12 @@ functions:
697697
type: test
698698
params:
699699
working_dir: "src"
700-
env:
701-
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
702-
MONGODB_URI: ${MONGODB_URI}
703-
DRIVERS_TOOLS: ${DRIVERS_TOOLS}
700+
include_expansions_in_env:
701+
- AWS_ACCESS_KEY_ID
702+
- AWS_SECRET_ACCESS_KEY
703+
- AWS_SESSION_TOKEN
704+
- PROJECT_DIRECTORY
705+
- DRIVERS_TOOLS
704706
binary: bash
705707
args:
706708
- ${PROJECT_DIRECTORY}/.evergreen/run-x509-tests.sh

.evergreen/config.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,12 @@ functions:
632632
type: test
633633
params:
634634
working_dir: src
635-
env:
636-
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
637-
MONGODB_URI: ${MONGODB_URI}
638-
DRIVERS_TOOLS: ${DRIVERS_TOOLS}
635+
include_expansions_in_env:
636+
- AWS_ACCESS_KEY_ID
637+
- AWS_SECRET_ACCESS_KEY
638+
- AWS_SESSION_TOKEN
639+
- PROJECT_DIRECTORY
640+
- DRIVERS_TOOLS
639641
binary: bash
640642
args:
641643
- ${PROJECT_DIRECTORY}/.evergreen/run-x509-tests.sh
@@ -1544,16 +1546,8 @@ tasks:
15441546
- auth
15451547
- x509
15461548
commands:
1547-
- command: expansions.update
1548-
type: setup
1549-
params:
1550-
updates:
1551-
- {key: VERSION, value: latest}
1552-
- {key: TOPOLOGY, value: server}
1553-
- {key: AUTH, value: noauth}
1554-
- {key: SSL, value: ssl}
15551549
- func: install dependencies
1556-
- func: bootstrap mongo-orchestration
1550+
- func: assume secrets manager role
15571551
- func: run x509 auth tests
15581552
- name: test-atlas-connectivity
15591553
tags:

.evergreen/generate_evergreen_tasks.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,8 @@ BASE_TASKS.push({
118118
name: `test-x509-authentication`,
119119
tags: ['latest', 'auth', 'x509'],
120120
commands: [
121-
updateExpansions({
122-
VERSION: 'latest',
123-
TOPOLOGY: 'server',
124-
AUTH: 'noauth',
125-
SSL: 'ssl'
126-
}),
127121
{ func: 'install dependencies' },
128-
{ func: 'bootstrap mongo-orchestration' },
122+
{ func: 'assume secrets manager role' },
129123
{ func: 'run x509 auth tests' }
130124
]
131125
});

.evergreen/run-x509-tests.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ source $DRIVERS_TOOLS/.evergreen/init-node-and-npm-env.sh
44

55
set -o errexit
66

7-
export SSL_KEY_FILE=$DRIVERS_TOOLS/.evergreen/x509gen/client.pem
8-
export SSL_CA_FILE=$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem
9-
export SSL_KEY_FILE_EXPIRED=$DRIVERS_TOOLS/.evergreen/x509gen/expired.pem
10-
export SSL_KEY_NO_USER=$DRIVERS_TOOLS/.evergreen/x509gen/crl.pem
7+
bash drivers-evergreen-tools/.evergreen/secrets_handling/setup-secrets.sh drivers/atlas_connect
8+
source secrets-export.sh
119

12-
SUBJECT=$(openssl x509 -subject -nameopt RFC2253 -noout -inform PEM -in $SSL_KEY_FILE)
10+
echo "${ATLAS_X509_DEV_CERT_BASE64}" | base64 --decode >clientcert.pem
11+
echo "${ATLAS_X509_DEV_CERT_NOUSER_BASE64}" | base64 --decode >nouser.pem
1312

14-
# Strip `subject=` prefix from the subject
15-
SUBJECT=${SUBJECT#"subject="}
13+
SSL_KEY_FILE_EXPIRED=$DRIVERS_TOOLS/.evergreen/x509gen/expired.pem
14+
MONGODB_URI="$ATLAS_X509_DEV"
1615

17-
# Remove any leading or trailing whitespace
18-
SUBJECT=$(echo "$SUBJECT" | awk '{$1=$1;print}')
19-
20-
export SUBJECT
16+
export MONGODB_URI
17+
export SSL_KEY_FILE_EXPIRED
18+
export SSL_KEY_FILE_NO_USER="nouser.pem"
19+
export SSL_KEY_FILE="clientcert.pem"
2120

2221
npm run check:x509

test/manual/x509_auth.test.ts

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,14 @@ const connectionString = new ConnectionString(process.env.MONGODB_URI!);
1414
describe('x509 Authentication', function () {
1515
let client: MongoClient;
1616
const validOptions: MongoClientOptions = {
17-
tls: true,
18-
tlsCertificateKeyFile: process.env.SSL_KEY_FILE,
19-
tlsCAFile: process.env.SSL_CA_FILE,
20-
authMechanism: 'MONGODB-X509' as const,
21-
authSource: '$external'
17+
tlsCertificateKeyFile: process.env.SSL_KEY_FILE
2218
};
2319

2420
this.afterEach(() => {
2521
return client?.close();
2622
});
2723

2824
context('When the user provides a valid certificate', function () {
29-
before('create x509 user', createX509User);
30-
after('drop x509 user', dropX509User);
31-
3225
it('successfully authenticates using x509', async function () {
3326
client = new MongoClient(connectionString.toString(), validOptions);
3427
const result = await client
@@ -64,9 +57,7 @@ describe('x509 Authentication', function () {
6457
const invalidOptions: MongoClientOptions = {
6558
// use an expired key file
6659
tlsCertificateKeyFile: process.env.SSL_KEY_FILE_EXPIRED,
67-
tlsCAFile: process.env.SSL_CA_FILE,
68-
authMechanism: 'MONGODB-X509' as const,
69-
authSource: '$external'
60+
serverSelectionTimeoutMS: 2000
7061
};
7162
client = new MongoClient(connectionString.toString(), {
7263
...invalidOptions,
@@ -82,7 +73,10 @@ describe('x509 Authentication', function () {
8273
'when a valid cert is provided but the certificate does not correspond to a user',
8374
function () {
8475
it('fails to authenticate', async function () {
85-
client = new MongoClient(connectionString.toString(), validOptions);
76+
client = new MongoClient(connectionString.toString(), {
77+
tlsCertificateKeyFile: process.env.SSL_KEY_FILE_NO_USER,
78+
serverSelectionTimeoutMS: 2000
79+
});
8680
const error = await client.connect().catch(error => error);
8781

8882
expect(error).to.be.instanceOf(MongoServerError);
@@ -91,42 +85,3 @@ describe('x509 Authentication', function () {
9185
}
9286
);
9387
});
94-
95-
async function createX509User() {
96-
const utilClient = new MongoClient(connectionString.toString(), {
97-
tls: true,
98-
tlsCertificateKeyFile: process.env.SSL_KEY_FILE,
99-
tlsCAFile: process.env.SSL_CA_FILE,
100-
serverSelectionTimeoutMS: 2000
101-
});
102-
103-
try {
104-
await utilClient.connect();
105-
await utilClient.db('$external').command({
106-
createUser: process.env.SUBJECT,
107-
roles: [
108-
{ role: 'readWrite', db: 'test' },
109-
{ role: 'userAdminAnyDatabase', db: 'admin' }
110-
]
111-
});
112-
} finally {
113-
await utilClient.close();
114-
}
115-
}
116-
117-
async function dropX509User() {
118-
const utilClient = new MongoClient(connectionString.toString(), {
119-
tls: true,
120-
tlsCertificateKeyFile: process.env.SSL_KEY_FILE,
121-
tlsCAFile: process.env.SSL_CA_FILE,
122-
serverSelectionTimeoutMS: 2000
123-
});
124-
try {
125-
await utilClient.connect();
126-
await utilClient.db('$external').command({
127-
dropUser: process.env.SUBJECT
128-
});
129-
} finally {
130-
await utilClient.close();
131-
}
132-
}

0 commit comments

Comments
 (0)