serverless-openapi-documenter 0.0.120-beta.1 → 0.0.123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/package.json +7 -3
- package/src/bruno.js +32 -0
- package/src/collection.js +29 -0
- package/src/definitionGenerator.js +49 -39
- package/src/openAPIGenerator.js +32 -37
- package/src/postman.js +53 -0
- package/src/schemaHandler.js +65 -61
- package/test/.mocharc.js +0 -9
- package/test/helpers/redocly.json +0 -4
- package/test/helpers/ref-parser.js +0 -5
- package/test/helpers/serverless.js +0 -19
- package/test/json/complex.json +0 -91
- package/test/json/newOWASP.json +0 -53
- package/test/json/valid-openAPI.json +0 -274
- package/test/models/BasicDocumentation.json +0 -48
- package/test/models/BasicValidFunction.json +0 -44
- package/test/models/ErrorResponse.json +0 -118
- package/test/models/PutDocumentResponse.json +0 -5
- package/test/models/models/models-alt.json +0 -17
- package/test/models/models/models.json +0 -20
- package/test/models/models/modelsList-alt.json +0 -17
- package/test/models/models/modelsList.json +0 -20
- package/test/unit/definitionGenerator.spec.js +0 -981
- package/test/unit/logger.spec.js +0 -160
- package/test/unit/openAPIGenerator.spec.js +0 -275
- package/test/unit/owasp.spec.js +0 -120
- package/test/unit/schemaHandler.spec.js +0 -1023
package/test/unit/logger.spec.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const expect = require("chai").expect;
|
|
4
|
-
const sinon = require("sinon");
|
|
5
|
-
|
|
6
|
-
const Logger = require("../../src/logger");
|
|
7
|
-
|
|
8
|
-
describe(`Logger`, function () {
|
|
9
|
-
let sls, logOutput;
|
|
10
|
-
|
|
11
|
-
beforeEach(function () {
|
|
12
|
-
sls = {
|
|
13
|
-
service: {
|
|
14
|
-
service: "test-service",
|
|
15
|
-
provider: {
|
|
16
|
-
stage: "test",
|
|
17
|
-
},
|
|
18
|
-
getAllFunctions: () => {},
|
|
19
|
-
getFunction: () => {},
|
|
20
|
-
},
|
|
21
|
-
version: "3.0.0",
|
|
22
|
-
variables: {
|
|
23
|
-
service: {
|
|
24
|
-
custom: {},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
configSchemaHandler: {
|
|
28
|
-
defineFunctionEventProperties: () => {},
|
|
29
|
-
defineFunctionProperties: () => {},
|
|
30
|
-
defineCustomProperties: () => {},
|
|
31
|
-
},
|
|
32
|
-
classes: {
|
|
33
|
-
Error: class ServerlessError {
|
|
34
|
-
constructor(err) {
|
|
35
|
-
return new Error(err);
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
processedInput: {
|
|
40
|
-
options: {
|
|
41
|
-
postmanCollection: "postman.json",
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
logOutput = {
|
|
47
|
-
log: {
|
|
48
|
-
debug: (str) => {},
|
|
49
|
-
error: (str) => {},
|
|
50
|
-
info: (str) => {},
|
|
51
|
-
notice: (str) => {},
|
|
52
|
-
success: (str) => {},
|
|
53
|
-
verbose: (str) => {},
|
|
54
|
-
warning: (str) => {},
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe(`debug`, function () {
|
|
60
|
-
it(`should log a debug log type when debug is called`, function () {
|
|
61
|
-
const logger = new Logger(sls, logOutput.log);
|
|
62
|
-
const spy = sinon.spy(logger, "log");
|
|
63
|
-
|
|
64
|
-
logger.debug("Testing");
|
|
65
|
-
|
|
66
|
-
expect(spy.called).to.be.true;
|
|
67
|
-
|
|
68
|
-
spy.restore();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe(`error`, function () {
|
|
73
|
-
it(`should log a error log type when error is called`, function () {
|
|
74
|
-
const logger = new Logger(sls, logOutput.log);
|
|
75
|
-
const spy = sinon.spy(logger, "log");
|
|
76
|
-
|
|
77
|
-
logger.error("Testing");
|
|
78
|
-
|
|
79
|
-
expect(spy.called).to.be.true;
|
|
80
|
-
|
|
81
|
-
spy.restore();
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe(`info`, function () {
|
|
86
|
-
it(`should log a info log type when info is called`, function () {
|
|
87
|
-
const logger = new Logger(sls, logOutput.log);
|
|
88
|
-
const spy = sinon.spy(logger, "log");
|
|
89
|
-
|
|
90
|
-
logger.info("Testing");
|
|
91
|
-
|
|
92
|
-
expect(spy.called).to.be.true;
|
|
93
|
-
|
|
94
|
-
spy.restore();
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe(`notice`, function () {
|
|
99
|
-
it(`should log a notice log type when log is called without a log type`, function () {
|
|
100
|
-
const logger = new Logger(sls, logOutput.log);
|
|
101
|
-
const spy = sinon.spy(logger, "log");
|
|
102
|
-
|
|
103
|
-
logger.log("Testing");
|
|
104
|
-
|
|
105
|
-
expect(spy.called).to.be.true;
|
|
106
|
-
|
|
107
|
-
spy.restore();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it(`should log a notice log type when notice is called`, function () {
|
|
111
|
-
const logger = new Logger(sls, logOutput.log);
|
|
112
|
-
const spy = sinon.spy(logger, "log");
|
|
113
|
-
|
|
114
|
-
logger.notice("Testing");
|
|
115
|
-
|
|
116
|
-
expect(spy.called).to.be.true;
|
|
117
|
-
|
|
118
|
-
spy.restore();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe(`success`, function () {
|
|
123
|
-
it(`should log a success log type when success is called`, function () {
|
|
124
|
-
const logger = new Logger(sls, logOutput.log);
|
|
125
|
-
const spy = sinon.spy(logger, "log");
|
|
126
|
-
|
|
127
|
-
logger.success("Testing");
|
|
128
|
-
|
|
129
|
-
expect(spy.called).to.be.true;
|
|
130
|
-
|
|
131
|
-
spy.restore();
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe(`verbose`, function () {
|
|
136
|
-
it(`should log a verbose log type when verbose is called`, function () {
|
|
137
|
-
const logger = new Logger(sls, logOutput.log);
|
|
138
|
-
const spy = sinon.spy(logger, "log");
|
|
139
|
-
|
|
140
|
-
logger.verbose("Testing");
|
|
141
|
-
|
|
142
|
-
expect(spy.called).to.be.true;
|
|
143
|
-
|
|
144
|
-
spy.restore();
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe(`warning`, function () {
|
|
149
|
-
it(`should log a warning log type when warning is called`, function () {
|
|
150
|
-
const logger = new Logger(sls, logOutput.log);
|
|
151
|
-
const spy = sinon.spy(logger, "log");
|
|
152
|
-
|
|
153
|
-
logger.warning("Testing");
|
|
154
|
-
|
|
155
|
-
expect(spy.called).to.be.true;
|
|
156
|
-
|
|
157
|
-
spy.restore();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
});
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
|
|
6
|
-
const PostmanGenerator = require("openapi-to-postmanv2");
|
|
7
|
-
const sinon = require("sinon");
|
|
8
|
-
const expect = require("chai").expect;
|
|
9
|
-
|
|
10
|
-
const validOpenAPI = require("../json/valid-openAPI.json");
|
|
11
|
-
|
|
12
|
-
const basicDocumentation = require("../models/BasicDocumentation.json");
|
|
13
|
-
const basicValidFunction = require("../models/BasicValidFunction.json");
|
|
14
|
-
|
|
15
|
-
const OpenAPIGenerator = require("../../src/openAPIGenerator");
|
|
16
|
-
|
|
17
|
-
describe("OpenAPIGenerator", () => {
|
|
18
|
-
let sls, logOutput;
|
|
19
|
-
|
|
20
|
-
beforeEach(function () {
|
|
21
|
-
sls = {
|
|
22
|
-
service: {
|
|
23
|
-
service: "test-service",
|
|
24
|
-
provider: {
|
|
25
|
-
stage: "test",
|
|
26
|
-
},
|
|
27
|
-
getAllFunctions: () => {},
|
|
28
|
-
getFunction: () => {},
|
|
29
|
-
},
|
|
30
|
-
version: "3.0.0",
|
|
31
|
-
variables: {
|
|
32
|
-
service: {
|
|
33
|
-
custom: {},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
configSchemaHandler: {
|
|
37
|
-
defineFunctionEventProperties: () => {},
|
|
38
|
-
defineFunctionProperties: () => {},
|
|
39
|
-
defineCustomProperties: () => {},
|
|
40
|
-
},
|
|
41
|
-
classes: {
|
|
42
|
-
Error: class ServerlessError {
|
|
43
|
-
constructor(err) {
|
|
44
|
-
return new Error(err);
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
processedInput: {
|
|
49
|
-
options: {
|
|
50
|
-
postmanCollection: "postman.json",
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
logOutput = {
|
|
56
|
-
log: {
|
|
57
|
-
notice: (str) => {},
|
|
58
|
-
error: (str) => {},
|
|
59
|
-
success: (str) => {},
|
|
60
|
-
verbose: (str) => {},
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
after(function () {
|
|
66
|
-
delete require
|
|
67
|
-
.cache[require.resolve(`${path.resolve("options")}/redocly.json`)];
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe("generationAndValidation", () => {
|
|
71
|
-
it("should correctly generate a valid OpenAPI document", async function () {
|
|
72
|
-
const succSpy = sinon.spy(logOutput.log, "success");
|
|
73
|
-
const errSpy = sinon.spy(logOutput.log, "error");
|
|
74
|
-
|
|
75
|
-
Object.assign(sls.service, basicDocumentation);
|
|
76
|
-
const getAllFuncsStub = sinon
|
|
77
|
-
.stub(sls.service, "getAllFunctions")
|
|
78
|
-
.returns(["createUser"]);
|
|
79
|
-
|
|
80
|
-
const getFuncStub = sinon
|
|
81
|
-
.stub(sls.service, "getFunction")
|
|
82
|
-
.returns(basicValidFunction.createUser);
|
|
83
|
-
|
|
84
|
-
const openAPIGenerator = new OpenAPIGenerator(sls, {}, logOutput);
|
|
85
|
-
openAPIGenerator.processCliInput();
|
|
86
|
-
|
|
87
|
-
const validOpenAPIDocument = await openAPIGenerator
|
|
88
|
-
.generationAndValidation()
|
|
89
|
-
.catch((err) => {
|
|
90
|
-
expect(err).to.be.undefined;
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
expect(succSpy.called).to.be.true;
|
|
94
|
-
expect(errSpy.called).to.be.false;
|
|
95
|
-
|
|
96
|
-
succSpy.restore();
|
|
97
|
-
errSpy.restore();
|
|
98
|
-
getAllFuncsStub.reset();
|
|
99
|
-
getFuncStub.reset();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
xit("should throw an error when trying to generate an invalid OpenAPI document", async function () {
|
|
103
|
-
const succSpy = sinon.spy(logOutput.log, "success");
|
|
104
|
-
const errSpy = sinon.spy(logOutput.log, "error");
|
|
105
|
-
|
|
106
|
-
Object.assign(sls.service, basicDocumentation);
|
|
107
|
-
const getAllFuncsStub = sinon
|
|
108
|
-
.stub(sls.service, "getAllFunctions")
|
|
109
|
-
.returns(["createUser"]);
|
|
110
|
-
const basicInvalidFunction = structuredClone(basicValidFunction);
|
|
111
|
-
|
|
112
|
-
delete basicInvalidFunction.createUser.events[0].http.documentation
|
|
113
|
-
.methodResponses[0].responseModels;
|
|
114
|
-
const getFuncStub = sinon
|
|
115
|
-
.stub(sls.service, "getFunction")
|
|
116
|
-
.returns(basicInvalidFunction.createUser);
|
|
117
|
-
|
|
118
|
-
const openAPIGenerator = new OpenAPIGenerator(sls, {}, logOutput);
|
|
119
|
-
openAPIGenerator.processCliInput();
|
|
120
|
-
|
|
121
|
-
const validOpenAPIDocument = await openAPIGenerator
|
|
122
|
-
.generationAndValidation()
|
|
123
|
-
.catch((err) => {
|
|
124
|
-
expect(err.message).to.be.equal(
|
|
125
|
-
"Error: createUser is missing a Response Model for statusCode 200"
|
|
126
|
-
);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
expect(succSpy.called).to.be.false;
|
|
130
|
-
expect(errSpy.called).to.be.true;
|
|
131
|
-
|
|
132
|
-
succSpy.restore();
|
|
133
|
-
errSpy.restore();
|
|
134
|
-
getAllFuncsStub.reset();
|
|
135
|
-
getFuncStub.reset();
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("should correctly validate a valid OpenAPI document", async function () {
|
|
139
|
-
const succSpy = sinon.spy(logOutput.log, "success");
|
|
140
|
-
const errSpy = sinon.spy(logOutput.log, "error");
|
|
141
|
-
|
|
142
|
-
Object.assign(sls.service, basicDocumentation);
|
|
143
|
-
const getAllFuncsStub = sinon
|
|
144
|
-
.stub(sls.service, "getAllFunctions")
|
|
145
|
-
.returns(["createUser"]);
|
|
146
|
-
const basicInvalidFunction = structuredClone(basicValidFunction);
|
|
147
|
-
|
|
148
|
-
const getFuncStub = sinon
|
|
149
|
-
.stub(sls.service, "getFunction")
|
|
150
|
-
.returns(basicInvalidFunction.createUser);
|
|
151
|
-
|
|
152
|
-
const openAPIGenerator = new OpenAPIGenerator(sls, {}, logOutput);
|
|
153
|
-
openAPIGenerator.processCliInput();
|
|
154
|
-
|
|
155
|
-
const validOpenAPIDocument = await openAPIGenerator
|
|
156
|
-
.generationAndValidation()
|
|
157
|
-
.catch((err) => {
|
|
158
|
-
expect(err).to.be.undefined;
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
expect(succSpy.called).to.be.true;
|
|
162
|
-
expect(errSpy.called).to.be.false;
|
|
163
|
-
expect(validOpenAPIDocument).to.have.property("openapi");
|
|
164
|
-
|
|
165
|
-
succSpy.restore();
|
|
166
|
-
errSpy.restore();
|
|
167
|
-
getAllFuncsStub.reset();
|
|
168
|
-
getFuncStub.reset();
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("should throw an error when trying to validate an invalid OpenAPI document", async function () {
|
|
172
|
-
const succSpy = sinon.spy(logOutput.log, "success");
|
|
173
|
-
const errSpy = sinon.spy(logOutput.log, "error");
|
|
174
|
-
|
|
175
|
-
Object.assign(sls.service, basicDocumentation);
|
|
176
|
-
|
|
177
|
-
const getAllFuncsStub = sinon
|
|
178
|
-
.stub(sls.service, "getAllFunctions")
|
|
179
|
-
.returns(["createUser"]);
|
|
180
|
-
|
|
181
|
-
const basicInvalidFunction = structuredClone(basicValidFunction);
|
|
182
|
-
|
|
183
|
-
delete basicInvalidFunction.createUser.events[0].http.documentation
|
|
184
|
-
.pathParams;
|
|
185
|
-
const getFuncStub = sinon
|
|
186
|
-
.stub(sls.service, "getFunction")
|
|
187
|
-
.returns(basicInvalidFunction.createUser);
|
|
188
|
-
|
|
189
|
-
const openAPIGenerator = new OpenAPIGenerator(sls, {}, logOutput);
|
|
190
|
-
openAPIGenerator.processCliInput();
|
|
191
|
-
|
|
192
|
-
const validOpenAPIDocument = await openAPIGenerator
|
|
193
|
-
.generationAndValidation()
|
|
194
|
-
.catch((err) => {
|
|
195
|
-
// expect(err.message).to.be.equal(
|
|
196
|
-
// `Error validating OpenAPI Description:\r\nThe operation does not define the path parameter \`{name}\` expected by path \`/find/{name}\`.`
|
|
197
|
-
// );
|
|
198
|
-
expect(err).to.have.property("message");
|
|
199
|
-
expect(err.message).to.include(
|
|
200
|
-
"Error validating OpenAPI Description:"
|
|
201
|
-
);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
expect(succSpy.called).to.be.false;
|
|
205
|
-
expect(errSpy.called).to.be.true;
|
|
206
|
-
|
|
207
|
-
succSpy.restore();
|
|
208
|
-
errSpy.restore();
|
|
209
|
-
getAllFuncsStub.reset();
|
|
210
|
-
getFuncStub.reset();
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe("createPostman", () => {
|
|
215
|
-
it("should generate a postman collection when a valid OpenAPI file is generated", function () {
|
|
216
|
-
const fsStub = sinon.stub(fs, "writeFileSync").returns(true);
|
|
217
|
-
const succSpy = sinon.spy(logOutput.log, "success");
|
|
218
|
-
const errSpy = sinon.spy(logOutput.log, "error");
|
|
219
|
-
const openAPIGenerator = new OpenAPIGenerator(sls, {}, logOutput);
|
|
220
|
-
openAPIGenerator.processCliInput();
|
|
221
|
-
|
|
222
|
-
openAPIGenerator.createPostman(validOpenAPI);
|
|
223
|
-
|
|
224
|
-
expect(fsStub.called).to.be.true;
|
|
225
|
-
expect(succSpy.calledTwice).to.be.true;
|
|
226
|
-
expect(errSpy.called).to.be.false;
|
|
227
|
-
fsStub.restore();
|
|
228
|
-
succSpy.restore();
|
|
229
|
-
errSpy.restore();
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it("should throw an error when writing a file fails", function () {
|
|
233
|
-
const errStub = sinon.stub(logOutput.log, "error").returns("");
|
|
234
|
-
const succSpy = sinon.spy(logOutput.log, "success");
|
|
235
|
-
const fsStub = sinon
|
|
236
|
-
.stub(fs, "writeFileSync")
|
|
237
|
-
.throws(new Error("throwing an error from writeFileSync"));
|
|
238
|
-
const openAPIGenerator = new OpenAPIGenerator(sls, {}, logOutput);
|
|
239
|
-
openAPIGenerator.processCliInput();
|
|
240
|
-
|
|
241
|
-
expect(() => {
|
|
242
|
-
openAPIGenerator.createPostman(validOpenAPI);
|
|
243
|
-
}).to.throw();
|
|
244
|
-
|
|
245
|
-
expect(fsStub.called).to.be.true;
|
|
246
|
-
expect(errStub.called).to.be.true;
|
|
247
|
-
expect(succSpy.calledOnce).to.be.true;
|
|
248
|
-
expect(succSpy.calledTwice).to.be.false;
|
|
249
|
-
fsStub.restore();
|
|
250
|
-
succSpy.restore();
|
|
251
|
-
errStub.restore();
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it("should throw an error converting an OpenAPI fails", function () {
|
|
255
|
-
const errStub = sinon.spy(logOutput.log, "error");
|
|
256
|
-
const succSpy = sinon.spy(logOutput.log, "success");
|
|
257
|
-
const pgStub = sinon.stub(PostmanGenerator, "convert");
|
|
258
|
-
pgStub.yields(new Error("throwing an error from PostmanGenerator"));
|
|
259
|
-
|
|
260
|
-
const openAPIGenerator = new OpenAPIGenerator(sls, {}, logOutput);
|
|
261
|
-
openAPIGenerator.processCliInput();
|
|
262
|
-
|
|
263
|
-
expect(() => {
|
|
264
|
-
openAPIGenerator.createPostman(validOpenAPI);
|
|
265
|
-
}).to.throw();
|
|
266
|
-
|
|
267
|
-
expect(errStub.called).to.be.true;
|
|
268
|
-
expect(succSpy.calledOnce).to.be.false;
|
|
269
|
-
expect(succSpy.calledTwice).to.be.false;
|
|
270
|
-
|
|
271
|
-
succSpy.restore();
|
|
272
|
-
errStub.restore();
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
});
|
package/test/unit/owasp.spec.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const expect = require("chai").expect;
|
|
4
|
-
const nock = require("nock");
|
|
5
|
-
|
|
6
|
-
const owasp = require("../../src/owasp");
|
|
7
|
-
|
|
8
|
-
const owaspJSON = require("../../json/owasp.json");
|
|
9
|
-
const newOWASPJSON = require("../json/newOWASP.json");
|
|
10
|
-
|
|
11
|
-
describe(`owasp`, function () {
|
|
12
|
-
describe(`getLatest`, function () {
|
|
13
|
-
it(`populates the defaults from the included OWASP release when the online version can not be reached`, async function () {
|
|
14
|
-
nock("https://owasp.org")
|
|
15
|
-
.get("/www-project-secure-headers/ci/headers_add.json")
|
|
16
|
-
.reply(404, {});
|
|
17
|
-
|
|
18
|
-
await owasp.getLatest().catch((err) => {
|
|
19
|
-
console.error(err);
|
|
20
|
-
expect(err).to.be.undefined;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
expect(
|
|
24
|
-
owasp.DEFAULT_OWASP_HEADERS["Permissions-Policy"]
|
|
25
|
-
).to.have.property("schema");
|
|
26
|
-
const permissionsPolicyDefault = owaspJSON.headers.filter(
|
|
27
|
-
(obj) => obj.name === "Permissions-Policy"
|
|
28
|
-
);
|
|
29
|
-
expect(
|
|
30
|
-
owasp.DEFAULT_OWASP_HEADERS["Permissions-Policy"].schema.default
|
|
31
|
-
).to.be.equal(permissionsPolicyDefault[0].value);
|
|
32
|
-
expect(Object.keys(owasp.DEFAULT_OWASP_HEADERS).length).to.be.equal(13);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it(`populates the defaults with information from a new OWASP release`, async function () {
|
|
36
|
-
nock("https://owasp.org")
|
|
37
|
-
.get("/www-project-secure-headers/ci/headers_add.json")
|
|
38
|
-
.reply(200, newOWASPJSON);
|
|
39
|
-
|
|
40
|
-
await owasp.getLatest().catch((err) => {
|
|
41
|
-
console.error(err);
|
|
42
|
-
expect(err).to.be.undefined;
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
expect(
|
|
46
|
-
owasp.DEFAULT_OWASP_HEADERS["Cross-Origin-Embedder-Policy"]
|
|
47
|
-
).to.have.property("schema");
|
|
48
|
-
const newCrossOriginEmbedderPolicy = newOWASPJSON.headers.filter(
|
|
49
|
-
(obj) => obj.name === "Cross-Origin-Embedder-Policy"
|
|
50
|
-
);
|
|
51
|
-
expect(
|
|
52
|
-
owasp.DEFAULT_OWASP_HEADERS["Cross-Origin-Embedder-Policy"].schema
|
|
53
|
-
.default
|
|
54
|
-
).to.be.equal(newCrossOriginEmbedderPolicy[0].value);
|
|
55
|
-
expect(Object.keys(owasp.DEFAULT_OWASP_HEADERS).length).to.be.equal(13);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it(`adds any properties contained in a new release`, async function () {
|
|
59
|
-
const newOWASPJSONAdded = structuredClone(newOWASPJSON);
|
|
60
|
-
newOWASPJSONAdded.headers.push({ name: "x-added", value: "true" });
|
|
61
|
-
|
|
62
|
-
nock("https://owasp.org")
|
|
63
|
-
.get("/www-project-secure-headers/ci/headers_add.json")
|
|
64
|
-
.reply(200, newOWASPJSONAdded);
|
|
65
|
-
|
|
66
|
-
await owasp.getLatest().catch((err) => {
|
|
67
|
-
console.error(err);
|
|
68
|
-
expect(err).to.be.undefined;
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
expect(owasp.DEFAULT_OWASP_HEADERS).to.have.property("x-added");
|
|
72
|
-
expect(owasp.DEFAULT_OWASP_HEADERS["x-added"]).to.have.property("schema");
|
|
73
|
-
expect(owasp.DEFAULT_OWASP_HEADERS["x-added"].schema.default).to.be.equal(
|
|
74
|
-
"true"
|
|
75
|
-
);
|
|
76
|
-
expect(Object.keys(owasp.DEFAULT_OWASP_HEADERS).length).to.be.equal(14);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe(`getHeaders`, function () {
|
|
81
|
-
it(`brings back default headers from a list`, function () {
|
|
82
|
-
const headerOptions = { cacheControl: true, xFrameOptions: true };
|
|
83
|
-
const headers = owasp.getHeaders(headerOptions);
|
|
84
|
-
|
|
85
|
-
expect(Object.keys(headers).length).to.be.equal(2);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it(`brings back default headers from a list with new schema defaults when values are provided`, function () {
|
|
89
|
-
const headerOptions = {
|
|
90
|
-
referrerPolicy: {
|
|
91
|
-
value: "true",
|
|
92
|
-
},
|
|
93
|
-
crossOriginOpenerPolicy: {
|
|
94
|
-
value: "strict",
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const headers = owasp.getHeaders(headerOptions);
|
|
99
|
-
|
|
100
|
-
expect(Object.keys(headers).length).to.be.equal(2);
|
|
101
|
-
|
|
102
|
-
expect(headers["Cross-Origin-Opener-Policy"].schema.default === "strict");
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it(`handles pragma being deprecated`, function () {
|
|
106
|
-
const headerOptions = {
|
|
107
|
-
pragma: {
|
|
108
|
-
value: "true",
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const headers = owasp.getHeaders(headerOptions);
|
|
113
|
-
|
|
114
|
-
expect(Object.keys(headers).length).to.be.equal(1);
|
|
115
|
-
|
|
116
|
-
expect(headers["Pragma"]).to.have.property("schema");
|
|
117
|
-
expect(headers["Pragma"].schema).to.have.property("default", "true");
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|