Skip to content
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
13 changes: 12 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
{
"patterns": [
"**/../lib/**",
"**/../src/**",
"mongodb-mock-server"
]
}
Expand Down Expand Up @@ -224,7 +225,8 @@
{
"patterns": [
"**/../lib/**",
"mongodb-mock-server"
"mongodb-mock-server",
"**/../src/**"
]
}
]
Expand Down Expand Up @@ -331,6 +333,15 @@
"disallowTypeAnnotations": false,
"fixStyle": "separate-type-imports"
}
],
"no-restricted-imports": [
"error",
{
"patterns": [
"**/../lib/**",
"**/../src/**"
]
}
]
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/cmap/auth/mongodb_oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type { Connection } from '../connection';
import { type AuthContext, AuthProvider } from './auth_provider';
import type { MongoCredentials } from './mongo_credentials';
import { AutomatedCallbackWorkflow } from './mongodb_oidc/automated_callback_workflow';
import { callback as azureCallback } from './mongodb_oidc/azure_machine_workflow';
import { callback as gcpCallback } from './mongodb_oidc/gcp_machine_workflow';
import { callback as k8sCallback } from './mongodb_oidc/k8s_machine_workflow';
import { azureCallback } from './mongodb_oidc/azure_machine_workflow';
import { gcpCallback } from './mongodb_oidc/gcp_machine_workflow';
import { k8sCallback } from './mongodb_oidc/k8s_machine_workflow';
import { TokenCache } from './mongodb_oidc/token_cache';
import { callback as testCallback } from './mongodb_oidc/token_machine_workflow';
import { tokenMachineCallback as testCallback } from './mongodb_oidc/token_machine_workflow';

