serverless-finch
Advanced tools
Comparing version 4.0.3 to 4.0.4
'use strict'; | ||
const fs = require('fs'); | ||
const is = require('is_js'); | ||
const path = require('path'); | ||
@@ -15,3 +14,3 @@ | ||
if (!is.object(options)) { | ||
if (!isObject(options)) { | ||
validationErrors.push('Options must be an object defined under `custom.client`'); | ||
@@ -29,3 +28,3 @@ throw validationErrors; | ||
// bucketName must be a string | ||
if (!is.string(options.bucketName)) { | ||
if (typeof options.bucketName !== 'string') { | ||
validationErrors.push('Please specify a bucket name for the client in serverless.yml'); | ||
@@ -36,3 +35,3 @@ } | ||
if (options.objectHeaders) { | ||
if (!is.object(options.objectHeaders)) { | ||
if (!isObject(options.objectHeaders)) { | ||
validationErrors.push('objectHeaders must be an object'); | ||
@@ -42,3 +41,3 @@ } | ||
Object.keys(options.objectHeaders).forEach(p => { | ||
if (!is.array(options.objectHeaders[p])) { | ||
if (!Array.isArray(options.objectHeaders[p])) { | ||
validationErrors.push('Each member of objectHeaders must be an array'); | ||
@@ -48,7 +47,7 @@ } | ||
options.objectHeaders[p].forEach(h => { | ||
if (!(is.existy(h.name) && is.string(h.name))) { | ||
if (typeof h.name !== 'string') { | ||
validationErrors.push(`Each object header must have a (string) 'name' attribute`); | ||
} | ||
if (!(is.existy(h.value) && is.string(h.value))) { | ||
if (typeof h.value !== 'string') { | ||
validationErrors.push(`Each object header must have a (string) 'value' attribute`); | ||
@@ -88,15 +87,15 @@ } | ||
const clientConfigOptions = Object.keys(options); | ||
if (is.inArray('indexDocument', clientConfigOptions)) { | ||
if (clientConfigOptions.includes('indexDocument')) { | ||
validationErrors.push('indexDocument cannot be specified with redirectAllRequestsTo'); | ||
} | ||
if (is.inArray('errorDocument', clientConfigOptions)) { | ||
if (clientConfigOptions.includes('errorDocument')) { | ||
validationErrors.push('errorDocument cannot be specified with redirectAllRequestsTo'); | ||
} | ||
if (is.inArray('routingRules', clientConfigOptions)) { | ||
if (clientConfigOptions.includes('routingRules')) { | ||
validationErrors.push('routingRules cannot be specified with redirectAllRequestsTo'); | ||
} | ||
if (!is.existy(options.redirectAllRequestsTo.hostName)) { | ||
if (!options.redirectAllRequestsTo.hostName) { | ||
validationErrors.push( | ||
@@ -106,3 +105,3 @@ 'redirectAllRequestsTo.hostName is required if redirectAllRequestsTo is specified' | ||
} | ||
if (!is.string(options.redirectAllRequestsTo.hostName)) { | ||
if (typeof options.redirectAllRequestsTo.hostName !== 'string') { | ||
validationErrors.push('redirectAllRequestsTo.hostName must be a string'); | ||
@@ -112,6 +111,6 @@ } | ||
if (options.redirectAllRequestsTo.protocol) { | ||
if (!is.string(options.redirectAllRequestsTo.protocol)) { | ||
if (typeof options.redirectAllRequestsTo.protocol !== 'string') { | ||
validationErrors.push('redirectAllRequestsTo.protocol must be a string'); | ||
} | ||
if (!is.inArray(options.redirectAllRequestsTo.protocol.toLowerCase(), ['http', 'https'])) { | ||
if (!['http', 'https'].includes(options.redirectAllRequestsTo.protocol.toLowerCase())) { | ||
validationErrors.push('redirectAllRequestsTo.protocol must be either http or https'); | ||
@@ -123,3 +122,3 @@ } | ||
if (options.routingRules) { | ||
if (!is.array(options.routingRules)) { | ||
if (!Array.isArray(options.routingRules)) { | ||
validationErrors.push('routingRules must be a list'); | ||
@@ -129,7 +128,7 @@ } | ||
options.routingRules.forEach(r => { | ||
if (!is.existy(r.redirect)) { | ||
if (!r.redirect) { | ||
validationErrors.push('redirect must be specified for each member of routingRules'); | ||
} | ||
if (is.existy(r.redirect.replaceKeyPrefixWith) && is.existy(r.redirect.replaceKeyWith)) { | ||
if (r.redirect.replaceKeyPrefixWith && r.redirect.replaceKeyWith) { | ||
validationErrors.push( | ||
@@ -150,3 +149,3 @@ 'replaceKeyPrefixWith and replaceKeyWith cannot both be specified for a member of member of routingRules' | ||
if (p === 'httpRedirectCode') { | ||
if (!is.integer(r.redirect[p])) { | ||
if (!Number.isInteger(r.redirect[p])) { | ||
validationErrors.push( | ||
@@ -157,3 +156,3 @@ 'redirect.httpRedirectCode must be an integer for each member of routingRules' | ||
} else { | ||
if (!is.string(r.redirect[p])) { | ||
if (typeof r.redirect[p] !== 'string') { | ||
validationErrors.push( | ||
@@ -168,8 +167,3 @@ `redirect.${p} must be a string for each member of routingRules` | ||
if (r.condition) { | ||
if ( | ||
!( | ||
is.existy(r.condition.httpErrorCodeReturnedEquals) || | ||
is.existy(r.condition.keyPrefixEquals) | ||
) | ||
) { | ||
if (!r.condition.httpErrorCodeReturnedEquals && !r.condition.keyPrefixEquals) { | ||
validationErrors.push( | ||
@@ -184,7 +178,7 @@ 'condition.httpErrorCodeReturnedEquals or condition.keyPrefixEquals must be defined for each member of routingRules' | ||
if (p === 'httpErrorCodeReturnedEquals') { | ||
if (!is.integer(r.condition[p])) { | ||
if (!Number.isInteger(r.condition[p])) { | ||
validationErrors.push('httpErrorCodeReturnedEquals must be an integer'); | ||
} | ||
} else { | ||
if (!is.string(r.condition[p])) { | ||
if (typeof r.condition[p] !== 'string') { | ||
validationErrors.push(`${p} must be a string`); | ||
@@ -204,2 +198,6 @@ } | ||
function isObject(value) { | ||
return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
} | ||
module.exports = validateClient; |
@@ -76,2 +76,56 @@ const chai = require('chai'); | ||
it('throws if redirectAllRequestsTo is missing hostName', () => { | ||
expect(() => validate(sls, { bucketName, redirectAllRequestsTo: {} })).to.throw(); | ||
expect(() => | ||
validate(sls, { bucketName, redirectAllRequestsTo: { hostName: 'example.com' } }) | ||
).not.to.throw(); | ||
}); | ||
it('throws if redirectAllRequestsTo has invalid protocol', () => { | ||
expect(() => | ||
validate(sls, { | ||
bucketName, | ||
redirectAllRequestsTo: { hostName: 'example.com', protocol: 'ftp' } | ||
}) | ||
).to.throw(); | ||
expect(() => | ||
validate(sls, { | ||
bucketName, | ||
redirectAllRequestsTo: { hostName: 'example.com', protocol: true } | ||
}) | ||
).to.throw(); | ||
expect(() => | ||
validate(sls, { | ||
bucketName, | ||
redirectAllRequestsTo: { hostName: 'example.com', protocol: 'http' } | ||
}) | ||
).not.to.throw(); | ||
expect(() => | ||
validate(sls, { | ||
bucketName, | ||
redirectAllRequestsTo: { hostName: 'example.com', protocol: 'https' } | ||
}) | ||
).not.to.throw(); | ||
}); | ||
it('throws if redirectAllRequestsTo is specified along with other website options', () => { | ||
const redirectAllRequestsTo = { | ||
hostName: 'example.com', | ||
protocol: 'https' | ||
}; | ||
expect(() => | ||
validate(sls, { bucketName, redirectAllRequestsTo, indexDocument: 'index.html' }) | ||
).to.throw(); | ||
expect(() => | ||
validate(sls, { bucketName, redirectAllRequestsTo, errorDocument: 'error.html' }) | ||
).to.throw(); | ||
expect(() => | ||
validate(sls, { | ||
bucketName, | ||
redirectAllRequestsTo, | ||
routingRules: { redirect: { replaceKeyWith: '' } } | ||
}) | ||
).to.throw(); | ||
}); | ||
it('throws if reading `corsFile` fails or contains invalid json', () => { | ||
@@ -78,0 +132,0 @@ readFileSyncStub.withArgs('nonexistent-file.json').throws(); |
{ | ||
"name": "serverless-finch", | ||
"version": "4.0.3", | ||
"version": "4.0.4", | ||
"engines": { | ||
@@ -41,3 +41,2 @@ "node": ">=14.15.5" | ||
"@serverless/utils": "^6.0.2", | ||
"is_js": "^0.9.0", | ||
"mime": "^3.0.0", | ||
@@ -44,0 +43,0 @@ "minimatch": "^5.0.1" |
96290
3
1837
- Removedis_js@^0.9.0
- Removedis_js@0.9.0(transitive)