Skip to content

Commit

Permalink
Improve validation of ROOT_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
zodern committed Feb 11, 2017
1 parent bd363b0 commit 5852db8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Displays better message if it can not find the meteor app
- Displays message if can not find pem for server
- Improve validating server's `host` in config
- Validator checks for `http://` or `https://` in `ROOT_URL`
- Update documentation on using `mup` on Windows

# 1.2.1
Expand Down
51 changes: 34 additions & 17 deletions src/validate/meteor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ const schema = joi.object().keys({
allowIncompatibleUpdates: joi.boolean(),
executable: joi.string()
}),
env: joi.object().keys({
'ROOT_URL': joi.string().required(),
'MONGO_URL': joi.string()
}).pattern(/[\s\S]*/, [joi.string(), joi.number()]),
env: joi
.object()
.keys({
ROOT_URL: joi
.string()
.regex(new RegExp('^(http|https)://', 'i'))
.required(),
MONGO_URL: joi.string()
})
.pattern(/[\s\S]*/, [joi.string(), joi.number()]),
log: joi.object().keys({
driver: joi.string(),
opts: joi.object()
Expand All @@ -36,30 +42,41 @@ const schema = joi.object().keys({
nginx: joi.object().keys({
clientUploadLimit: joi.string().trim()
}),
ssl: joi.object().keys({
autogenerate: joi.object().keys({
email: joi.string().email().required(),
domains: joi.string().required()
}).label('autogenerate'),
crt: joi.string().trim(),
key: joi.string().trim(),
port: joi.number()
}).and('crt', 'key')
ssl: joi
.object()
.keys({
autogenerate: joi
.object()
.keys({
email: joi.string().email().required(),
domains: joi.string().required()
})
.label('autogenerate'),
crt: joi.string().trim(),
key: joi.string().trim(),
port: joi.number()
})
.and('crt', 'key')
.without('autogenerate', ['crt', 'key'])
.or('crt', 'autogenerate')
.label('ssl')
});

export default function (config) {
export default function(config) {
let details = [];
// console.log( joi.validate(config.meteor, schema, {convert: false}))
details = combineErrorDetails(details, joi.validate(config.meteor, schema, {convert: false}));
details = combineErrorDetails(
details,
joi.validate(config.meteor, schema, { convert: false })
);
if (config.meteor.name.indexOf(' ') > -1) {
details.push({
message: '"name" has a space'
});
}
details = combineErrorDetails(details, serversExist(config.servers, config.meteor.servers));
details = combineErrorDetails(
details,
serversExist(config.servers, config.meteor.servers)
);

return addLocation(details, 'meteor');
}

0 comments on commit 5852db8

Please sign in to comment.