@metlo/testing
Advanced tools
Comparing version 0.3.4 to 0.3.5
@@ -1,2 +0,2 @@ | ||
import { TemplateConfig } from "../types/resource_config"; | ||
import { Host, TemplateConfig } from "../types/resource_config"; | ||
import { TestStepBuilder } from "./builder"; | ||
@@ -12,4 +12,4 @@ import { AuthActor } from "./permissions"; | ||
export declare const getAuthTestPayloads: (endpoint: GenTestEndpoint, config: TemplateConfig) => AuthTestStepPayload[]; | ||
export declare const addAuthToRequest: (authActor: AuthActor, gen: GeneratedTestRequest, ctx: GenTestContext) => GeneratedTestRequest; | ||
export declare const authTestStepPayloadToBuilder: (endpoint: GenTestEndpoint, payload: AuthTestStepPayload, idx: number) => TestStepBuilder; | ||
export declare const addAuthToRequest: (authActor: AuthActor, gen: GeneratedTestRequest, ctx: GenTestContext, hostInfo: Host) => GeneratedTestRequest; | ||
export declare const authTestStepPayloadToBuilder: (endpoint: GenTestEndpoint, payload: AuthTestStepPayload, idx: number, hostInfo: Host) => TestStepBuilder; | ||
export {}; |
@@ -50,3 +50,5 @@ "use strict"; | ||
if (resourceLevelAccessItems) { | ||
payload.reason = `Doesn't have access to resources ${noResourceLevelAccessItems.join(" and ")}`; | ||
payload.reason = `Actor doesn't have access to resource${noResourceLevelAccessItems.length > 1 | ||
? `s: ${noResourceLevelAccessItems.join(", ")}` | ||
: ` ${noResourceLevelAccessItems[0]}`}.`; | ||
} | ||
@@ -63,3 +65,5 @@ payloads.push(payload); | ||
if (resourceLevelAccessItems.length > 0) { | ||
payload.reason = `Has access to ${resourceLevelAccessItems.join(" and ")}`; | ||
payload.reason = `Actor has access to resource${resourceLevelAccessItems.length > 1 | ||
? `s: ${resourceLevelAccessItems.join(", ")}` | ||
: ` ${resourceLevelAccessItems[0]}`}.`; | ||
} | ||
@@ -82,4 +86,4 @@ payloads.push(payload); | ||
exports.getAuthTestPayloads = getAuthTestPayloads; | ||
const addAuthToRequest = (authActor, gen, ctx) => { | ||
const authConfig = ctx.endpoint.authConfig; | ||
const addAuthToRequest = (authActor, gen, ctx, hostInfo) => { | ||
const authConfig = hostInfo !== null && hostInfo !== void 0 ? hostInfo : ctx.endpoint.authConfig; | ||
if (!authConfig) { | ||
@@ -102,3 +106,3 @@ return gen; | ||
} | ||
else if (authConfig.authType == enums_1.AuthType.HEADER) { | ||
else if (authConfig.authType == enums_1.AuthType.HEADER && authConfig.headerKey) { | ||
headers = headers.concat({ | ||
@@ -113,3 +117,3 @@ name: authConfig.headerKey, | ||
} | ||
else if (authConfig.authType == enums_1.AuthType.JWT) { | ||
else if (authConfig.authType == enums_1.AuthType.JWT && authConfig.headerKey) { | ||
headers = headers.concat({ | ||
@@ -127,3 +131,3 @@ name: authConfig.headerKey, | ||
exports.addAuthToRequest = addAuthToRequest; | ||
const authTestStepPayloadToBuilder = (endpoint, payload, idx) => { | ||
const authTestStepPayloadToBuilder = (endpoint, payload, idx, hostInfo) => { | ||
let entityMap = {}; | ||
@@ -147,3 +151,3 @@ let description = ""; | ||
let gen = (0, sample_request_1.makeSampleRequestNoAuthInner)(ctx); | ||
gen = (0, exports.addAuthToRequest)(payload.authActorEntity, gen, ctx); | ||
gen = (0, exports.addAuthToRequest)(payload.authActorEntity, gen, ctx, hostInfo); | ||
let builder = new builder_1.TestStepBuilder(gen.req).addToEnv(...gen.env); | ||
@@ -150,0 +154,0 @@ if (payload.authorized) { |
@@ -101,3 +101,3 @@ "use strict"; | ||
.filter(([k, v]) => v.items.length > 0 && v.items[0].auth) | ||
.map(([k, v]) => v.items.map((e, i) => ({ name: k, auth: e.auth, item: e, idx: i }))) | ||
.map(([k, v]) => v.items.map((e, i) => ({ name: k, auth: e.auth, item: e, idx: i + 1 }))) | ||
.flat(); | ||
@@ -104,0 +104,0 @@ }; |
@@ -200,2 +200,3 @@ "use strict"; | ||
let env = []; | ||
ctx.prefix = ctx.prefix ? ctx.prefix + "_" : ""; | ||
let replacedPath = ctx.endpoint.path; | ||
@@ -235,6 +236,5 @@ for (const paramField of ctx.endpoint.dataFields.filter(e => e.dataSection == enums_2.DataSection.REQUEST_PATH)) { | ||
const entityMap = (0, permissions_1.getEntityMap)(endpoint, config); | ||
const prefix = name ? name + "_" : ""; | ||
const ctx = { | ||
endpoint, | ||
prefix, | ||
prefix: name, | ||
entityMap, | ||
@@ -241,0 +241,0 @@ }; |
@@ -20,2 +20,3 @@ import { KeyValType, TestRequest } from "../types/test"; | ||
export interface GenTestEndpoint { | ||
uuid?: string; | ||
host: string; | ||
@@ -22,0 +23,0 @@ path: string; |
@@ -15,1 +15,2 @@ import { FailedAssertion, FailedRequest, TestConfig, TestResult } from "./types/test"; | ||
export { runTest, estimateTest } from "./runner"; | ||
export { generateAuthTests } from "./generate/generate-auth-tests"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.estimateTest = exports.runTest = exports.processResourceConfig = exports.parseResourceConfig = exports.TestStepBuilder = exports.TestBuilder = exports.TestConfigSchema = exports.ExtractorType = exports.AssertionType = exports.getFailedRequests = exports.getFailedAssertions = exports.loadTestConfig = exports.dumpTestConfig = void 0; | ||
exports.generateAuthTests = exports.estimateTest = exports.runTest = exports.processResourceConfig = exports.parseResourceConfig = exports.TestStepBuilder = exports.TestBuilder = exports.TestConfigSchema = exports.ExtractorType = exports.AssertionType = exports.getFailedRequests = exports.getFailedAssertions = exports.loadTestConfig = exports.dumpTestConfig = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -121,2 +121,4 @@ const chalk_1 = tslib_1.__importDefault(require("chalk")); | ||
Object.defineProperty(exports, "estimateTest", { enumerable: true, get: function () { return runner_1.estimateTest; } }); | ||
var generate_auth_tests_1 = require("./generate/generate-auth-tests"); | ||
Object.defineProperty(exports, "generateAuthTests", { enumerable: true, get: function () { return generate_auth_tests_1.generateAuthTests; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -10,2 +10,3 @@ "use strict"; | ||
const testStepPayloads = (0, auth_test_step_gen_1.getAuthTestPayloads)(endpoint, config); | ||
const hostInfo = config.hosts[endpoint.host]; | ||
let builder = new builder_1.TestBuilder().setMeta({ | ||
@@ -17,3 +18,3 @@ name: `${endpoint.path} VALIDATE_AUTH_RULES`, | ||
for (let i = 0; i < testStepPayloads.length; i++) { | ||
builder = builder.addTestStep((0, auth_test_step_gen_1.authTestStepPayloadToBuilder)(endpoint, testStepPayloads[i], i)); | ||
builder = builder.addTestStep((0, auth_test_step_gen_1.authTestStepPayloadToBuilder)(endpoint, testStepPayloads[i], i + 1, hostInfo)); | ||
} | ||
@@ -20,0 +21,0 @@ return builder; |
{ | ||
"name": "@metlo/testing", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1226318
113
13159