UNPKG

3.27 kBJavaScriptView Raw
1/*
2 Copyright 2019 Google LLC
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 https://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17var plugin = {
18 ruleId: "EX-PO007",
19 name: "Policy Naming Conventions - type indication",
20 message:
21 "It is recommended that the policy name include an indicator of the policy type.",
22 fatal: false,
23 severity: 1, //warning
24 nodeType: "Policy",
25 enabled: true
26 },
27 policyMetaData = {
28 AccessControl: { indications: ["AC-"] },
29 AccessEntity: { indications: ["AE-"] },
30 AssignMessage: { indications: ["AM-"] },
31 BasicAuthentication: {indications: ["BA-"] },
32 ExtractVariables: { indications: ["EV-"] },
33 FlowCallout: { indications: ["FC-"] },
34 GenerateSAMLAssertion: { indications: ["SA-"] },
35 GetOAuthV1Info:{indications: ["OA-"]},
36 GetOAuthV2Info: {indications: ["OA-"]},
37 InvalidateCache: {indications: ["CI-"] },
38 JSONThreatProtection: {indications: ["JT-"] },
39 JSONToXML: { indications: ["JX-"] },
40 JavaCallout: { indications: ["JC-"] },
41 Javascript: { indications: ["JS-"] },
42 KeyValueMapOperations: {indications: ["KV-"] },
43 Ldap: { indications: ["LD-"] },
44 LookupCache: { indications: ["CL-"] },
45 MessageLogging: { indications: ["ML-"] },
46 MessageValidation: { indications: ["MV-"] },
47 OAuthV1: {indications: ["OA-"]},
48 OAuthV2: {indications: ["OA-"]},
49 PopulateCache: {indications: ["CP-"] },
50 Quota: { indications: ["QU-"] },
51 RaiseFault: { indications: ["RF-"] },
52 RegularExpressionProtection: { indications: ["RE-"] },
53 ResetQuota: { indications: ["QR-"] },
54 ResponseCache: { indications: ["RC-"] },
55 Script: { indications: ["PY-"] },
56 ServiceCallout: { indications: ["SC-"] },
57 SpikeArrest: { indications: ["SA-"] },
58 StatisticsCollector: { indications: ["SC-"] },
59 VerifyAPIKey: { indications: ["VK-"] },
60 XMLThreatProtection: { indications: ["XT-"] },
61 XMLToJSON: { indications: ["XJ-"] },
62 XSL: { indications: ["XS-"] },
63 "": { indications: [] }
64 };
65
66var onPolicy = function(policy, cb) {
67 var displayName = policy.getDisplayName(),
68 policyType = policy.getType(),
69 prefixes = policyMetaData[policyType].indications,
70 found = false,
71 hadWarn = false;
72
73 prefixes.some(function(prefix) {
74 if (displayName.startsWith(prefix)) {
75 found = true;
76 return;
77 }
78 });
79
80 if (!found || displayName === "") {
81 policy.addMessage({
82 plugin,
83 message:
84 'Naming Conventions: Policy "' +
85 displayName +
86 '" of type "' +
87 policyType +
88 '" should have an indicative prefix. Valid prefixes include: ' +
89 JSON.stringify(prefixes)
90 });
91 hadWarn = true;
92 }
93 if (typeof cb == "function") {
94 cb(null, hadWarn);
95 }
96};
97
98module.exports = {
99 plugin,
100 onPolicy
101};