*
Unit tests for validating that access rules get correctly applied
(for the function applyAccessRules) from prepare.js.
480637
function createMockConfigAndManifestForApplyAccessRules (isWin10) {
    var rules = [];
    for (var i = 1; i < arguments.length; i++) {
        rules.push(arguments[i]);
    }

    var TEST_XML = '<?xml version="1.0" encoding="UTF-8"?>\n' +
    '<widget xmlns     = "http://www.w3.org/ns/widgets"\n' +
    '        xmlns:cdv = "http://cordova.apache.org/ns/1.0"\n' +
    '        id        = "org.apache.cordova.HelloCordova"\n' +
    '        version   = "1.0.0.0">\n' +
    '    <name>HelloCordova</name>\n' +
    '    <author href="http://cordova.io" email="dev@cordova.apache.org">\n' +
    '        Apache\n' +
    '    </author>\n' +
    '    <content src="index.html" />\n' +
    '</widget>\n';

    var origParseElementtreeSync = xml.parseElementtreeSync;
    spyOn(xml, 'parseElementtreeSync').and.callFake(function (path) {
        if (path === 'config.xml') return new et.ElementTree(et.XML(TEST_XML));
        return origParseElementtreeSync(path);
    });

    var config = new ConfigParser('config.xml');

    var origGetPreference = config.getPreference;
    spyOn(config, 'getPreference').and.callFake(function (prefName) {
        if (prefName === 'WindowsDefaultUriPrefix') {
            return isWin10 ? 'ms-appx-web://' : 'ms-appx://';
        }

        return origGetPreference.call(config, prefName);
    });

    config.getAccesses = function () {
        if (isWin10) {
            return [];
        }

        return rules.map(function (rule) {
            return { 'origin': rule };
        });
    };

    config.getAllowNavigations = function () {
        if (isWin10) {
            return rules.map(function (rule) {
                return { 'href': rule };
            });
        }

        return [];
    };

    var filePath = isWin10 ? Win10ManifestPath : Win81ManifestPath;
    var manifest = AppxManifest.get(filePath);
    spyOn(fs, 'writeFileSync');

    return { config: config, manifest: manifest };
}
813780
protected function validateAccessSettings()
    {
        $field = 'access';
        $rules = $this->getSubmitted($field);

        $errors = $converted = array();
        foreach (gplcart_string_explode_multiline($rules) as $line => $rule) {

            $line++;

            $parts = gplcart_string_explode_whitespace($rule, 2);

            if (count($parts) != 2) {
                $errors[] = $line;
                continue;
            }

            list($role_id, $pattern) = $parts;

            if (strlen(trim($pattern, '\\/')) != strlen($pattern)) {
                $errors[] = $line;
            }

            if (!$this->isValidRoleSettings($role_id)) {
                $errors[] = $line;
                continue;
            }

            $normalized_pattern = gplcart_path_normalize($pattern);

            if (!gplcart_string_is_regexp($normalized_pattern) || strlen($normalized_pattern) > 250) {
                $errors[] = $line;
                continue;
            }

            $converted[$role_id][] = $normalized_pattern;
        }

        if (!empty($errors)) {
            $error = $this->translation->text('Error on line @num', array('@num' => implode(',', $errors)));
            $this->setError($field, $error);
            return false;
        }

        $this->setSubmitted($field, $converted);
        return true;
    }
543110
public static void assertAccessibility(String htmlString, Testable testable) {
        assertThat(htmlString, is(compliantTo(testable)));
    }
