UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

52 lines 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SoapResponse = void 0; const xml_response_1 = require("./xml-response"); const validMimeTypes = [ "application/soap+xml", "text/xml", "text/soap+xml", "application/wsdl+xml", "text/wsdl+xml", ]; class SoapResponse extends xml_response_1.XmlResponse { init(httpResponse) { var _a; super.init(httpResponse); this.context.assert(this.statusCode).between(200, 299); const mimeType = (_a = String(this.header("Content-Type").$) .split(";") .shift()) === null || _a === void 0 ? void 0 : _a.trim(); this.context .assert(`Mime Type is valid for SOAP (${validMimeTypes.join(", ")})`, mimeType) .in(validMimeTypes); if (this.hasRequiredSoapFields()) { this.context.assert("Has required SOAP fields", true).equals(true); } } hasRequiredSoapFields() { const root = this.cheerio.root().children()[0]; const rootName = root["name"]; const rootParts = rootName.split(":"); const prefix = rootParts.length == 1 ? null : rootParts[0]; const envTag = prefix === null ? "Envelope" : `${prefix}\\:Envelope`; const bodyTag = prefix === null ? "Body" : `${prefix}\\:Body`; if (rootParts.length == 0 || rootParts.length > 2 || rootName == envTag) { this.context.logFailure(`Root element is <${envTag}>`, rootName); return false; } const envelope = this.cheerio(envTag); if (envelope.length !== 1) { this.context.logFailure(`Found envelope tag <${envTag}>`); return false; } const body = envelope.children(bodyTag); if (body.length !== 1) { this.context.logFailure(`<${envTag}> contains child <${bodyTag}>`); return false; } return true; } } exports.SoapResponse = SoapResponse; //# sourceMappingURL=soap-response.js.map