How to use the joi.forbidden function in joi

To help you get started, we’ve selected a few joi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github muoncore / muon-node / muon / transport / amqp / transport-helper.js View on Github external
var uuid = require('node-uuid');
var Joi = require('joi');
require('sexylog');
var messages = require('../../domain/messages.js');

// Regular expressions for transport message format:
var reply_queue_regex = /[a-z0-9\-]\.reply\.[a-zA-Z0-9\-]/;
var listen_queue_regex = /[a-z0-9\-]\.listen\.[a-zA-Z0-9\-]/;

var transportMessageSchema = Joi.object().keys({
   data: Joi.any().required(),
   properties: Joi.object().optional(),
   headers:  Joi.object({
       handshake: Joi.string().min(3).regex(/(initiated|accepted)/).optional(),
       protocol: Joi.alternatives().when('handshake', { is: 'initiated', then: Joi.string().required(), otherwise: Joi.string().optional() }),
       server_reply_q: Joi.alternatives().when('handshake', { is: 'initiated', then: Joi.string().required(), otherwise: Joi.forbidden() }),
       server_listen_q: Joi.alternatives().when('handshake', { is: 'initiated', then: Joi.string().required(), otherwise: Joi.forbidden() }),
       content_type: Joi.string().min(10).regex(/[a-z\.]\/[a-z\.]/).optional(),
   }).required()
});

exports.serviceNegotiationQueueName = function(serviceName) {

    var serviceQueueName = "service." + serviceName;
    return serviceQueueName;
}


