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
1 change: 1 addition & 0 deletions packages/fxa-auth-server/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
},
testTimeout: 10000,
clearMocks: true,
workerIdleMemoryLimit: '512MB',
setupFiles: ['<rootDir>/jest.setup.js', '<rootDir>/jest.setup-proxyquire.js'],
testPathIgnorePatterns: ['/node_modules/'],
// Coverage configuration (enabled via --coverage flag)
Expand Down
1 change: 1 addition & 0 deletions packages/fxa-auth-server/jest.integration.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
],

testTimeout: 120000,
maxWorkers: 4,

globalSetup: '<rootDir>/test/support/jest-global-setup.ts',
globalTeardown: '<rootDir>/test/support/jest-global-teardown.ts',
Expand Down
2 changes: 1 addition & 1 deletion packages/fxa-auth-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"test-unit": "VERIFIER_VERSION=0 TEST_TYPE=unit scripts/test-ci.sh",
"test-integration": "VERIFIER_VERSION=0 TEST_TYPE=integration scripts/test-ci.sh",
"test-integration-v2": "VERIFIER_VERSION=0 TEST_TYPE=integration-v2 scripts/test-ci.sh",
"test-integration-jest": "JEST_JUNIT_OUTPUT_DIR='../../artifacts/tests/fxa-auth-server' JEST_JUNIT_OUTPUT_NAME='jest-integration-results.xml' npx jest --config jest.integration.config.js --forceExit --ci --reporters=default --reporters=jest-junit",
"test-integration-jest": "VERIFIER_VERSION=0 TEST_TYPE=integration-jest scripts/test-ci.sh",
"populate-firestore-customers": "CONFIG_FILES='config/secrets.json' node -r esbuild-register ./scripts/populate-firestore-customers.ts",
"populate-vat-taxes": "CONFIG_FILES='config/secrets.json' node -r esbuild-register ./scripts/populate-vat-taxes.ts",
"paypal-processor": "CONFIG_FILES='config/secrets.json' node -r esbuild-register ./scripts/paypal-processor.ts",
Expand Down
35 changes: 24 additions & 11 deletions packages/fxa-auth-server/scripts/test-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ if [ "$TEST_TYPE" == 'integration' ]; then GREP_TESTS="--grep /#integration\s-/"
if [ "$TEST_TYPE" == 'integration-v2' ]; then GREP_TESTS="--grep /#integrationV2\s-/"; fi;


TESTS=(local oauth remote scripts)
if [ -z "$1" ]; then
# Skip mocha tests for integration-jest — only run Jest tests
if [ "$TEST_TYPE" != 'integration-jest' ]; then
TESTS=(local oauth remote scripts)
else
TESTS=($1)
if [ -z "$1" ]; then
TESTS=(local oauth remote scripts)
else
TESTS=($1)
fi

for t in "${TESTS[@]}"; do
echo -e "\n\nTesting: $t"

#./scripts/mocha-coverage.js $DEFAULT_ARGS $GREP_TESTS --reporter-options mochaFile="../../artifacts/tests/fxa-auth-server/$t/test-results.xml" "test/$t"
MOCHA_FILE=../../artifacts/tests/$npm_package_name/fxa-auth-server-mocha-$TEST_TYPE-$t-results.xml mocha $DEFAULT_ARGS $GREP_TESTS test/$t
done
fi

for t in "${TESTS[@]}"; do
echo -e "\n\nTesting: $t"

#./scripts/mocha-coverage.js $DEFAULT_ARGS $GREP_TESTS --reporter-options mochaFile="../../artifacts/tests/fxa-auth-server/$t/test-results.xml" "test/$t"
MOCHA_FILE=../../artifacts/tests/$npm_package_name/fxa-auth-server-mocha-$TEST_TYPE-$t-results.xml mocha $DEFAULT_ARGS $GREP_TESTS test/$t
done

