-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.js
68 lines (60 loc) · 2.29 KB
/
validate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* eslint-disable linebreak-style */
/* eslint-disable no-param-reassign */
/* eslint-disable dot-notation */
/* eslint-disable no-console */
const { toLower } = require('./convert');
/**
* Validates the client_id parameter is the expected value.
* @param {*} clientIdValue The value to validate.
* @returns Boolean. Returns true if the parameter was a valid value, otherwise false.
*/
function isValidClientId(clientIdValue) {
// SECURITY: Replace with stronger client id. :)
const clientIdPrefix = '3';
return clientIdValue && clientIdValue.startsWith(clientIdPrefix);
}
/**
* Validates the client_secret parameter is the expected value.
* @param {*} clientSecretValue The value to validate.
* @returns Boolean. Returns true if the parameter was a valid value, otherwise false.
*/
function isValidClientSecret(clientSecretValue) {
// SECURITY: Replace with stronger client secret. :)
const clientSecretPrefix = 'T';
return clientSecretValue && clientSecretValue.startsWith(clientSecretPrefix);
}
/**
* Validates the redirect_uri parameter is the expected value.
* @param {*} redirectUriValue The value to validate.
* @returns Boolean. Returns true if the parameter was a valid value, otherwise false.
*/
function isValidRedirectUri(redirectUriValue) {
// SECURITY: Replace with uri validation rules.
return redirectUriValue && toLower(redirectUriValue).startsWith('http');
}
/**
* Validate the make parameter is an expected value.
* @param {*} makeValue The value to validate.
* @returns Boolean. Returns true if the parameter was a valid value, otherwise false.
*/
function isValidMake(makeValue) {
if (makeValue === undefined) {
return false;
}
makeValue = toLower(makeValue);
return makeValue === 'f' || makeValue === 'ford' || makeValue === 'l' || makeValue === 'lincoln';
}
/**
* Validate the year parameter is in the expected range.
* @param {*} yearValue The value to validate.
* @returns Boolean. Returns true if the parameter was a valid value, otherwise false.
*/
function isValidYear(yearValue) {
const year = parseInt(yearValue, 10);
return year >= 2010;
}
exports.isValidClientId = isValidClientId;
exports.isValidClientSecret = isValidClientSecret;
exports.isValidRedirectUri = isValidRedirectUri;
exports.isValidMake = isValidMake;
exports.isValidYear = isValidYear;