exports.queueSettings = function() {
    var queueSettings = {
         durable: false,
         type: "direct",
github Twipped / joi-to-swagger / tests.js View on Github external
{ type: 'number', format: 'float' }
	);


	simpleTest(
		joi.object({
			req: joi.string().required(),
			forbiddenAny: joi.forbidden(),
			forbiddenString: joi.string().forbidden(),
			forbiddenNumber: joi.number().forbidden(),
			forbiddenBoolean: joi.boolean().forbidden(),
			forbiddenBinary: joi.binary().forbidden(),
			maybeRequiredOrForbidden: joi.number().when('someField', {
				is: true,
				then: joi.required(),
				otherwise: joi.forbidden(),
			})
				.meta({ swaggerIndex: 1 }),
		}),
		{ type: 'object', required: [ 'req' ], properties: { req: { type: 'string' } } }
	);


	simpleTest(
		joi.object().keys({
			id: joi.number().integer().required(),
			name: joi.string(),
		}),
		{
			type: 'object',
			required: [ 'id' ],
			properties: {
github rethinkdb / horizon / server / src / schema / horizon_protocol.js View on Github external
'use strict';

const Joi = require('joi');

const handshake = Joi.object().keys({
  request_id: Joi.number().required(),
  method: Joi.only('token', 'anonymous', 'unauthenticated').required(),
  token: Joi.string().required()
    .when('method', { is: Joi.not('token').required(), then: Joi.forbidden() }),
}).unknown(false);

const read = Joi.alternatives().try(
  Joi.object().keys({
    collection: Joi.string().token().required(),
    find: Joi.object().min(1).unknown(true).required(),
  }).unknown(false),
  Joi.object().keys({
    collection: Joi.string().token().required(),

    limit: Joi.number().integer().greater(-1).optional()
      .when('find', { is: Joi.any().required(), then: Joi.forbidden() }),

    order: Joi.array().ordered(
        Joi.array().items(Joi.string()).min(1).unique().label('fields').required(),
        Joi.string().valid('ascending', 'descending').label('direction').required()).optional()
github contentful / contentful-import / lib / utils / schema.js View on Github external
sys: Joi.object(),
  fields: Joi.object()
}

const contentTypeSchema = {
  sys: Joi.object(),
  fields: Joi.array().required().items(Joi.object().keys({
    id: Joi.string().required(),
    name: Joi.string().required(),
    type: Joi.string().required().regex(/^Symbol|Text|Integer|Number|Date|Object|Boolean|Array|Link|Location$/),
    validations: Joi.array(),
    disabled: Joi.boolean(),
    omitted: Joi.boolean(),
    required: Joi.boolean(),
    localized: Joi.boolean(),
    linkType: Joi.string().when('type', {is: 'Link', then: Joi.string().regex(/^Asset|Entry$/), otherwise: Joi.forbidden()})
  }))
}

const assetSchema = {
  sys: Joi.object(),
  fields: Joi.object({
    file: Joi.object().pattern(/.+/, Joi.object({
      url: Joi.string().required(),
      details: Joi.object({
        size: Joi.number(),
        image: Joi.object({
          width: Joi.number(),
          height: Joi.number()
        })}),
      fileName: Joi.string().required(),
      contentType: Joi.string().required()
github clarkie / dynogels / lib / schema.js View on Github external
'use strict';

const Joi = require('joi');
const nodeUUID = require('uuid');
const _ = require('lodash');

const internals = {};

internals.secondaryIndexSchema = Joi.object().keys({
  hashKey: Joi.string().when('type', { is: 'local', then: Joi.ref('$hashKey'), otherwise: Joi.required() }),
  rangeKey: Joi.string().when('type', { is: 'local', then: Joi.required(), otherwise: Joi.optional() }),
  type: Joi.string().valid('local', 'global').required(),
  name: Joi.string().required(),
  projection: Joi.object(),
  readCapacity: Joi.number().when('type', { is: 'global', then: Joi.optional(), otherwise: Joi.forbidden() }),
  writeCapacity: Joi.number().when('type', { is: 'global', then: Joi.optional(), otherwise: Joi.forbidden() })
});

internals.configSchema = Joi.object().keys({
  hashKey: Joi.string().required(),
  rangeKey: Joi.string(),
  tableName: Joi.alternatives().try(Joi.string(), Joi.func()),
  indexes: Joi.array().items(internals.secondaryIndexSchema),
  schema: Joi.object(),
  timestamps: Joi.boolean().default(false),
  createdAt: Joi.alternatives().try(Joi.string(), Joi.boolean()),
  updatedAt: Joi.alternatives().try(Joi.string(), Joi.boolean()),
  log: Joi.object({
    info: Joi.func(),
    warn: Joi.func(),
  }).optional().unknown(),
github elastic / kibana / x-pack / legacy / plugins / siem / server / lib / detection_engine / routes / schemas / add_prepackaged_rules_schema.ts View on Github external
export const addPrepackagedRulesSchema = Joi.object({
  description: description.required(),
  enabled: enabled.default(false),
  false_positives: false_positives.default([]),
  filters,
  from: from.required(),
  rule_id: rule_id.required(),
  immutable: immutable.default(true),
  index,
  interval: interval.default('5m'),
  query: query.allow('').default(''),
  language: language.default('kuery'),
  saved_id: saved_id.when('type', {
    is: 'saved_query',
    then: Joi.required(),
    otherwise: Joi.forbidden(),
  }),
  timeline_id,
  meta,
  risk_score: risk_score.required(),
  max_signals: max_signals.default(DEFAULT_MAX_SIGNALS),
  name: name.required(),
  severity: severity.required(),
  tags: tags.default([]),
  to: to.required(),
  type: type.required(),
  threats: threats.default([]),
  references: references.default([]),
  version: version.required(),
});
github mozilla / fxa-oauth-server / lib / routes / authorization.js View on Github external
is: CODE,
          then: Joi.optional(),
          otherwise: Joi.forbidden()
        }),
      code_challenge: Joi.string()
        .length(PKCE_CODE_CHALLENGE_LENGTH)
        .when('response_type', {
          is: CODE,
          then: Joi.optional(),
          otherwise: Joi.forbidden()
        }),
      derivedKeyBundle: Joi.string()
        .when('response_type', {
          is: CODE,
          then: Joi.optional(),
          otherwise: Joi.forbidden()
        })
    }
  },
  response: {
    schema: Joi.object().keys({
      redirect: Joi.string(),
      access_token: validators.token,
      token_type: Joi.string().valid('bearer'),
      scope: Joi.string().allow(''),
      auth_at: Joi.number(),
      expires_in: Joi.number()
    }).without('redirect', [
      'access_token'
    ]).with('access_token', [
      'token_type',
      'scope',
github mozilla / fxa-auth-server / fxa-oauth-server / lib / routes / token.js View on Github external
access_type: Joi.string()
    .valid(ACCESS_TYPE_OFFLINE, ACCESS_TYPE_ONLINE)
    .default(ACCESS_TYPE_ONLINE)
    .optional()
    .when('grant_type', {
      is: GRANT_FXA_ASSERTION,
      otherwise: Joi.forbidden()
    }),
  code: Joi.string()
    .length(config.get('unique.code') * 2)
    .regex(validators.HEX_STRING)
    .required()
    .when('grant_type', {
      is: GRANT_AUTHORIZATION_CODE,
      otherwise: Joi.forbidden()
    }),

  code_verifier: validators.codeVerifier
    .when('code', {
      is: Joi.string().required(),
      otherwise: Joi.forbidden()
    }),

  refresh_token: validators.token
    .required()
    .when('grant_type', {
      is: GRANT_REFRESH_TOKEN,
      otherwise: Joi.forbidden()
    }),

  assertion: validators.assertion
github academia-de-codigo / noire-server / lib / modules / authorization / routes / web-tls / profile.js View on Github external
handler: ProfileCtrl.update,
    auth: {
        scope: 'user'
    },
    plugins: {
        stateless: false
    },
    validate: {
        payload: {
            id: Joi.forbidden(),
            username: Joi.string().min(User.USERNAME_MIN_LENGTH).max(User.USERNAME_MAX_LENGTH).required(),
            name: Joi.string().min(User.NAME_MIN_LENGTH).max(User.NAME_MAX_LENGTH),
            email: Joi.string().email(),
            password: Joi.string().min(User.PASSWORD_MIN_LENGTH).max(User.PASSWORD_MAX_LENGTH),
            active: Joi.boolean(),
            roles: Joi.forbidden()
        }
    }
};
github mozilla / thimble.mozilla.org / services / id.webmaker.org / web / server.js View on Github external
{
      method: 'POST',
      path: '/login/oauth/access_token',
      config: {
        validate: {
          payload: {
            grant_type: Joi.any().valid('authorization_code', 'password').required(),
            code: Joi.string().when('grant_type', {
              is: 'authorization_code',
              then: Joi.required(),
              otherwise: Joi.forbidden()
            }),
            client_secret: Joi.string().when('grant_type', {
              is: 'authorization_code',
              then: Joi.required(),
              otherwise: Joi.forbidden()
            }),
            client_id: Joi.string().required(),
            uid: Joi.string().when('grant_type', {
              is: 'password',
              then: Joi.required(),
              otherwise: Joi.forbidden()
            }),
            password: Joi.string().when('grant_type', {
              is: 'password',
              then: Joi.required(),
              otherwise: Joi.forbidden()
            }),
            scopes: Joi.string().when('grant_type', {
              is: 'password',
              then: Joi.required(),
              otherwise: Joi.forbidden()