-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestMyCustomRules.js
More file actions
76 lines (65 loc) · 2.47 KB
/
testMyCustomRules.js
File metadata and controls
76 lines (65 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const assert = require("assert"),
path = require("path"),
Bundle = require("../apigeelint/lib/package/Bundle.js"),
bl = require("../apigeelint/lib/package/bundleLinter.js");
const configuration = {
debug: true,
source: {
type: "filesystem",
path: path.resolve(__dirname, '../apigeelint/test/fixtures/resources/sampleProxy/24Solver/apiproxy'),
bundleType: "apiproxy"
},
profile: 'apigeex',
excluded: {},
setExitCode: false,
output: () => {} // suppress output
};
describe("Check proxy name prefix", function() {
var pluginFile = path.resolve(__dirname, "checkProxyNamePrefix.js"),
ruleId = "MyRule-001";
it("should show error when proxy name don't start with B2B-* or B2C-*", function() {
var bundle = new Bundle(configuration);
bl.executePlugin(pluginFile, bundle);
var report = getReportByRuleId(ruleId, bundle.getReport());
assert.equal(report[0].message, "API Proxy name (TwentyFour) should start with B2B-* or B2C-*");
assert.equal(report[0].severity, 2);
});
it("shouldn't show error when proxy name starts with B2B-*", function() {
var bundle = new Bundle(configuration);
bundle.getName = function() { return "B2B-TEST"; };
bl.executePlugin(pluginFile, bundle);
var report = getReportByRuleId(ruleId, bundle.getReport());
assert.equal(report.length, 0);
});
it("shouldn't show error when proxy name starts with B2C-*", function() {
var bundle = new Bundle(configuration);
bundle.getName = function() { return "B2C-TEST"; };
bl.executePlugin(pluginFile, bundle);
var report = getReportByRuleId(ruleId, bundle.getReport());
assert.equal(report.length, 0);
});
});
describe("Check Spike Arrest", function() {
var pluginFile = path.resolve(__dirname, "checkPreFlowSpikeArrest.js"),
ruleId = "MyRule-002";
it("should show error when missing Spike Arrest", function() {
var bundle = new Bundle(configuration);
bl.executePlugin(pluginFile, bundle);
var report = getReportByRuleId(ruleId, bundle.getReport());
assert.equal(report[0].message, "Spike Arrest policy should be included in the PreFlow section.");
assert.equal(report[0].severity, 2);
});
});
function getReportByRuleId(ruleId, bundleReport) {
var jsimpl = bl.getFormatter("json.js"),
jsonReport = JSON.parse(jsimpl(bundleReport)),
reports = [];
for (let r of jsonReport) {
for (let m of r.messages) {
if (m.ruleId === ruleId) {
reports.push(m);
}
}
}
return reports;
}