diff --git a/api-docs/openapi.json b/api-docs/openapi.json index 51907b833..99dd14389 100644 --- a/api-docs/openapi.json +++ b/api-docs/openapi.json @@ -253,6 +253,32 @@ "responses": { "200": { "description": "The requested CVE ID information is returned", + "headers": { + "RateLimit-Limit": { + "schema": { + "type": "integer" + }, + "description": "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + "schema": { + "type": "string" + }, + "description": "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + "schema": { + "type": "integer" + }, + "description": "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + "schema": { + "type": "integer" + }, + "description": "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, "content": { "application/json": { "schema": { @@ -263,6 +289,32 @@ }, "400": { "description": "Bad Request", + "headers": { + "RateLimit-Limit": { + "schema": { + "type": "integer" + }, + "description": "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + "schema": { + "type": "string" + }, + "description": "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + "schema": { + "type": "integer" + }, + "description": "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + "schema": { + "type": "integer" + }, + "description": "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, "content": { "application/json": { "schema": { @@ -273,6 +325,32 @@ }, "401": { "description": "Not Authenticated", + "headers": { + "RateLimit-Limit": { + "schema": { + "type": "integer" + }, + "description": "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + "schema": { + "type": "string" + }, + "description": "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + "schema": { + "type": "integer" + }, + "description": "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + "schema": { + "type": "integer" + }, + "description": "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, "content": { "application/json": { "schema": { @@ -283,6 +361,32 @@ }, "403": { "description": "Forbidden", + "headers": { + "RateLimit-Limit": { + "schema": { + "type": "integer" + }, + "description": "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + "schema": { + "type": "string" + }, + "description": "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + "schema": { + "type": "integer" + }, + "description": "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + "schema": { + "type": "integer" + }, + "description": "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, "content": { "application/json": { "schema": { @@ -293,6 +397,32 @@ }, "404": { "description": "Not Found", + "headers": { + "RateLimit-Limit": { + "schema": { + "type": "integer" + }, + "description": "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + "schema": { + "type": "string" + }, + "description": "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + "schema": { + "type": "integer" + }, + "description": "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + "schema": { + "type": "integer" + }, + "description": "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, "content": { "application/json": { "schema": { @@ -303,6 +433,32 @@ }, "429": { "description": "Too Many Requests", + "headers": { + "RateLimit-Limit": { + "schema": { + "type": "integer" + }, + "description": "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + "schema": { + "type": "string" + }, + "description": "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + "schema": { + "type": "integer" + }, + "description": "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + "schema": { + "type": "integer" + }, + "description": "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, "content": { "application/json": { "schema": { @@ -313,6 +469,32 @@ }, "500": { "description": "Internal Server Error", + "headers": { + "RateLimit-Limit": { + "schema": { + "type": "integer" + }, + "description": "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + "schema": { + "type": "string" + }, + "description": "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + "schema": { + "type": "integer" + }, + "description": "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + "schema": { + "type": "integer" + }, + "description": "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, "content": { "application/json": { "schema": { @@ -552,6 +734,32 @@ }, "400": { "description": "Bad Request", + "headers": { + "RateLimit-Limit": { + "schema": { + "type": "integer" + }, + "description": "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + "schema": { + "type": "string" + }, + "description": "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + "schema": { + "type": "integer" + }, + "description": "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + "schema": { + "type": "integer" + }, + "description": "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, "content": { "application/json": { "schema": { @@ -562,6 +770,32 @@ }, "403": { "description": "Forbidden", + "headers": { + "RateLimit-Limit": { + "schema": { + "type": "integer" + }, + "description": "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + "schema": { + "type": "string" + }, + "description": "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + "schema": { + "type": "integer" + }, + "description": "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + "schema": { + "type": "integer" + }, + "description": "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, "content": { "application/json": { "schema": { @@ -582,6 +816,32 @@ }, "429": { "description": "Too Many Requests", + "headers": { + "RateLimit-Limit": { + "schema": { + "type": "integer" + }, + "description": "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + "schema": { + "type": "string" + }, + "description": "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + "schema": { + "type": "integer" + }, + "description": "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + "schema": { + "type": "integer" + }, + "description": "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, "content": { "application/json": { "schema": { @@ -592,6 +852,32 @@ }, "500": { "description": "Internal Server Error", + "headers": { + "RateLimit-Limit": { + "schema": { + "type": "integer" + }, + "description": "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + "schema": { + "type": "string" + }, + "description": "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + "schema": { + "type": "integer" + }, + "description": "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + "schema": { + "type": "integer" + }, + "description": "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, "content": { "application/json": { "schema": { diff --git a/package-lock.json b/package-lock.json index e2b632f09..b07c98a0a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "JSONStream": "^1.3.5", "kleur": "^4.1.4", "lodash": "^4.17.21", + "luxon": "^3.4.4", "mongo-cursor-pagination": "^8.1.3", "mongoose": "^5.13.20", "mongoose-aggregate-paginate-v2": "1.0.6", @@ -36,7 +37,6 @@ "swagger-autogen": "^2.19.0", "swagger-ui-express": "^4.3.0", "uuid": "^8.3.2", - "validate-date": "^2.0.0", "validator": ">=13.7.0", "winston": "^3.2.1", "yamljs": "^0.3.0" @@ -5673,6 +5673,14 @@ "yallist": "^3.0.2" } }, + "node_modules/luxon": { + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.4.tgz", + "integrity": "sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA==", + "engines": { + "node": ">=12" + } + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -9838,11 +9846,6 @@ "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", "dev": true }, - "node_modules/validate-date": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/validate-date/-/validate-date-2.0.0.tgz", - "integrity": "sha512-DmRIajI6qR/j3JibfDaQsar2IYIUdRUPRBgo/M/kcl6CR5aWb3CsNTX2tdgu2KD3oAMpfXfuJncP30Z3xNHAJg==" - }, "node_modules/validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", @@ -14584,6 +14587,11 @@ "yallist": "^3.0.2" } }, + "luxon": { + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.4.tgz", + "integrity": "sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA==" + }, "make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -17704,11 +17712,6 @@ "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", "dev": true }, - "validate-date": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/validate-date/-/validate-date-2.0.0.tgz", - "integrity": "sha512-DmRIajI6qR/j3JibfDaQsar2IYIUdRUPRBgo/M/kcl6CR5aWb3CsNTX2tdgu2KD3oAMpfXfuJncP30Z3xNHAJg==" - }, "validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", diff --git a/package.json b/package.json index e85f8f2b0..a44d1aa33 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "JSONStream": "^1.3.5", "kleur": "^4.1.4", "lodash": "^4.17.21", + "luxon": "^3.4.4", "mongo-cursor-pagination": "^8.1.3", "mongoose": "^5.13.20", "mongoose-aggregate-paginate-v2": "1.0.6", @@ -54,7 +55,6 @@ "swagger-autogen": "^2.19.0", "swagger-ui-express": "^4.3.0", "uuid": "^8.3.2", - "validate-date": "^2.0.0", "validator": ">=13.7.0", "winston": "^3.2.1", "yamljs": "^0.3.0" diff --git a/src/controller/cve-id.controller/index.js b/src/controller/cve-id.controller/index.js index 0ab114d0c..93819b48d 100644 --- a/src/controller/cve-id.controller/index.js +++ b/src/controller/cve-id.controller/index.js @@ -208,6 +208,32 @@ router.get('/cve-id/:id', ] #swagger.responses[200] = { description: 'The requested CVE ID information is returned', + headers: { + "RateLimit-Limit": { + schema: { + type: "integer" + }, + description: "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + schema: { + type: "string" + }, + description: "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + schema: { + type: "integer" + }, + description: "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + schema: { + type: "integer" + }, + description: "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, content: { "application/json": { schema: { $ref: '../schemas/cve-id/get-cve-id-response.json' } @@ -216,6 +242,32 @@ router.get('/cve-id/:id', } #swagger.responses[400] = { description: 'Bad Request', + headers: { + "RateLimit-Limit": { + schema: { + type: "integer" + }, + description: "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + schema: { + type: "string" + }, + description: "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + schema: { + type: "integer" + }, + description: "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + schema: { + type: "integer" + }, + description: "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, content: { "application/json": { schema: { $ref: '../schemas/errors/bad-request.json' } @@ -224,6 +276,32 @@ router.get('/cve-id/:id', } #swagger.responses[401] = { description: 'Not Authenticated', + headers: { + "RateLimit-Limit": { + schema: { + type: "integer" + }, + description: "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + schema: { + type: "string" + }, + description: "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + schema: { + type: "integer" + }, + description: "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + schema: { + type: "integer" + }, + description: "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, content: { "application/json": { schema: { $ref: '../schemas/errors/generic.json' } @@ -232,6 +310,32 @@ router.get('/cve-id/:id', } #swagger.responses[403] = { description: 'Forbidden', + headers: { + "RateLimit-Limit": { + schema: { + type: "integer" + }, + description: "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + schema: { + type: "string" + }, + description: "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + schema: { + type: "integer" + }, + description: "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + schema: { + type: "integer" + }, + description: "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, content: { "application/json": { schema: { $ref: '../schemas/errors/generic.json' } @@ -240,6 +344,32 @@ router.get('/cve-id/:id', } #swagger.responses[404] = { description: 'Not Found', + headers: { + "RateLimit-Limit": { + schema: { + type: "integer" + }, + description: "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + schema: { + type: "string" + }, + description: "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + schema: { + type: "integer" + }, + description: "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + schema: { + type: "integer" + }, + description: "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, content: { "application/json": { schema: { $ref: '../schemas/errors/generic.json' } @@ -248,6 +378,32 @@ router.get('/cve-id/:id', } #swagger.responses[429] = { description: 'Too Many Requests', + headers: { + "RateLimit-Limit": { + schema: { + type: "integer" + }, + description: "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + schema: { + type: "string" + }, + description: "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + schema: { + type: "integer" + }, + description: "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + schema: { + type: "integer" + }, + description: "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, content: { "application/json": { schema: { $ref: '../schemas/errors/generic.json' } @@ -256,6 +412,32 @@ router.get('/cve-id/:id', } #swagger.responses[500] = { description: 'Internal Server Error', + headers: { + "RateLimit-Limit": { + schema: { + type: "integer" + }, + description: "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + schema: { + type: "string" + }, + description: "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + schema: { + type: "integer" + }, + description: "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + schema: { + type: "integer" + }, + description: "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, content: { "application/json": { schema: { $ref: '../schemas/errors/generic.json' } diff --git a/src/controller/cve.controller/index.js b/src/controller/cve.controller/index.js index eba11d177..a2a9cb95a 100644 --- a/src/controller/cve.controller/index.js +++ b/src/controller/cve.controller/index.js @@ -41,6 +41,32 @@ router.get('/cve/:id', #swagger.responses[400] = { description: 'Bad Request', + headers: { + "RateLimit-Limit": { + schema: { + type: "integer" + }, + description: "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + schema: { + type: "string" + }, + description: "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + schema: { + type: "integer" + }, + description: "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + schema: { + type: "integer" + }, + description: "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, content: { "application/json": { schema: { $ref: '../schemas/errors/bad-request.json' } @@ -49,6 +75,32 @@ router.get('/cve/:id', } #swagger.responses[403] = { description: 'Forbidden', + headers: { + "RateLimit-Limit": { + schema: { + type: "integer" + }, + description: "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + schema: { + type: "string" + }, + description: "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + schema: { + type: "integer" + }, + description: "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + schema: { + type: "integer" + }, + description: "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, content: { "application/json": { schema: { $ref: '../schemas/errors/generic.json' } @@ -65,6 +117,32 @@ router.get('/cve/:id', } #swagger.responses[429] = { description: 'Too Many Requests', + headers: { + "RateLimit-Limit": { + schema: { + type: "integer" + }, + description: "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + schema: { + type: "string" + }, + description: "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + schema: { + type: "integer" + }, + description: "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + schema: { + type: "integer" + }, + description: "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, content: { "application/json": { schema: { $ref: '../schemas/errors/generic.json' } @@ -73,6 +151,32 @@ router.get('/cve/:id', } #swagger.responses[500] = { description: 'Internal Server Error', + headers: { + "RateLimit-Limit": { + schema: { + type: "integer" + }, + description: "Indicates the service limit associated with the client in the current time window. If the client exceeds that limit, it MAY not be served." + }, + "RateLimit-Policy": { + schema: { + type: "string" + }, + description: "Indicates a service policy currently associated with the client. Its value is informative." + }, + "RateLimit-Remaining": { + schema: { + type: "integer" + }, + description: "Indicates the remaining quota units associated with the expiring-limit. Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When the value of the remaining keyword is low, it indicates that the server may soon throttle the client." + }, + "RateLimit-Reset": { + schema: { + type: "integer" + }, + description: "Indicates the number of seconds until the available quota units associated with the expiring-limit resets." + } + }, content: { "application/json": { schema: { $ref: '../schemas/errors/generic.json' } diff --git a/src/utils/utils.js b/src/utils/utils.js index 650f4bd07..f6ec5d2a1 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -1,7 +1,7 @@ const Org = require('../model/org') const User = require('../model/user') const getConstants = require('../constants').getConstants -const validateDate = require('validate-date') +const { DateTime } = require('luxon') async function getOrgUUID (shortName) { const org = await Org.findOne().byShortName(shortName) @@ -140,16 +140,13 @@ function toDate (val) { if (value) { const dateStr = value[0] // Make sure that the string passed is a valid date - // eslint doesn't like that responseType is not defined, but it is needed as is - /* eslint-disable-next-line */ - const valid = validateDate(dateStr.toString().substring(0, 10), responseType = 'boolean') - if (valid) { + if (DateTime.fromISO(dateStr.toString()).isValid) { result = new Date(dateStr) } } else { value = val.match(/^\d{4}-\d{2}-\d{2}$/) /* eslint-disable-next-line */ - if ((value) && (validateDate(value.toString().substring(0, 10), responseType = 'boolean'))) { + if ((value) && DateTime.fromISO(dateStr.toString()).isValid) { result = new Date(`${value[0]}T00:00:00.000+00:00`) } } diff --git a/test/integration-tests/cve-id/getCveIdTest.js b/test/integration-tests/cve-id/getCveIdTest.js index 3eddba977..a86854634 100644 --- a/test/integration-tests/cve-id/getCveIdTest.js +++ b/test/integration-tests/cve-id/getCveIdTest.js @@ -100,5 +100,26 @@ describe('Testing Get CVE-ID endpoint', () => { expect(res.body.cve_ids).to.have.length(PUB_YEAR_COUNT) }) }) + it('Z format should be be valid', async () => { + await chai.request(app) + .get('/api/cve-id?time_modified.gt=2024-01-15T00:00:01-02:00') + .set(constants.headers) + .then((res, err) => { + expect(err).to.be.undefined + expect(res).to.have.status(200) + }) + }) + }) + context('negative tests', () => { + it('Feb 29 2100 should not be valid', async () => { + await chai.request(app) + .get('/api/cve-id?time_modified.gt=2100-02-29T00:00:00Z') + .set(constants.headers) + .then((res, err) => { + expect(err).to.be.undefined + expect(res).to.have.status(400) + expect(res.body.error).to.contain('BAD_INPUT') + }) + }) }) })