if [ "$TEST_TYPE" == 'integration' ]; then
yarn run clean-up-old-ci-stripe-customers;
fi;
Expand All @@ -42,6 +45,16 @@ elif [ "$TEST_TYPE" == 'integration' ]; then
JEST_JUNIT_OUTPUT_DIR="../../artifacts/tests/fxa-auth-server" \
JEST_JUNIT_OUTPUT_NAME="fxa-auth-server-jest-integration-results.xml" \
npx jest --coverage --forceExit --ci --reporters=default --reporters=jest-junit --testPathPattern='verification-reminders'
elif [ "$TEST_TYPE" == 'integration-jest' ]; then
echo -e "\n\nRunning Jest verification-reminders tests"
JEST_JUNIT_OUTPUT_DIR="../../artifacts/tests/fxa-auth-server" \
JEST_JUNIT_OUTPUT_NAME="fxa-auth-server-jest-verification-reminders-results.xml" \
npx jest --coverage --forceExit --ci --reporters=default --reporters=jest-junit --testPathPattern='verification-reminders'

echo -e "\n\nRunning Jest migrated integration tests"
JEST_JUNIT_OUTPUT_DIR="../../artifacts/tests/fxa-auth-server" \
JEST_JUNIT_OUTPUT_NAME="fxa-auth-server-jest-integration-jest-results.xml" \
npx jest --config jest.integration.config.js --forceExit --ci --reporters=default --reporters=jest-junit
elif [ -z "$TEST_TYPE" ]; then
echo -e "\n\nRunning all Jest tests"
JEST_JUNIT_OUTPUT_DIR="../../artifacts/tests/fxa-auth-server" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { createTestServer, TestServerInstance } from '../support/helpers/test-server';
import crypto from 'crypto';

interface AuthServerError extends Error {
errno: number;
code: number;
email: string;
}
import * as jwt from '../../lib/oauth/jwt';
import { createTestServer, TestServerInstance } from '../support/helpers/test-server';
import { AuthServerError, generateMetricsContext } from '../support/helpers/test-utils';

interface TestConfig extends Record<string, unknown> {
smtp: { syncUrl: string };
publicUrl: string;
}

// eslint-disable-next-line @typescript-eslint/no-require-imports
const Client = require('../client')();
const mocks = require('../mocks');

