Co-authored-by: Tianxiang Chen <tianxchen@microsoft.com>
This commit is contained in:
tianxchen-ms 2022-08-23 15:11:06 +08:00 коммит произвёл GitHub
Родитель 9875310b7e
Коммит 9db4046c0b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 22 добавлений и 22 удалений

Просмотреть файл

@ -1,11 +1,4 @@
import {
RequestDefinition,
ResponseDefinition,
ItemDefinition,
Request,
Response,
DescriptionDefinition,
} from "postman-collection";
import { ItemDefinition, Request, Response, DescriptionDefinition } from "postman-collection";
import {
NewmanAssertion,
NewmanExecution,
@ -32,8 +25,8 @@ interface Assertion {
interface RawNewmanExecution {
id: string;
item: ItemDefinition;
request: RequestDefinition;
response: ResponseDefinition;
request: Request;
response: Response;
assertions?: Assertion[];
}
@ -48,8 +41,8 @@ export function parseNewmanReport(newmanReport: RawNewmanReport): NewmanReport {
}
function generateExampleItem(it: RawNewmanExecution): NewmanExecution {
const resp = new Response(it.response);
const req = new Request(it.request);
const resp = it.response;
const req = it.request;
const rawReq = parseRequest(req);
const rawResp = parseResponse(resp);
const annotation = JSON.parse((it.item.description as DescriptionDefinition)?.content || "{}");

Просмотреть файл

@ -314,7 +314,6 @@ export class NewmanReportValidator {
try {
return JSON.parse(body);
} catch (e) {
console.error(`Failed to parse body: ${body}`);
return body ? body : undefined;
}
}

Просмотреть файл

@ -26,7 +26,7 @@ import {
} from "./newmanReportValidator";
import { SwaggerAnalyzer, SwaggerAnalyzerOption } from "./swaggerAnalyzer";
import { EnvironmentVariables, VariableEnv } from "./variableEnv";
import { parseNewmanReport, RawNewmanReport } from "./newmanReportParser";
import { parseNewmanReport } from "./newmanReportParser";
import {
defaultCollectionFileName,
defaultEnvFileName,
@ -399,8 +399,7 @@ export class PostmanCollectionGenerator {
{
collection: collection,
environment: runtimeEnv,
reporters: ["cli", "json"],
reporter: { json: { export: reportExportPath } },
reporters: ["cli"],
},
function (err, summary) {
if (summary.run.failures.length > 0) {
@ -413,7 +412,13 @@ export class PostmanCollectionGenerator {
}
)
.on("done", async (_err, _summary) => {
await this.postRun(scenario, reportExportPath, runtimeEnv);
const summary = {
environment: {
values: _summary.environment.values.members,
},
run: _summary.run,
};
await this.postRun(scenario, reportExportPath, runtimeEnv, summary);
resolve(_summary);
});
});
@ -421,7 +426,12 @@ export class PostmanCollectionGenerator {
await newmanRun();
}
private async postRun(scenario: Scenario, reportExportPath: string, runtimeEnv: VariableScope) {
private async postRun(
scenario: Scenario,
reportExportPath: string,
runtimeEnv: VariableScope,
summary: any
) {
const keys = await this.swaggerAnalyzer.getAllSecretKey();
const values: string[] = [];
for (const [k, v] of Object.entries(runtimeEnv.syncVariablesTo())) {
@ -431,17 +441,15 @@ export class PostmanCollectionGenerator {
}
this.dataMasker.addMaskedValues(values);
this.dataMasker.addMaskedKeys(keys);
// read content and upload. mask newman report.
const rawReport = JSON.parse(await this.fileLoader.load(reportExportPath)) as RawNewmanReport;
// add mask environment secret value
for (const item of rawReport.environment.values) {
for (const item of summary.environment.values) {
if (this.dataMasker.maybeSecretKey(item.key)) {
this.dataMasker.addMaskedValues([item.value]);
}
}
const newmanReport = parseNewmanReport(rawReport);
const newmanReport = parseNewmanReport(summary);
const newmanReportValidatorOption: NewmanReportValidatorOption = {
apiScenarioFilePath: scenario._scenarioDef._filePath,