Initial commit
This commit is contained in:
88
node_modules/@zeit/schemas/test/deployment-env.js
generated
vendored
Normal file
88
node_modules/@zeit/schemas/test/deployment-env.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
/* eslint camelcase: 0 */
|
||||
const AJV = require('ajv');
|
||||
const assert = require('assert');
|
||||
const {
|
||||
EnvKeys,
|
||||
EnvObject
|
||||
} = require('../deployment/config-env');
|
||||
|
||||
const ajv = new AJV({allErrors: true});
|
||||
|
||||
// EnvKeys
|
||||
exports.test_env_keys_valid = () => {
|
||||
const isValid = ajv.validate(EnvKeys, [
|
||||
'FOO',
|
||||
'BAR'
|
||||
]);
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_env_keys_too_short = () => {
|
||||
const isValid = ajv.validate(EnvKeys, [
|
||||
'FOO',
|
||||
''
|
||||
]);
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors[0].keyword, 'minLength');
|
||||
};
|
||||
|
||||
exports.test_env_keys_too_long = () => {
|
||||
const isValid = ajv.validate(EnvKeys, [
|
||||
'FOO',
|
||||
'A'.repeat(257)
|
||||
]);
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors[0].keyword, 'maxLength');
|
||||
};
|
||||
|
||||
exports.test_env_keys_invalid_chars = () => {
|
||||
const isValid = ajv.validate(EnvKeys, [
|
||||
'FOO',
|
||||
'BA,D'
|
||||
]);
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors[0].keyword, 'pattern');
|
||||
};
|
||||
|
||||
exports.test_env_keys_invalid_type = () => {
|
||||
const isValid = ajv.validate(EnvKeys, [
|
||||
'FOO',
|
||||
true
|
||||
]);
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors[0].keyword, 'type');
|
||||
};
|
||||
|
||||
exports.test_env_keys_non_unique = () => {
|
||||
const isValid = ajv.validate(EnvKeys, [
|
||||
'FOO',
|
||||
'FOO'
|
||||
]);
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors[0].keyword, 'uniqueItems');
|
||||
};
|
||||
|
||||
// EnvObject
|
||||
exports.test_env_object_valid = () => {
|
||||
const isValid = ajv.validate(EnvObject, {
|
||||
FOO: 'BAR',
|
||||
BAZ: '@secret'
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_env_object_bad_type = () => {
|
||||
const isValid = ajv.validate(EnvObject, {
|
||||
FOO: true
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors[0].keyword, 'type');
|
||||
};
|
||||
|
||||
exports.test_env_object_too_long = () => {
|
||||
const isValid = ajv.validate(EnvObject, {
|
||||
FOO: 'a'.repeat(70000)
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors[0].keyword, 'maxLength');
|
||||
};
|
||||
299
node_modules/@zeit/schemas/test/deployment.js
generated
vendored
Normal file
299
node_modules/@zeit/schemas/test/deployment.js
generated
vendored
Normal file
@@ -0,0 +1,299 @@
|
||||
/* eslint camelcase: 0 */
|
||||
const AJV = require('ajv');
|
||||
const assert = require('assert');
|
||||
const deploymentConfigSchema = require('../deployment/config');
|
||||
|
||||
const ajv = new AJV({allErrors: true});
|
||||
|
||||
exports.test_unknown_keys = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
foo: 1,
|
||||
bar: 2
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors.length, 2);
|
||||
['foo', 'bar'].forEach((prop, i) => {
|
||||
const error = ajv.errors[i];
|
||||
assert.equal(error.keyword, 'additionalProperties');
|
||||
assert.equal(error.params.additionalProperty, prop);
|
||||
});
|
||||
};
|
||||
|
||||
exports.test_features_object = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
features: {
|
||||
foo: 'v2',
|
||||
bar: 2
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_slot_key = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
features: {
|
||||
cloud: 'v2'
|
||||
},
|
||||
slot: 'c.125-m512'
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_staging_slot_key = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
features: {
|
||||
cloud: 'v2'
|
||||
},
|
||||
slot: 'staging-c.5-t1-w-m1024'
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_invalid_slot_key = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
features: {
|
||||
cloud: 'v2'
|
||||
},
|
||||
slot: 'invalid-key'
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
};
|
||||
|
||||
exports.test_slot_key_without_cloud_v2 = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
slot: 'c.125-m512'
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
};
|
||||
|
||||
exports.test_invalid_features_object = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
features: {
|
||||
foo: []
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
};
|
||||
|
||||
exports.test_features_object = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
limits: {
|
||||
duration: 60000,
|
||||
maxConcurrentReqs: 2,
|
||||
timeout: 60000 * 2
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_invalid_limits_object = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
limits: {
|
||||
foo: []
|
||||
}
|
||||
});
|
||||
assert.equal(!isValid, true);
|
||||
};
|
||||
|
||||
exports.test_valid_env_types = () => {
|
||||
let isValid = ajv.validate(deploymentConfigSchema, {
|
||||
env: {
|
||||
VALID: '1'
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
|
||||
isValid = ajv.validate(deploymentConfigSchema, {
|
||||
env: [
|
||||
'VALID'
|
||||
]
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_invalid_env_types = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
env: {
|
||||
INVALID: true
|
||||
}
|
||||
});
|
||||
assert.equal(!isValid, true);
|
||||
};
|
||||
|
||||
exports.test_valid_build_env_types = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
build: {
|
||||
env: {
|
||||
VALID: '1'
|
||||
}
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_invalid_build_env_types = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
build: {
|
||||
env: {
|
||||
INVALID: true
|
||||
}
|
||||
}
|
||||
});
|
||||
assert.equal(!isValid, true);
|
||||
};
|
||||
|
||||
exports.test_invalid_static_object = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
'static': {
|
||||
foo: []
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
};
|
||||
|
||||
exports.test_valid_static_headers_object = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
'static': {
|
||||
headers: [
|
||||
{
|
||||
source: '/_next/webpack/chunks/*',
|
||||
headers: [{
|
||||
key: 'Cache-Control',
|
||||
value: 'adssds'
|
||||
}]
|
||||
},
|
||||
{
|
||||
source: '/_next/static/commons/**',
|
||||
headers: [{
|
||||
key: 'Cache-Control',
|
||||
value: 'public, max-age=31536000, immutable'
|
||||
}]
|
||||
},
|
||||
{
|
||||
source: '/_next/*/page/**/*.js',
|
||||
headers: [{
|
||||
key: 'Cache-Control',
|
||||
value: 'public, max-age=31536000, immutable'
|
||||
}]
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_invalid_static_headers_object = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
'static': {
|
||||
headers: [
|
||||
{
|
||||
source: '/_next/webpack/chunks/*',
|
||||
headers: [{
|
||||
key: ':alternate-protocol',
|
||||
value: 'foo\x00bar'
|
||||
}]
|
||||
},
|
||||
{
|
||||
source: '/_next/static/commons/**',
|
||||
headers: [{
|
||||
key: 'Cache-Control',
|
||||
value: 'public, max-age=31536000, immutable'
|
||||
}]
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(isValid, false);
|
||||
};
|
||||
|
||||
exports.test_valid_static_object_trailing_slash = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
'static': {
|
||||
trailingSlash: true
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_valid_static_object_invalid_prop = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
'static': {
|
||||
trailingSlash: []
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
};
|
||||
|
||||
exports.test_github_enabled = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
github: {
|
||||
enabled: false
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_github_aliasing = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
github: {
|
||||
aliasing: false
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_github_auto_alias = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
github: {
|
||||
autoAlias: false
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_github_additional_field = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
github: {
|
||||
abc: 'bbc'
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
};
|
||||
|
||||
exports.test_scale_sfo1 = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
scale: {
|
||||
sfo1: {
|
||||
min: 0,
|
||||
max: 1
|
||||
}
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_scale_all = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
scale: {
|
||||
all: {
|
||||
min: 0,
|
||||
max: 'auto'
|
||||
}
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, true);
|
||||
};
|
||||
|
||||
exports.test_scale_invalid = () => {
|
||||
const isValid = ajv.validate(deploymentConfigSchema, {
|
||||
scale: {
|
||||
foo: {
|
||||
min: -1,
|
||||
max: 'auto'
|
||||
}
|
||||
}
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
};
|
||||
129
node_modules/@zeit/schemas/test/user.js
generated
vendored
Normal file
129
node_modules/@zeit/schemas/test/user.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
/* eslint camelcase: 0 */
|
||||
const AJV = require('ajv');
|
||||
const assert = require('assert');
|
||||
const {User} = require('../user');
|
||||
|
||||
const ajv = new AJV({allErrors: true});
|
||||
|
||||
// Username
|
||||
exports.test_username_null = () => {
|
||||
const isValid = ajv.validate(User, {
|
||||
username: null
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors.length, 1);
|
||||
assert.equal(ajv.errors[0].dataPath, '.username');
|
||||
assert.equal(ajv.errors[0].message, 'should be string');
|
||||
};
|
||||
|
||||
exports.test_username_invalid_pattern = () => {
|
||||
const isValid = ajv.validate(User, {
|
||||
username: '!!!'
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors.length, 1);
|
||||
assert.equal(ajv.errors[0].dataPath, '.username');
|
||||
assert.equal(ajv.errors[0].message, 'should match pattern "^[a-z][a-z0-9_-]*$"');
|
||||
};
|
||||
|
||||
exports.test_username_too_short = () => {
|
||||
const isValid = ajv.validate(User, {
|
||||
username: ''
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors.length, 2);
|
||||
assert.equal(ajv.errors[0].dataPath, '.username');
|
||||
assert.equal(ajv.errors[0].message, 'should NOT be shorter than 1 characters');
|
||||
assert.equal(ajv.errors[1].dataPath, '.username');
|
||||
assert.equal(ajv.errors[1].message, 'should match pattern "^[a-z][a-z0-9_-]*$"');
|
||||
};
|
||||
|
||||
exports.test_username_too_long = () => {
|
||||
const isValid = ajv.validate(User, {
|
||||
username: 'a'.repeat(50)
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors.length, 1);
|
||||
assert.equal(ajv.errors[0].dataPath, '.username');
|
||||
assert.equal(ajv.errors[0].message, 'should NOT be longer than 48 characters');
|
||||
};
|
||||
|
||||
exports.test_username_valid = () => {
|
||||
assert(ajv.validate(User, {username: 'n8'}));
|
||||
assert(ajv.validate(User, {username: 'rauchg'}));
|
||||
};
|
||||
|
||||
// Name
|
||||
exports.test_name_too_short = () => {
|
||||
const isValid = ajv.validate(User, {
|
||||
name: ''
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors.length, 1);
|
||||
assert.equal(ajv.errors[0].dataPath, '.name');
|
||||
assert.equal(ajv.errors[0].message, 'should NOT be shorter than 1 characters');
|
||||
};
|
||||
|
||||
exports.test_name_too_long = () => {
|
||||
const isValid = ajv.validate(User, {
|
||||
name: 'a'.repeat(50)
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors.length, 1);
|
||||
assert.equal(ajv.errors[0].dataPath, '.name');
|
||||
assert.equal(ajv.errors[0].message, 'should NOT be longer than 32 characters');
|
||||
};
|
||||
|
||||
exports.test_name_valid = () => {
|
||||
assert(ajv.validate(User, {name: 'Nate'}));
|
||||
};
|
||||
|
||||
// BillingChecked
|
||||
exports.test_billing_checked_null = () => {
|
||||
const isValid = ajv.validate(User, {
|
||||
billingChecked: null
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors.length, 1);
|
||||
assert.equal(ajv.errors[0].dataPath, '.billingChecked');
|
||||
assert.equal(ajv.errors[0].message, 'should be boolean');
|
||||
};
|
||||
|
||||
exports.test_billing_checked_valid = () => {
|
||||
assert(ajv.validate(User, {billingChecked: true}));
|
||||
};
|
||||
|
||||
// Avatar
|
||||
exports.test_avatar_too_short = () => {
|
||||
const isValid = ajv.validate(User, {
|
||||
avatar: 'abc'
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors.length, 1);
|
||||
assert.equal(ajv.errors[0].dataPath, '.avatar');
|
||||
assert.equal(ajv.errors[0].message, 'should NOT be shorter than 40 characters');
|
||||
};
|
||||
|
||||
exports.test_avatar_too_long = () => {
|
||||
const isValid = ajv.validate(User, {
|
||||
avatar: 'a'.repeat(50)
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors.length, 1);
|
||||
assert.equal(ajv.errors[0].dataPath, '.avatar');
|
||||
assert.equal(ajv.errors[0].message, 'should NOT be longer than 40 characters');
|
||||
};
|
||||
|
||||
exports.test_avatar_invalid = () => {
|
||||
const isValid = ajv.validate(User, {
|
||||
avatar: 'n'.repeat(40)
|
||||
});
|
||||
assert.equal(isValid, false);
|
||||
assert.equal(ajv.errors.length, 1);
|
||||
assert.equal(ajv.errors[0].dataPath, '.avatar');
|
||||
assert.equal(ajv.errors[0].message, 'should match pattern "^[0-9a-f]+$"');
|
||||
};
|
||||
|
||||
exports.test_avatar_valid = () => {
|
||||
assert(ajv.validate(User, {avatar: 'a'.repeat(40)}));
|
||||
};
|
||||
Reference in New Issue
Block a user