apigeelint
Version:
Node module and tool to lint a bundle for an Apigee API Proxy or sharedflow.
101 lines (88 loc) • 3.02 kB
JavaScript
/*
Copyright © 2019-2022, 2026 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* global describe, it */
const assert = require("node:assert"),
ruleId = "ST006",
path = require("node:path"),
debug = require("debug")(`apigeelint:${ruleId}`),
util = require("node:util"),
bl = require("../../lib/package/bundleLinter.js");
const expectedMessageRe = new RegExp(
"^For the [A-Za-z]{4,} step \\([-A-Za-z0-9_]{2,}\\), an appropriate check for a message body was not found\\..*",
);
describe(`${ruleId} - JSONThreatProtection Conditions`, () => {
function check(suffix, bundleType, expected) {
const configuration = {
debug: true,
source: {
type: "filesystem",
path: path.resolve(
__dirname,
`../fixtures/resources/ThreatProtection-Attachment/${bundleType}`,
),
bundleType,
},
excluded: {},
setExitCode: false,
output: () => {}, // suppress output
};
bl.lint(configuration, (bundle) => {
const items = bundle.getReport();
assert.ok(items);
assert.ok(items.length);
debug(util.format(items));
const proxyEndpointItems = items.filter((m) =>
m.filePath.endsWith(suffix),
);
debug(util.format(proxyEndpointItems));
assert.equal(proxyEndpointItems.length, 1);
proxyEndpointItems.forEach((item) => debug(util.format(item.messages)));
const st006Messages = proxyEndpointItems[0].messages.filter(
(m) => m.ruleId == ruleId,
);
debug(util.format(st006Messages));
assert.equal(st006Messages.length, expected.length);
expected.forEach((item, ix) => {
assert.equal(st006Messages[ix].line, item.line, `case(${ix}) line`);
assert.equal(
st006Messages[ix].column,
item.column,
`case(${ix}) column`,
);
assert.equal(st006Messages[ix].severity, 1, `case(${ix}) severity`);
assert.ok(
st006Messages[ix].message.match(expectedMessageRe),
`case(${ix}) message`,
);
});
});
}
it("should generate the expected warnings in an apiproxy", () => {
const expected = [
{
line: 36,
column: 9,
},
];
check("endpoint1.xml", "apiproxy", expected);
});
it("should generate the expected warnings in a sharedflow", () => {
const expected = [
{
line: 4,
column: 3,
},
];
check("sf-default.xml", "sharedflowbundle", expected);
});
});