675817
function validateRSAA(action) {
  var validationErrors = [];
  const validCallAPIKeys = [
    'endpoint',
    'options',
    'method',
    'body',
    'headers',
    'credentials',
    'bailout',
    'types',
    'fetch',
    'ok'
  ];
  const validMethods = [
    'GET',
    'HEAD',
    'POST',
    'PUT',
    'PATCH',
    'DELETE',
    'OPTIONS'
  ];
  const validCredentials = ['omit', 'same-origin', 'include'];

  if (!isRSAA(action)) {
    validationErrors.push(
      'RSAAs must be plain JavaScript objects with an [RSAA] property'
    );
    return validationErrors;
  }

  const callAPI = action[RSAA];
  if (!isPlainObject(callAPI)) {
    validationErrors.push('[RSAA] property must be a plain JavaScript object');
  }
  for (let key in callAPI) {
    if (!~validCallAPIKeys.indexOf(key)) {
      validationErrors.push(`Invalid [RSAA] key: ${key}`);
    }
  }

  const {
    endpoint,
    method,
    headers,
    options,
    credentials,
    types,
    bailout,
    fetch,
    ok
  } = callAPI;
  if (typeof endpoint === 'undefined') {
    validationErrors.push('[RSAA] must have an endpoint property');
  } else if (typeof endpoint !== 'string' && typeof endpoint !== 'function') {
    validationErrors.push(
      '[RSAA].endpoint property must be a string or a function'
    );
  }
  if (typeof method === 'undefined') {
    validationErrors.push('[RSAA] must have a method property');
  } else if (typeof method !== 'string') {
    validationErrors.push('[RSAA].method property must be a string');
  } else if (!~validMethods.indexOf(method.toUpperCase())) {
    validationErrors.push(`Invalid [RSAA].method: ${method.toUpperCase()}`);
  }

  if (
    typeof headers !== 'undefined' &&
    !isPlainObject(headers) &&
    typeof headers !== 'function'
  ) {
    validationErrors.push(
      '[RSAA].headers property must be undefined, a plain JavaScript object, or a function'
    );
  }
  if (
    typeof options !== 'undefined' &&
    !isPlainObject(options) &&
    typeof options !== 'function'
  ) {
    validationErrors.push(
      '[RSAA].options property must be undefined, a plain JavaScript object, or a function'
    );
  }
  if (typeof credentials !== 'undefined') {
    if (typeof credentials !== 'string') {
      validationErrors.push(
        '[RSAA].credentials property must be undefined, or a string'
      );
    } else if (!~validCredentials.indexOf(credentials)) {
      validationErrors.push(`Invalid [RSAA].credentials: ${credentials}`);
    }
  }
  if (
    typeof bailout !== 'undefined' &&
    typeof bailout !== 'boolean' &&
    typeof bailout !== 'function'
  ) {
    validationErrors.push(
      '[RSAA].bailout property must be undefined, a boolean, or a function'
    );
  }

  if (typeof types === 'undefined') {
    validationErrors.push('[RSAA] must have a types property');
  } else if (!Array.isArray(types) || types.length !== 3) {
    validationErrors.push('[RSAA].types property must be an array of length 3');
  } else {
    const [requestType, successType, failureType] = types;
    if (
      typeof requestType !== 'string' &&
      typeof requestType !== 'symbol' &&
      !isValidTypeDescriptor(requestType)
    ) {
      validationErrors.push('Invalid request type');
    }
    if (
      typeof successType !== 'string' &&
      typeof successType !== 'symbol' &&
      !isValidTypeDescriptor(successType)
    ) {
      validationErrors.push('Invalid success type');
    }
    if (
      typeof failureType !== 'string' &&
      typeof failureType !== 'symbol' &&
      !isValidTypeDescriptor(failureType)
    ) {
      validationErrors.push('Invalid failure type');
    }
  }

  if (typeof fetch !== 'undefined') {
    if (typeof fetch !== 'function') {
      validationErrors.push('[RSAA].fetch property must be a function');
    }
  }

  if (typeof ok !== 'undefined') {
    if (typeof ok !== 'function') {
      validationErrors.push('[RSAA].ok property must be a function');
    }
  }

  return validationErrors;
}
291859
def prepare(self,
            method=None, url=None, headers=None, files=None, data=None,
            params=None, auth=None, cookies=None, hooks=None, json=None):
        """"""

        self.prepare_method(method)
        self.prepare_url(url, params)
        self.prepare_headers(headers)
        self.prepare_cookies(cookies)
        self.prepare_body(data, files, json)
        self.prepare_auth(auth, url)

        # Note that prepare_auth must be last to enable authentication schemes
        # such as OAuth to work on a fully prepared request.

        # This MUST go after prepare_auth. Authenticators could add a hook
        self.prepare_hooks(hooks)
256170
function decorateAccess(proto, methods) {
		methods.forEach(function(method) {
			proto[method] = beforeaccess(proto[method]);
		});
	}
693789
protected function evaluateSafenessInJS()
	{
		// Test each value against the list of disallowed characters
		$disallowedChars = ContextSafeness::getDisallowedCharactersInJS();
		foreach ($this->vars['map'] as $value)
		{
			foreach ($disallowedChars as $char)
			{
				if (strpos($value, $char) !== false)
				{
					return;
				}
			}
		}

		$this->markAsSafeInJS();
	}