/** Error when credentials are missing. */
const MISSING_CREDENTIALS_ERROR = 'AuthContext must provide credentials.';
Expand Down
2 changes: 1 addition & 1 deletion src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const TOKEN_RESOURCE_MISSING_ERROR =
* @param params - The OIDC callback parameters.
* @returns The OIDC response.
*/
export const callback: OIDCCallbackFunction = async (
export const azureCallback: OIDCCallbackFunction = async (
params: OIDCCallbackParams
): Promise<OIDCResponse> => {
const tokenAudience = params.tokenAudience;
Expand Down
2 changes: 1 addition & 1 deletion src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TOKEN_RESOURCE_MISSING_ERROR =
* @param params - The OIDC callback parameters.
* @returns The OIDC response.
*/
export const callback: OIDCCallbackFunction = async (
export const gcpCallback: OIDCCallbackFunction = async (
params: OIDCCallbackParams
): Promise<OIDCResponse> => {
const tokenAudience = params.tokenAudience;
Expand Down
2 changes: 1 addition & 1 deletion src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const AWS_FILENAME = 'AWS_WEB_IDENTITY_TOKEN_FILE';
* @param params - The OIDC callback parameters.
* @returns The OIDC response.
*/
export const callback: OIDCCallbackFunction = async (): Promise<OIDCResponse> => {
export const k8sCallback: OIDCCallbackFunction = async (): Promise<OIDCResponse> => {
let filename: string;
if (process.env[AZURE_FILENAME]) {
filename = process.env[AZURE_FILENAME];
Expand Down
2 changes: 1 addition & 1 deletion src/cmap/auth/mongodb_oidc/token_machine_workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const TOKEN_MISSING_ERROR = 'OIDC_TOKEN_FILE must be set in the environment.';
* @param params - The OIDC callback parameters.
* @returns The OIDC response.
*/
export const callback: OIDCCallbackFunction = async (): Promise<OIDCResponse> => {
export const tokenMachineCallback: OIDCCallbackFunction = async (): Promise<OIDCResponse> => {
const tokenFile = process.env.OIDC_TOKEN_FILE;
if (!tokenFile) {
throw new MongoAWSError(TOKEN_MISSING_ERROR);
Expand Down
3 changes: 2 additions & 1 deletion test/action/dependency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from 'node:path';
import { expect } from 'chai';

import { dependencies, peerDependencies, peerDependenciesMeta } from '../../package.json';
import { setDifference } from '../../src/utils';
import { setDifference } from '../mongodb';
import { alphabetically, itInNodeProcess, sorted } from '../tools/utils';

const EXPECTED_DEPENDENCIES = sorted(
Expand Down Expand Up @@ -139,6 +139,7 @@ describe('package.json', function () {

beforeEach(async function () {
for (const key of Object.keys(require.cache)) delete require.cache[key];
// Intentionally import from `src` because we are testing the package's exports (index.ts)
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('../../src');
imports = Array.from(
Expand Down
2 changes: 1 addition & 1 deletion test/benchmarks/unitBench/list.bench.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const chalk = require('chalk');
const { List } = require('../../../src/utils');
const { List } = require('../../mongodb');
const { createHistogram } = require('perf_hooks');
const { process } = require('process');

Expand Down
2 changes: 1 addition & 1 deletion test/csfle-kms-providers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as process from 'process';

import { type KMSProviders } from './../src';
import { type KMSProviders } from './mongodb';

const csfleKMSProviders = {
aws: {
Expand Down
5 changes: 1 addition & 4 deletions test/integration/auth/auth.prose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { expect } from 'chai';
import * as process from 'process';
import * as sinon from 'sinon';

import { type MongoClient } from '../../../src';
import { ScramSHA256 } from '../../../src/cmap/auth/scram';
import { Connection } from '../../../src/cmap/connection';
import { LEGACY_HELLO_COMMAND } from '../../../src/constants';
import { Connection, LEGACY_HELLO_COMMAND, type MongoClient, ScramSHA256 } from '../../mongodb';
import { type TestConfiguration } from '../../tools/runner/config';

function makeConnectionString(config, username, password) {
Expand Down
4 changes: 1 addition & 3 deletions test/integration/auth/mongodb_aws.prose.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { expect } from 'chai';
import * as process from 'process';

import { type MongoClient, MongoServerError } from '../../../src';
import { AWSSDKCredentialProvider } from '../../../src/cmap/auth/aws_temporary_credentials';

import { AWSSDKCredentialProvider, type MongoClient, MongoServerError } from '../../mongodb';
const isMongoDBAWSAuthEnvironment = (process.env.MONGODB_URI ?? '').includes('MONGODB-AWS');

describe('MONGODB-AWS Prose Tests', function () {
Expand Down
17 changes: 8 additions & 9 deletions test/integration/auth/mongodb_aws.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ import * as process from 'process';
import * as sinon from 'sinon';

import {
aws4Sign,
type AWSCredentials,
AWSSDKCredentialProvider,
type CommandOptions,
Connection,
type Document,
MongoAWSError,
type MongoClient,
MongoDBAWS,
type MongoDBNamespace,
type MongoDBResponseConstructor,
MongoMissingCredentialsError,
MongoMissingDependencyError,
MongoServerError
} from '../../../src';
import { refreshKMSCredentials } from '../../../src/client-side-encryption/providers';
import { AWSSDKCredentialProvider } from '../../../src/cmap/auth/aws_temporary_credentials';
import { aws4Sign } from '../../../src/cmap/auth/aws4';
import { MongoDBAWS } from '../../../src/cmap/auth/mongodb_aws';
import { Connection } from '../../../src/cmap/connection';
import { setDifference } from '../../../src/utils';

MongoServerError,
refreshKMSCredentials,
setDifference
} from '../../mongodb';
const isMongoDBAWSAuthEnvironment = (process.env.MONGODB_URI ?? '').includes('MONGODB-AWS');

describe('MONGODB-AWS', function () {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/auth/mongodb_oidc.prose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
type Collection,
MongoClient,
type MongoClientOptions,
type MongoDBOIDC,
type OIDCCallbackFunction,
type OIDCCallbackParams,
type OIDCResponse
} from '../../../src';
import { type MongoDBOIDC, type OIDCCallbackFunction } from '../../../src/cmap/auth/mongodb_oidc';

} from '../../mongodb';
const createCallback = (tokenFile = 'test_user1', expiresInSeconds?: number, extraFields?: any) => {
return async (params: OIDCCallbackParams) => {
const token = await readFile(path.join(process.env.OIDC_TOKEN_DIR, tokenFile), {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/bson-decimal128/decimal128.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';

import { type Collection, Decimal128, type MongoClient } from '../../../src';
import { type Collection, Decimal128, type MongoClient } from '../../mongodb';

describe('Decimal128', function () {
let client: MongoClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { LEGACY_HELLO_COMMAND } = require('../../../src/constants');
const { LEGACY_HELLO_COMMAND } = require('../../mongodb');

const { setupDatabase } = require('../shared');
const { expect } = require('chai');
Expand Down
20 changes: 11 additions & 9 deletions test/integration/change-streams/change_stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ import {
type ChangeStream,
type ChangeStreamDocument,
type ChangeStreamOptions,
type Collection,
type CommandStartedEvent,
type Db,
isHello,
LEGACY_HELLO_COMMAND,
MongoAPIError,
MongoChangeStreamError,
type MongoClient,
MongoServerError,
ReadPreference,
type ResumeToken
} from '../../../src/change_stream';
import { type CommandStartedEvent } from '../../../src/cmap/command_monitoring_events';
import { type Collection } from '../../../src/collection';
import { LEGACY_HELLO_COMMAND } from '../../../src/constants';
import { type Db } from '../../../src/db';
import { MongoAPIError, MongoChangeStreamError, MongoServerError } from '../../../src/error';
import { type MongoClient } from '../../../src/mongo_client';
import { ReadPreference } from '../../../src/read_preference';
import { isHello } from '../../../src/utils';
} from '../../mongodb';
import * as mock from '../../tools/mongodb-mock/index';
import { TestBuilder, UnifiedTestSuiteBuilder } from '../../tools/unified_suite_builder';
import { type FailCommandFailPoint, sleep } from '../../tools/utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import {
type CommandStartedEvent,
type CommandSucceededEvent,
type Document,
LEGACY_HELLO_COMMAND,
Long,
type MongoClient,
MongoNetworkError,
ObjectId,
Timestamp
} from '../../../src';
import { LEGACY_HELLO_COMMAND } from '../../../src/constants';
} from '../../mongodb';
import * as mock from '../../tools/mongodb-mock/index';
import { setupDatabase } from '../shared';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import * as fs from 'fs';
import * as path from 'path';
import * as process from 'process';

import { type MongoClient, WriteConcern } from '../../../src';
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption';
import { getCSFLEKMSProviders } from '../../csfle-kms-providers';
import { ClientEncryption, type MongoClient, WriteConcern } from '../../mongodb';
import { getEncryptExtraOptions } from '../../tools/utils';

describe('Client Side Encryption Prose Corpus Test', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { expect } from 'chai';
import * as process from 'process';
import { satisfies } from 'semver';

import { ClientEncryption, type MongoClient } from '../../../src';
import { getCSFLEKMSProviders } from '../../csfle-kms-providers';
import { ClientEncryption, type MongoClient } from '../../mongodb';

const metadata: MongoDBMetadataUI = {
requires: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import { readFileSync } from 'fs';
import * as path from 'path';
import * as process from 'process';

import { type CommandStartedEvent, type MongoClient, type MongoClientOptions } from '../../../src';
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption';
import {
ClientEncryption,
type CommandStartedEvent,
type MongoClient,
type MongoClientOptions
} from '../../mongodb';
import { type TestConfiguration } from '../../tools/runner/config';
import { getEncryptExtraOptions } from '../../tools/utils';
import { dropCollection } from '../shared';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { expect } from 'chai';
import {
Binary,
BSON,
ClientEncryption,
type CommandFailedEvent,
type CommandSucceededEvent,
type MongoClient,
MongoNetworkError
} from '../../../src';
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption';
} from '../../mongodb';
import { getEncryptExtraOptions } from '../../tools/utils';

const metadata: MongoDBMetadataUI = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { expect } from 'chai';
import { env } from 'process';

import { Binary } from '../../../src';
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption';

import { Binary, ClientEncryption } from '../../mongodb';
const dataKeyOptions = {
masterKey: {
projectId: 'devprod-drivers',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { expect } from 'chai';

import { type Document } from '../../../src';
import { MongoCryptAzureKMSRequestError } from '../../../src/client-side-encryption/errors';
import {
type AzureKMSRequestOptions,
fetchAzureKMSToken
} from '../../../src/client-side-encryption/providers/azure';

type Document,
fetchAzureKMSToken,
MongoCryptAzureKMSRequestError
} from '../../mongodb';
const BASE_URL = new URL(`http://127.0.0.1:8080/metadata/identity/oauth2/token`);
class KMSRequestOptions implements AzureKMSRequestOptions {
url: URL = BASE_URL;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { expect } from 'chai';
import { env } from 'process';

import { Binary } from '../../../src';
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption';
import { MongoCryptAzureKMSRequestError } from '../../../src/client-side-encryption/errors';

import { Binary, ClientEncryption, MongoCryptAzureKMSRequestError } from '../../mongodb';
const dataKeyOptions = {
masterKey: {
keyVaultEndpoint: 'https://drivers-2411-keyvault.vault.azure.net/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { expect } from 'chai';
import { once } from 'events';
import { createServer, type Server } from 'net';

import { type MongoClient } from '../../../src';
import { getCSFLEKMSProviders } from '../../csfle-kms-providers';
import { type MongoClient } from '../../mongodb';
import { getEncryptExtraOptions } from '../../tools/utils';

describe('20. Bypass creating mongocryptd client when shared library is loaded', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { expect } from 'chai';

import { Collection, type Db, MongoServerError } from '../../../src';
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption';
import { MongoCryptCreateEncryptedCollectionError } from '../../../src/client-side-encryption/errors';
import {
getCSFLEKMSProviders,
kmsCredentialsPresent,
missingKeys
} from '../../csfle-kms-providers';

import {
ClientEncryption,
Collection,
type Db,
MongoCryptCreateEncryptedCollectionError,
MongoServerError
} from '../../mongodb';
const metadata: MongoDBMetadataUI = {
requires: {
clientSideEncryption: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import { expect } from 'chai';
import { readFile } from 'fs/promises';
import { join } from 'path';

import { Decimal128, type Document, Double, Long, type MongoClient } from '../../../src';
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption';
import { MongoCryptError } from '../../../src/client-side-encryption/errors';
import { getCSFLEKMSProviders } from '../../csfle-kms-providers';

import {
ClientEncryption,
Decimal128,
type Document,
Double,
Long,
type MongoClient,
MongoCryptError
} from '../../mongodb';
const getKmsProviders = () => {
const result = getCSFLEKMSProviders();

Expand Down
Loading