let server: TestServerInstance;
let config: TestConfig;
Expand Down Expand Up @@ -167,7 +164,6 @@ describe.each(testVersions)(

const stubResponse = await client.stubAccount('dcdb5ae7add825d2');

const jwt = require('../../lib/oauth/jwt');
const setupToken = jwt.sign(
{ uid: stubResponse.uid, iat: Date.now() },
{ header: { typ: 'fin+JWT' } }
Expand Down Expand Up @@ -236,7 +232,6 @@ describe.each(testVersions)(

const stubResponse = await client.stubAccount('dcdb5ae7add825d2');

const jwt = require('../../lib/oauth/jwt');
const setupToken = jwt.sign(
{
uid: stubResponse.uid,
Expand Down Expand Up @@ -431,6 +426,195 @@ describe.each(testVersions)(
}
});

it('invalid entrypointExperiment', async () => {
const api = new Client.Api(server.publicUrl, testOptions);
const email = server.uniqueEmail();
const authPW =
'0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
const options = {
...testOptions,
metricsContext: {
entrypoint: 'foo',
entrypointExperiment: ';',
entrypointVariation: 'var',
utmCampaign: 'bar',
utmContent: 'baz',
utmMedium: 'qux',
utmSource: 'wibble',
utmTerm: 'blee',
},
};

try {
await api.accountCreate(email, authPW, options);
fail('should have thrown');
} catch (err: unknown) {
expect((err as AuthServerError).errno).toBe(107);
}
});

it('invalid entrypointVariation', async () => {
const api = new Client.Api(server.publicUrl, testOptions);
const email = server.uniqueEmail();
const authPW =
'0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
const options = {
...testOptions,
metricsContext: {
entrypoint: 'foo',
entrypointExperiment: 'exp',
entrypointVariation: ';',
utmCampaign: 'bar',
utmContent: 'baz',
utmMedium: 'qux',
utmSource: 'wibble',
utmTerm: 'blee',
},
};

try {
await api.accountCreate(email, authPW, options);
fail('should have thrown');
} catch (err: unknown) {
expect((err as AuthServerError).errno).toBe(107);
}
});

it('invalid utmCampaign', async () => {
const api = new Client.Api(server.publicUrl, testOptions);
const email = server.uniqueEmail();
const authPW =
'0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
const options = {
...testOptions,
metricsContext: {
entrypoint: 'foo',
entrypointExperiment: 'exp',
entrypointVariation: 'var',
utmCampaign: ';',
utmContent: 'bar',
utmMedium: 'baz',
utmSource: 'qux',
utmTerm: 'wibble',
},
};

try {
await api.accountCreate(email, authPW, options);
fail('should have thrown');
} catch (err: unknown) {
expect((err as AuthServerError).errno).toBe(107);
}
});

it('invalid utmContent', async () => {
const api = new Client.Api(server.publicUrl, testOptions);
const email = server.uniqueEmail();
const authPW =
'0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
const options = {
...testOptions,
metricsContext: {
entrypoint: 'foo',
entrypointExperiment: 'exp',
entrypointVariation: 'var',
utmCampaign: 'bar',
utmContent: ';',
utmMedium: 'baz',
utmSource: 'qux',
utmTerm: 'wibble',
},
};

try {
await api.accountCreate(email, authPW, options);
fail('should have thrown');
} catch (err: unknown) {
expect((err as AuthServerError).errno).toBe(107);
}
});

it('invalid utmMedium', async () => {
const api = new Client.Api(server.publicUrl, testOptions);
const email = server.uniqueEmail();
const authPW =
'0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
const options = {
...testOptions,
metricsContext: {
entrypoint: 'foo',
entrypointExperiment: 'exp',
entrypointVariation: 'var',
utmCampaign: 'bar',
utmContent: 'baz',
utmMedium: ';',
utmSource: 'qux',
utmTerm: 'wibble',
},
};

try {
await api.accountCreate(email, authPW, options);
fail('should have thrown');
} catch (err: unknown) {
expect((err as AuthServerError).errno).toBe(107);
}
});

it('invalid utmSource', async () => {
const api = new Client.Api(server.publicUrl, testOptions);
const email = server.uniqueEmail();
const authPW =
'0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
const options = {
...testOptions,
metricsContext: {
entrypoint: 'foo',
entrypointExperiment: 'exp',
entrypointVariation: 'var',
utmCampaign: 'bar',
utmContent: 'baz',
utmMedium: 'qux',
utmSource: ';',
utmTerm: 'wibble',
},
};

try {
await api.accountCreate(email, authPW, options);
fail('should have thrown');
} catch (err: unknown) {
expect((err as AuthServerError).errno).toBe(107);
}
});

it('invalid utmTerm', async () => {
const api = new Client.Api(server.publicUrl, testOptions);
const email = server.uniqueEmail();
const authPW =
'0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
const options = {
...testOptions,
metricsContext: {
entrypoint: 'foo',
entrypointExperiment: 'exp',
entrypointVariation: 'var',
utmCampaign: 'bar',
utmContent: 'baz',
utmMedium: 'qux',
utmSource: 'wibble',
utmTerm: ';',
},
};

try {
await api.accountCreate(email, authPW, options);
fail('should have thrown');
} catch (err: unknown) {
expect((err as AuthServerError).errno).toBe(107);
}
});

it('create account with service query parameter', async () => {
const email = server.uniqueEmail();

Expand Down Expand Up @@ -470,8 +654,8 @@ describe.each(testVersions)(
},
});
fail('account creation should have failed');
} catch (err) {
expect(err).toBeTruthy();
} catch (err: unknown) {
expect((err as AuthServerError).errno).toBe(107);
}
});

Expand All @@ -488,16 +672,16 @@ describe.each(testVersions)(
},
});
fail('account creation should have failed');
} catch (err) {
expect(err).toBeTruthy();
} catch (err: unknown) {
expect((err as AuthServerError).errno).toBe(107);
}
});

it('account creation works with maximal metricsContext metadata', async () => {
const email = server.uniqueEmail();
const options = {
...testOptions,
metricsContext: mocks.generateMetricsContext(),
metricsContext: generateMetricsContext(),
};

const client = await Client.create(server.publicUrl, email, 'foo', options);
Expand Down Expand Up @@ -532,8 +716,8 @@ describe.each(testVersions)(
},
});
fail('account creation should have failed');
} catch (err) {
expect(err).toBeTruthy();
} catch (err: unknown) {
expect((err as AuthServerError).errno).toBe(107);
}
});

Expand All @@ -548,8 +732,8 @@ describe.each(testVersions)(
},
});
fail('account creation should have failed');
} catch (err) {
expect(err).toBeTruthy();
} catch (err: unknown) {
expect((err as AuthServerError).errno).toBe(107);
}
});

Expand Down
Loading