408498
function applied(fn, scope) {
    if (fn.wrappedInApply) {
      return fn;
    }
    var wrapped = function() {
      var args = arguments;
      var phase = scope.$root.$$phase;
      if (phase === "$apply" || phase === "$digest") {
        return fn.apply(null, args);
      } else {
        return scope.$apply(function() {
          return fn.apply( null, args );
        });
      }
    };
    wrapped.wrappedInApply = true;
    return wrapped;
  }
93934
function initAccessControl (args) {
    // get global access control instance
    var accessControl = ImmutableAccessControl.getGlobal()
    // check for deprecated access control
    if (defined(args.accessControl)) {
        throw new Error('model local accessControl is deprecated')
    }
    // check for deprecated access model if passed
    if (defined(args.accessModel)) {
        throw new Error('accessModel is deprecated')
    }
    // set access id column if passed
    if (args.accessIdName) {
        // set access id name
        this.accessIdName = args.accessIdName
        // get column spec
        var spec = this.columns[this.accessIdName]
        // column for access id name must exist
        this.assert(defined(spec), `column not defined for accessIdName ${args.accessIdName}`)
        // column must be id
        this.assert(spec.type === 'id', `accessIdName column ${args.accessIdName} must have type id`)
        // set access id name with access control provider
        accessControl.setAccessIdName(this.name, this.accessIdName)
    }
    // set default access id name o model
    else {
        // default is accountId if model has an account id
        this.accessIdName = this.defaultColumnsInverse.accountId ? 'accountId' : undefined
    }
    // if rules not passed skip adding
    if (!defined(args.accessControlRules)) {
        return
    }
    // require access control rules to be array
    this.assert(Array.isArray(args.accessControlRules), 'accessControlRules must be array')
    // add each access control rule
    _.each(args.accessControlRules, accessControlRule => {
        // if rule is a string then it is for `all` role
        if (typeof accessControlRule === 'string') {
            // prepend model:<modelName>: to rule
            accessControlRule = `model:${this.name}:${accessControlRule}`
            // add rule with all role
            accessControl.setRule(['all', accessControlRule], true)
        }
        // otherwise must be array with role(s) and rule as last element
        else if (Array.isArray(accessControlRule)) {
            // get index of last element
            var lastIdx = accessControlRule.length - 1
            // prepend model:<modelName>: to rule
            accessControlRule[lastIdx] = `model:${this.name}:${accessControlRule[lastIdx]}`
            // add rule
            accessControl.setRule(accessControlRule, true)
        }
        // error
        else {
            throw this.error('string or array required for accessControlRules element')
        }
    })
}
776281
function _traverseRules(sheet, base) {
            var i,
                href = sheet.href,
                cssRules;

            // Deal with Firefox's SecurityError when accessing sheets
            // from other domains. Chrome will safely return `undefined`.
            try {
                cssRules = sheet.cssRules;
            } catch (e) {
                if (e.name !== "SecurityError") {
                    throw e;
                }
            }

            if (href && cssRules) {
                if (rel.stylesheets[href] === undefined) {
                    rel.stylesheets[href] = [];
                }
                rel.stylesheets[href].push(base);

                for (i = 0; i < cssRules.length; i++) {
                    if (cssRules[i].href) {
                        traverseRules(cssRules[i].styleSheet, base);
                    }
                }
            }
        }
731366
function prepareRules(options, rules, defaultDir) {
  rules = u.findRules(options, rules, defaultDir);
  var anyStartRules = [];
  var anyEndRules = [];
  var typeToRules = {'': anyStartRules, 'end': anyEndRules};

  rules.forEach(function (rule) {
    var ruleTypes = rule.type || [];
    ruleTypes = Array.isArray(ruleTypes) ? ruleTypes : [ruleTypes];
    if (ruleTypes.length === 0) {
      ruleTypes.push('');
    }
    ruleTypes.forEach(function (ruleType) {
      if (ruleType === '') {
        anyStartRules.push(rule);
        // add this any rule to the end of any typed start rule lists
        Object.keys(typeToRules).forEach(function (key) {
          if (key !== '' && key !== 'end' && key.substring(0,4) !== 'end-') {
            typeToRules[key].push(rule);
          }
        });
      } else if (ruleType === 'end') {
        anyEndRules.push(rule);
        // add this any rule to the end of any typed end rule lists
        Object.keys(typeToRules).forEach(function (key) {
          if (key !== '' && key.substring(0,4) === 'end-') {
            typeToRules[key].push(rule);
          }
        });
      } else {
        if (!(ruleType in typeToRules)) {
          typeToRules[ruleType] = [];
          if (ruleType.substring(0,4) !== 'end-') {
            // put all preceding any start rules first
            typeToRules[ruleType] = [].concat(anyStartRules);
          } else {
            // put all preceding any end rules first
            typeToRules[ruleType] = [].concat(anyEndRules);
          }
        }
        typeToRules[ruleType].push(rule);
      }
    });
  });

  return typeToRules;
}
501782
function prepareLinkProofs(arrUnits, callbacks){
	if (!ValidationUtils.isNonemptyArray(arrUnits))
		return callbacks.ifError("no units array");
	if (arrUnits.length === 1)
		return callbacks.ifError("chain of one element");
	mutex.lock(['prepareLinkProofs'], function(unlock){
		var start_ts = Date.now();
		var arrChain = [];
		async.forEachOfSeries(
			arrUnits,
			function(unit, i, cb){
				if (i === 0)
					return cb();
				createLinkProof(arrUnits[i-1], arrUnits[i], arrChain, cb);
			},
			function(err){
				console.log("prepareLinkProofs for units "+arrUnits.join(', ')+" took "+(Date.now()-start_ts)+'ms, err='+err);
				err ? callbacks.ifError(err) : callbacks.ifOk(arrChain);
				unlock();
			}
		);
	});
}
1085551
function prepare (o) {
    try {
      var input = checkInput(o)
      var q = Queries.mkQuery(input)

      // we have win!
      return [q]
    } catch (err) {
      // other than spewing, we ignore errors
      console.error(err.stack)

      // so this request will be flatmapped away
      return []
    }
  }
