mirror of
https://github.com/Kong/insomnia.git
synced 2026-10-25 08:09:06 -04:00
Disable cert validation option while running tests in inso (#3492)
This commit is contained in:
1 parent
5e00656807
commit
706b0f076a
6 files changed
+33
-11
No files matched your search
@@ -1,12 +1,18 @@
|
||||
import { BaseModel, stats, types as modelTypes } from '../models';
|
||||
import * as models from '../models';
|
||||
import { getBodyBuffer } from '../models/response';
|
||||
import { Settings } from '../models/settings';
|
||||
import { send } from '../network/network';
|
||||
import * as plugins from '../plugins';
|
||||
import { database as db } from './database';
|
||||
import { database } from './database';
|
||||
|
||||
export async function getSendRequestCallbackMemDb(environmentId, memDB) {
|
||||
// The network layer uses settings from the settings model
|
||||
// We want to give consumers the ability to override certain settings
|
||||
type SettingsOverride = Pick<Settings, 'validateSSL'>;
|
||||
|
||||
export async function getSendRequestCallbackMemDb(environmentId: string, memDB: any, settingsOverrides?: SettingsOverride) {
|
||||
// Initialize the DB in-memory and fill it with data if we're given one
|
||||
await db.init(
|
||||
await database.init(
|
||||
modelTypes(),
|
||||
{
|
||||
inMemoryOnly: true,
|
||||
@@ -16,29 +22,34 @@ export async function getSendRequestCallbackMemDb(environmentId, memDB) {
|
||||
);
|
||||
const docs: BaseModel[] = [];
|
||||
|
||||
const settings = await models.settings.getOrCreate();
|
||||
docs.push({ ...settings, ...settingsOverrides });
|
||||
|
||||
for (const type of Object.keys(memDB)) {
|
||||
for (const doc of memDB[type]) {
|
||||
docs.push(doc);
|
||||
}
|
||||
}
|
||||
|
||||
await db.batchModifyDocs({
|
||||
await database.batchModifyDocs({
|
||||
upsert: docs,
|
||||
remove: [],
|
||||
});
|
||||
|
||||
// Return callback helper to send requests
|
||||
return async function sendRequest(requestId) {
|
||||
return async function sendRequest(requestId: string) {
|
||||
return sendAndTransform(requestId, environmentId);
|
||||
};
|
||||
}
|
||||
export function getSendRequestCallback(environmentId) {
|
||||
return async function sendRequest(requestId) {
|
||||
|
||||
export function getSendRequestCallback(environmentId?: string) {
|
||||
return async function sendRequest(requestId: string) {
|
||||
stats.incrementExecutedRequests();
|
||||
return sendAndTransform(requestId, environmentId);
|
||||
};
|
||||
}
|
||||
|
||||
async function sendAndTransform(requestId, environmentId) {
|
||||
async function sendAndTransform(requestId: string, environmentId?: string) {
|
||||
try {
|
||||
plugins.ignorePlugin('insomnia-plugin-kong-bundle');
|
||||
const res = await send(requestId, environmentId);
|
||||
|
||||
@@ -282,7 +282,7 @@ class WrapperUnitTest extends PureComponent<Props, State> {
|
||||
tests,
|
||||
},
|
||||
]);
|
||||
const sendRequest = getSendRequestCallback(activeEnvironment ? activeEnvironment._id : null);
|
||||
const sendRequest = getSendRequestCallback(activeEnvironment?._id);
|
||||
let results;
|
||||
|
||||
try {
|
||||
|
||||
@@ -151,6 +151,7 @@ The test runner is built on top of Mocha, thus many of the options behave as the
|
||||
| `--testNamePattern <regex>` | `-t` | run tests that match the regex|
|
||||
| `--bail` | `-b` | abort ("bail") after the first test failure|
|
||||
| `--keepFile` | | do not delete the generated test file (useful for debugging)|
|
||||
| `--disableCertValidation` | | disable certificate validation|
|
||||
|
||||
### Examples
|
||||
|
||||
@@ -169,6 +170,13 @@ inso run test "Sample Specification" --env "OpenAPI env"
|
||||
inso run test spc_46c5a4 --env env_env_ca046a
|
||||
```
|
||||
|
||||
Don't validate SSL certificates
|
||||
|
||||
``` sh
|
||||
inso run test "Sample Specification" --env "OpenAPI env" --disableSSL
|
||||
inso run test spc_46c5a4 --env env_env_ca046a --disableSSL
|
||||
```
|
||||
|
||||
Scope by the a test suite name or id
|
||||
|
||||
``` sh
|
||||
|
||||
@@ -168,5 +168,6 @@ Options:
|
||||
progress, spec] (default: spec)
|
||||
-b, --bail abort (\\"bail\\") after first test failure
|
||||
--keepFile do not delete the generated test file
|
||||
--disableCertValidation disable certificate validation
|
||||
-h, --help display help for command"
|
||||
`;
|
||||
@@ -64,6 +64,7 @@ const makeTestCommand = (commandCreator: CreateCommand) => {
|
||||
)
|
||||
.option('-b, --bail', 'abort ("bail") after first test failure')
|
||||
.option('--keepFile', 'do not delete the generated test file')
|
||||
.option('--disableCertValidation', 'disable certificate validation')
|
||||
.action((identifier, cmd) => {
|
||||
let options = getOptions<RunTestsOptions>(cmd, {
|
||||
reporter: defaultReporter,
|
||||
|
||||
@@ -25,6 +25,7 @@ export type RunTestsOptions = GlobalOptions & {
|
||||
bail?: boolean;
|
||||
keepFile?: boolean;
|
||||
testNamePattern?: string;
|
||||
disableCertValidation?: boolean;
|
||||
};
|
||||
|
||||
function validateOptions({ reporter }: Partial<RunTestsOptions>): boolean {
|
||||
@@ -55,7 +56,7 @@ export async function runInsomniaTests(
|
||||
return false;
|
||||
}
|
||||
|
||||
const { reporter, bail, keepFile, appDataDir, workingDir, env, ci, testNamePattern } = options;
|
||||
const { reporter, bail, keepFile, appDataDir, workingDir, env, ci, testNamePattern, disableCertValidation } = options;
|
||||
const db = await loadDb({
|
||||
workingDir,
|
||||
appDataDir,
|
||||
@@ -93,7 +94,7 @@ export async function runInsomniaTests(
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires -- Load lazily when needed, otherwise this require slows down the entire CLI.
|
||||
const { getSendRequestCallbackMemDb } = require('insomnia-send-request');
|
||||
|
||||
const sendRequest = await getSendRequestCallbackMemDb(environment._id, db);
|
||||
const sendRequest = await getSendRequestCallbackMemDb(environment._id, db, { validateSSL: !disableCertValidation });
|
||||
return await noConsoleLog(() =>
|
||||
runTestsCli(testFileContents, {
|
||||
reporter,
|
||||
|
||||
Reference in new issue
Block a user