-
Notifications
You must be signed in to change notification settings - Fork 0
ci(NODE-6505): Setup CI #4
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
Changes from 21 commits
1ccf38e
aeda36b
e5d8cad
a041206
0c978a2
f8cbb9a
2fa3417
c71d3c2
e6facfe
06f9758
86f7874
7a30734
b39c754
ccb726e
b0a1c3c
6198ade
a135e79
ca25868
270d151
69dbda6
3ce14a4
eac708f
f38366b
62d18d8
40858d4
d6044e7
08f4c23
1098636
955cedf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: Encryption Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: ['master', 'NODE-6505/ci-setup'] | ||
| workflow_dispatch: {} | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| run-tests: | ||
| permissions: | ||
| # required for all workflows | ||
| security-events: write | ||
| id-token: write | ||
| contents: write | ||
| runs-on: ubuntu-latest | ||
| name: Encryption tests | ||
| env: | ||
| FORCE_COLOR: true | ||
| steps: | ||
| - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 | ||
| - name: Setup node | ||
| uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4 | ||
| with: | ||
| node-version: latest | ||
| - name: Install Dependencies | ||
| run: npm install | ||
| - name: Install mongodb-client-encryption | ||
| run: npm install mongodb-client-encryption | ||
| - name: Set up cluster | ||
| id: setup-cluster | ||
|
||
| uses: mongodb-labs/drivers-evergreen-tools@master | ||
| with: | ||
| version: 8.0.0 | ||
| topology: sharded_cluster | ||
| auth: auth | ||
| - name: Run Tests | ||
| run: npm run test-encryption | ||
| env: | ||
| MONGOOSE_TEST_URI: ${{ steps.setup-cluster.outputs.cluster-uri }} | ||
| CRYPT_SHARED_LIB_PATH: ${{ steps.setup-cluster.outputs.crypt-shared-lib-path }} | ||
baileympearson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| 'use strict'; | ||
|
|
||
| const assert = require('assert'); | ||
| const mdb = require('mongodb'); | ||
| const isBsonType = require('../../lib/helpers/isBsonType'); | ||
|
|
||
| const LOCAL_KEY = Buffer.from('Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk', 'base64'); | ||
|
|
||
| describe('environmental variables', () => { | ||
| it('MONGOOSE_TEST_URI is set', async function() { | ||
| const uri = process.env.MONGOOSE_TEST_URI; | ||
| assert.ok(uri); | ||
| }); | ||
|
|
||
| it('CRYPT_SHARED_LIB_PATH is set', async function() { | ||
| const shared_library_path = process.env.CRYPT_SHARED_LIB_PATH; | ||
| assert.ok(shared_library_path); | ||
| }); | ||
| }); | ||
|
|
||
| describe('basic integration', () => { | ||
| let keyVaultClient; | ||
| let dataKey; | ||
| let encryptedClient; | ||
| let dummyClient; | ||
|
|
||
| beforeEach(async function() { | ||
| keyVaultClient = new mdb.MongoClient(process.env.MONGOOSE_TEST_URI); | ||
| await keyVaultClient.connect(); | ||
| await keyVaultClient.db('keyvault').collection('datakeys'); | ||
| const clientEncryption = new mdb.ClientEncryption(keyVaultClient, { | ||
| keyVaultNamespace: 'keyvault.datakeys', | ||
| kmsProviders: { local: { key: LOCAL_KEY } } | ||
| }); | ||
| dataKey = await clientEncryption.createDataKey('local'); | ||
|
|
||
| encryptedClient = new mdb.MongoClient( | ||
| process.env.MONGOOSE_TEST_URI, | ||
| { | ||
| autoEncryption: { | ||
| keyVaultNamespace: 'keyvault.datakeys', | ||
baileympearson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| kmsProviders: { local: { key: LOCAL_KEY } }, | ||
| schemaMap: { | ||
| 'db.coll': { | ||
| bsonType: 'object', | ||
| encryptMetadata: { | ||
| keyId: [new mdb.UUID(dataKey)] | ||
baileympearson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| properties: { | ||
| a: { | ||
| encrypt: { | ||
| bsonType: 'int', | ||
| algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Random', | ||
| keyId: [new mdb.UUID(dataKey)] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| extraOptions: { | ||
| cryptdSharedLibRequired: true, | ||
| cryptSharedLibPath: process.env.CRYPT_SHARED_LIB_PATH | ||
| } | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| dummyClient = new mdb.MongoClient(process.env.MONGOOSE_TEST_URI); | ||
baileympearson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| afterEach(async function() { | ||
| await keyVaultClient.close(); | ||
| await encryptedClient.close(); | ||
| await dummyClient.close(); | ||
| }); | ||
|
|
||
| it('supports mongodb csfle auto-encryption integration', async() => { | ||
baileympearson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| await encryptedClient.connect(); | ||
| await encryptedClient.db('db').collection('coll').insertOne({ a: 1 }); | ||
baileympearson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // a dummyClient not configured with autoEncryption, returns a encrypted binary type, meaning that encryption succeeded | ||
| const encryptedCursor = await dummyClient.db('db').collection('coll').find(); | ||
| const encryptedResult = await encryptedCursor.next(); | ||
baileympearson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert.ok(encryptedResult); | ||
| assert.ok(encryptedResult.a); | ||
| assert.ok(isBsonType(encryptedResult.a, 'Binary')); | ||
| assert.ok(encryptedResult.a.sub_type === 6); | ||
|
|
||
| // when the encryptedClient runs a find, the original unencrypted value is returned | ||
| const unencryptedCursor = await encryptedClient.db('db').collection('coll').find(); | ||
baileympearson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const unencryptedResult = await unencryptedCursor.next(); | ||
| assert.ok(unencryptedResult); | ||
| assert.ok(unencryptedResult.a === 1); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.