696678
function checkAccessRights(req, res, next) {
	const uri = (typeof req.contextPath === "string" && req.baseUrl.substring(req.contextPath.length)) || req.baseUrl;
	req.user.checkRights(req.user.username, uri, req, res, next);
}
1364511
protected void arrangePreparedAccessContext(ActionRuntime runtime) { // called by callback
        final AccessContextResource resource = createAccessContextResource(runtime);
        final AccessContext accessContext = accessContextArranger.arrangePreparedAccessContext(resource);
        PreparedAccessContext.setAccessContextOnThread(accessContext);
    }
1214547
function validate(rules, args, cb) {
  try {
    _known(rules, args);
    _required(rules, args);

    Object.keys(args).forEach(function (arg) {

      var value = args[arg],
        ruleSet = rules[arg];

      try {
        ruleSet.forEach(function (rule) {
          if (rule !== 'required') {
            exports.checks[rule](value || '');
          }
        });
      } catch (e) {
        throw new Error(util.format(
          'Validation error - arg: %s, value: %s, desc: %s',
          arg, value, e.message));
      }
    });
    cb();
  } catch (e) {
    cb(e);
  }
}
1208824
function makeAccessController(rerun) {
  // `accesses` is a map indexed by object,
  // containing "access" entries with values of `{names: [], observer}`.
  // `names` of null means to watch properties of any name.
  // It is built by calls to `notifyAccess`, invoked through `accessNotifier`.
  var accesses = new Map();

  function unobserve() {
    accesses.forEach(({observer}) => observer.unobserve());
  }

  function observe() {
    accesses.forEach(({observer}) => observer.observe(['update', 'add', 'delete']));
  }

  // Start capturing accessed dependencies.
  function capture() {
    accesses.clear();
    accessNotifier.push(notifyAccess);
  }

  // Stop capturing accessed dependencies.
  function uncapture() {
    accessNotifier.pop();
  }

  function start() {
    unobserve();
    capture();
  }

  function stop() {
    uncapture();
    observe();
  }

  // `notifyAccess` is the callback invoked by upwardables when a property is accessed.
  // It records the access in the `accesses` map.
  function notifyAccess({object, name}) {

    // Create an observer for changes in properties accessed during execution of this function.
    function makeAccessedObserver() {
      return Observer(object, function(changes) {
        changes.forEach(({type, name}) => {
          var {names} = accessEntry;
          if (!names || type === 'update' && names.indexOf(name) !== -1)
            rerun();
        });
      });
    }

    // Make a new entry in the access table, containing initial property name if any
    // and observer for properties accessed on the object.
    function makeAccessEntry() {
      accesses.set(object, {
        names:    name ? [name] : null,
        observer: makeAccessedObserver()
      });
    }

    // If properties on this object are already being watched, there is already an entry
    // in the access table for it. Add a new property name to the existing entry.
    function setAccessEntry() {
      if (name && accessEntry.names) accessEntry.names.push(name);
      else accessEntry.names = null;
    }

    var accessEntry = accesses.get(object);
    if (accessEntry) setAccessEntry();
    else makeAccessEntry();
  }

  return {start, stop};
}