How to use assert-plus - 10 common examples

To help you get started, we’ve selected a few assert-plus 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 joyent / manatee / lib / adm.js View on Github external
function translateHistoryNode(opts, cb) {
    assert.object(opts, 'opts');
    assert.object(opts.zkClient, 'opts.zkClient');
    assert.string(opts.zkPath, 'opts.zkPath');
    assert.string(opts.zkNode, 'opts.zkNode');

    // Old entries look like timestamp-ip-role-master-slave-zkseq from zk.
    // New Entries look like generation-zkseq
    var fNode = opts.zkNode.split('-');
    if (fNode.length > 2) {
        return (cb(null, oldHistoryToObj(fNode)));
    }

    var p = opts.zkPath + '/' + opts.zkNode;
    opts.zkClient.getData(p, function (err, data, stat) {
        if (err) {
            return (cb(err));
        }
        var time = bignum.fromBuffer(stat.ctime).toNumber();
github charlielin99 / Jobalytics / node_modules / sshpk / lib / formats / x509.js View on Github external
der._offset += der.length;
	}

	/* extensions */
	if (der.peek() === Local(3)) {
		der.readSequence(Local(3));
		var extEnd = der.offset + der.length;
		der.readSequence();

		while (der.offset < extEnd)
			readExtension(cert, buf, der);

		assert.strictEqual(der.offset, extEnd);
	}

	assert.strictEqual(der.offset, sigOffset);

	der.readSequence();
	after = der.offset + der.length;
	var sigAlgOid = der.readOID();
	var sigAlg = SIGN_ALGS[sigAlgOid];
	if (sigAlg === undefined)
		throw (new Error('unknown signature algorithm ' + sigAlgOid));
	der._offset = after;

	var sigData = der.readString(asn1.Ber.BitString, true);
	if (sigData[0] === 0)
		sigData = sigData.slice(1);
	var algParts = sigAlg.split('-');

	sig.signature = Signature.parse(sigData, algParts[0], 'asn1');
	sig.signature.hashAlgorithm = algParts[1];
github ashiq-r31 / PWA-Sushi-Hunt / node_modules / sshpk / lib / formats / pem.js View on Github external
function read(buf, options, forceType) {
	var input = buf;
	if (typeof (buf) !== 'string') {
		assert.buffer(buf, 'buf');
		buf = buf.toString('ascii');
	}

	var lines = buf.trim().split('\n');

	var m = lines[0].match(/*JSSTYLED*/
	    /[-]+[ ]*BEGIN ([A-Z0-9][A-Za-z0-9]+ )?(PUBLIC|PRIVATE) KEY[ ]*[-]+/);
	assert.ok(m, 'invalid PEM header');

	var m2 = lines[lines.length - 1].match(/*JSSTYLED*/
	    /[-]+[ ]*END ([A-Z0-9][A-Za-z0-9]+ )?(PUBLIC|PRIVATE) KEY[ ]*[-]+/);
	assert.ok(m2, 'invalid PEM footer');

	/* Begin and end banners must match key type */
	assert.equal(m[2], m2[2]);
	var type = m[2].toLowerCase();
github joyent / sdc-docker / lib / config-loader.js View on Github external
assert.object(opts.log, 'opts.log');

    var configPath = path.resolve(__dirname, '..', 'etc', 'config.json');
    opts.log.info('Loading config from "%s"', configPath);
    var config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));

    // config-agent doesn't support arrays so ENABLED_LOG_DRIVERS is stored
    // as a comma-separated list in a string. We'll unmangle that here and
    // make sure that no driver was specified that doesn't actually exist.
    if (config.enabledLogDrivers) {
        assert.string(config.enabledLogDrivers, 'config.enabledLogDrivers-raw');
        config.enabledLogDrivers = config.enabledLogDrivers.split(',');
    } else {
        config.enabledLogDrivers = ['json-file'];
    }
    assert.arrayOfString(config.enabledLogDrivers, 'config.enabledLogDrivers');
    config.enabledLogDrivers.forEach(function _checkLogDriver(driver) {
        assert.ok(common.LOG_DRIVERS.hasOwnProperty(driver),
            'config.enabledLogDrivers.' + driver + ' is not a valid driver');
    });

    if (config.hasOwnProperty('fwrule_version')) {
        assert.number(config.fwrule_version, 'config.fwrule_version');
    } else {
        config.fwrule_version = 1;
    }

    if (config.dcMaintEta) {
        var d = new Date(config.dcMaintEta);
        if (d.toString() !== 'Invalid Date') {
            config.dcMaintUtcEta = d.toUTCString();
        }
github joyent / smartos-live / src / img / node_modules / imgmanifest / lib / imgmanifest.js View on Github external
function imgUuidFromDockerDigests(digests) {
    assert.arrayOfString(digests, 'digests');

    // Sanity check the digests.
    var badDigests = digests.filter(function (d) {
        var sp = d.split(':');
        if (sp.length !== 2 || sp[0] !== 'sha256' || sp[1].length !== 64) {
            return true;
        }
        return false;
    });
    if (badDigests.length > 0) {
        throw new Error(
            'docker digests should be of the form "sha256:xxx", got: ' +
            badDigests);
    }

    var sha256sum = crypto.createHash('sha256');
github joyent / buildymcbuildface / lib / imgadm / lib / cli.js View on Github external
CLI.prototype.do_ancestry = function do_ancestry(subcmd, opts, args, cb) {
    var self = this;
    if (opts.help) {
        self.do_help('help', {}, [subcmd], cb);
        return;
    }
    if (args.length !== 1) {
        cb(new errors.UsageError(format(
            'incorrect number of args (%d): "%s"',
            args.length, args.join(' '))));
        return;
    }
    var uuid = args[0];
    assert.uuid(uuid, 'uuid');
    var zpool = opts.P || self.tool.DEFAULT_ZPOOL;
    /* JSSTYLED */
    var columns = opts.o.trim().split(/\s*,\s*/g);
    var log = self.log;
    log.debug({opts: opts, zpool: zpool, uuid: uuid}, 'ancestry');

    var ancestry = [];
    getNextAncestor(uuid);


    function getNextAncestor(aUuid) {
        var getOpts = {uuid: aUuid, zpool: zpool};
        self.tool.getImage(getOpts, function (err, imageInfo) {
            if (err) {
                cb(err);
                return;
github joyent / moray / lib / objects / common.js View on Github external
function buildWhereClause(opts, cb) {
    assert.object(opts, 'options');
    assert.object(opts.bucket, 'options.bucket');
    assert.object(opts.filter, 'options.filter');
    assert.object(opts.log, 'options.log');
    assert.object(opts.opts, 'options.opts');
    assert.func(cb, 'callback');

    var f = opts.filter;
    var log = opts.log;
    var o = opts.opts;
    var where = 'WHERE ';
    var sort = '';
    var args = [];
    var sql;

    // Query only against fields with valid indices
    var b = opts.idxBucket;

    function append(item) {
        if (item.attribute) {
            if (sort.length > 0) {
github restify / clients / lib / HttpClient.js View on Github external
var startRequestTimeout = function startRequestTimeout() {
        // the request object must already exist before we can set a timeout
        // on it.
        assert.object(req, 'req');

        if (opts.requestTimeout) {
            requestTimer = setTimeout(function requestTimeout() {
                requestTimer = null;

                var err = errors.createRequestTimeoutErr(opts, req);
                req._forcedAbortErr = err;
                req.abort();
            }, opts.requestTimeout);
        }
    };
github davidhealey / waistline / node_modules / npm / node_modules / request / node_modules / http-signature / node_modules / sshpk / lib / signature.js View on Github external
function parseOneNum(data, type, format, opts, headType) {
	if (format === 'ssh') {
		try {
			var buf = new SSHBuffer({buffer: data});
			var head = buf.readString();
		} catch (e) {
			/* fall through */
		}
		if (head === headType) {
			var sig = buf.readPart();
			assert.ok(buf.atEnd(), 'extra trailing bytes');
			sig.name = 'sig';
			opts.parts.push(sig);
			return (new Signature(opts));
		}
	}
	opts.parts.push({name: 'sig', data: data});
	return (new Signature(opts));
}
github joyent / smartos-live / src / img / node_modules / docker-registry-client / lib / index.js View on Github external
function login(opts, cb) {
    assert.object(opts, 'opts');
    assert.string(opts.username, 'opts.username');
    assert.string(opts.password, 'opts.password');
    assert.optionalString(opts.email, 'opts.email');
    assert.func(cb, 'cb');

    reg2.ping(opts, function (pingErr, body, pingRes, req) {
        if (!pingRes) {
            assert.ok(pingErr, 'no err *or* res from v2 ping');
            cb(pingErr);
            return;
        }
        if (pingRes.statusCode === 404) {
            // The index doesn't support v2, so try v1 if we can.
            if (opts.email) {
                reg1.login(opts, cb);
            } else {
                cb(pingErr);
            }
        } else {
            reg2.login(common.objMerge({