it("numericToAlpha3 276 => DEU", function() {
			assert.equal(i18niso.numericToAlpha3(276), "DEU");
		});
		it("toAlpha2 SGP => SGP", function() {
			assert.equal(i18niso.toAlpha3("SGP"), "SGP");
		});
		it("toAlpha2 XXX => undefined", function() {
			assert.equal(i18niso.toAlpha2("XXX"), undefined);
		});
			it("for CL", function () {
				assert.equal(i18niso.getName("CL", lang), "Chile");
			});
			it("for af", function () {
				assert.equal(i18niso.getName("af", lang), "Afghanistan");
			});
			it("for cy", function () {
				assert.equal(i18niso.getName("cy", lang), "Zypern");
			});
			it("nameToAlpha2 Brazil => BR", function() {
				assert.equal(i18niso.getAlpha2Code("Brazil", lang), "BR");
			});
Exemplo n.º 8
0
			logger.once("level_critical", function(log) {
				assert.equal(log.message, "message");
				done();
			});
Exemplo n.º 9
0
			logger.once("level_critical", function(log) {
				assert.equal(log.origin, "origin");
				assert.equal(log.message, "message");
				assert.deepEqual(log.metadata, {a: 1});
				done();
			});
Exemplo n.º 10
0
			logger.once("level_error", function(log) {
				assert.equal(log.message, "message");
				assert.deepEqual(log.metadata, {a: 1});
				done();
			});
Exemplo n.º 11
0
			logger.once("level_error", function(log) {
				assert.equal(log.message, "message");
				assert.equal(log.metadata.message, "test");
				assert.equal(log.metadata.type, "Error");
				done();
			});
Exemplo n.º 12
0
			logger.once("level_error", function(log) {
				assert.equal(log.origin, "origin");
				assert.equal(log.message, "message");
				done();
			});
Exemplo n.º 13
0
		mock.muc_calls.forEach(function (c) {
			assertplus.equal(c.method, 'exec');
		});
Exemplo n.º 14
0
function finishTest(testcase, exec, error, results, callback)
{
	var mock, expected;

	mock = exec.ce_urclient;
	assertplus.ok((error !== null && mock === null) ||
	    mock instanceof MockUrClient);

	if (testcase['error']) {
		nexecuted++;

		if (error === null) {
			console.error('expected error: ', testcase['error']);
			console.error('found no error');
			callback(new VError('missing expected error'));
		} else if (!testcase['error'].test(error.message)) {
			console.error('expected error: ', testcase['error']);
			console.error('found error: ', error.message);
			callback(new VError('wrong error'));
		} else {
			callback();
		}

		return;
	}

	if (error !== null) {
		nexecuted++;
		console.error('expected no error, but found one');
		console.error('found error: ', error);
		callback(new VError('unexpected error'));
		return;
	}

	expected = testcase['expected_results'];
	assertplus.equal(expected['count'], results.length);
	assertplus.equal(expected['count'], mock.muc_calls.length);

	if (expected['output']) {
		/*
		 * The expected results describe command output.  In that case,
		 * the only commands the mock Ur should have seen were exec's,
		 * we should have the expected number of results, and those
		 * results' output should reflect whether we expected in-zone
		 * output or global zone output.
		 */
		mock.muc_calls.forEach(function (c) {
			assertplus.equal(c.method, 'exec');
		});

		results.forEach(function (r) {
			assertplus.ok(r['uuid']);
			assertplus.ok(r['hostname']);
			if (expected['zone']) {
				assertplus.ok(r['zonename']);
				assertplus.ok(r['service'] == 'webapi' ||
				    r['service'] == 'postgres');
				assertplus.equal(
				    r['result']['stdout'], 'in zone');
			} else {
				assertplus.ok(!r['zonename']);
				assertplus.ok(!r['service']);
				assertplus.equal(r['result']['stdout'],
				    'global zone');
			}

			assertplus.equal(r['result']['exit_status'], 0);
			assertplus.equal(r['result']['stderr'].length, 0);
		});

		nexecuted++;
		callback();
		return;
	}

	/*
	 * The expected results describe a file transfer.  Check that the
	 * src_file, dst_file, and dst_dir properties were specified
	 * appropriately.
	 */
	mock.muc_calls.forEach(function (c) {
		assertplus.equal(c.method,
		    testcase['args']['execMode'] ==
		    oneach.MZ_EM_RECEIVEFROMREMOTE ? 'recv_file' : 'send_file');
		assertplus.equal(c.args.src_file, expected['src_file']);
		assertplus.equal(c.args.dst_dir, expected['dst_dir']);
		assertplus.equal(c.args.dst_file, expected['dst_file']);
	});
	nexecuted++;
	callback();
}
		it("missing land", function() {
			assert.equal(i18niso.getAlpha2Code("Deutschland", "xx"), undefined);
		});
Exemplo n.º 16
0
			logger.once("level_debug", function(log) {
				assert.equal(log.fullOrigin.file, "test/api.js", "log.fullOrigin.file");
				assert.equal(log.fullOrigin.line, 383, "log.fullOrigin.line");
				done();
			});
			it("for de", function () {
				assert.equal(i18niso.getName("de", lang), "Deutschland");
			});
Exemplo n.º 18
0
			logger.once("level_debug", function(log) {
				assert.equal(log.origin, "origin");
				assert.equal(log.message, "message");
				assert.equal(log.metadata, undefined);
				done();
			});
			it("nameToAlpha2 United States => US", function() {
				assert.equal(i18niso.getAlpha2Code("United States", lang), "US");
			});
Exemplo n.º 20
0
 }, function(err, req, res, data) {
     assert.ifError(err);
     assert.equal(data[0].name,'test, test');
     done();
 });
			it("for de", function () {
				assert.equal(i18niso.getName("de", lang), "Germany");
			});
Exemplo n.º 22
0
/*
 * For reading we support both PKCS#1 and PKCS#8. If we find a private key,
 * we just take the public component of it and use that.
 */
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();

	var alg;
	if (m[1]) {
		/* They also must match algorithms, if given */
		assert.equal(m[1], m2[1], 'PEM header and footer mismatch');
		alg = m[1].trim();
	}

	var headers = {};
	while (true) {
		lines = lines.slice(1);
		m = lines[0].match(/*JSSTYLED*/
		    /^([A-Za-z0-9-]+): (.+)$/);
		if (!m)
			break;
		headers[m[1].toLowerCase()] = m[2];
	}

	var cipher, key, iv;
	if (headers['proc-type']) {
		var parts = headers['proc-type'].split(',');
		if (parts[0] === '4' && parts[1] === 'ENCRYPTED') {
			if (typeof (options.passphrase) === 'string') {
				options.passphrase = new Buffer(
				    options.passphrase, 'utf-8');
			}
			if (!Buffer.isBuffer(options.passphrase)) {
				throw (new errors.KeyEncryptedError(
				    options.filename, 'PEM'));
			} else {
				parts = headers['dek-info'].split(',');
				assert.ok(parts.length === 2);
				cipher = parts[0].toLowerCase();
				iv = new Buffer(parts[1], 'hex');
				key = utils.opensslKeyDeriv(cipher, iv,
				    options.passphrase, 1).key;
			}
		}
	}

	/* Chop off the first and last lines */
	lines = lines.slice(0, -1).join('');
	buf = new Buffer(lines, 'base64');

	if (cipher && key && iv) {
		var cipherStream = crypto.createDecipheriv(cipher, key, iv);
		var chunk, chunks = [];
		cipherStream.once('error', function (e) {
			if (e.toString().indexOf('bad decrypt') !== -1) {
				throw (new Error('Incorrect passphrase ' +
				    'supplied, could not decrypt key'));
			}
			throw (e);
		});
		cipherStream.write(buf);
		cipherStream.end();
		while ((chunk = cipherStream.read()) !== null)
			chunks.push(chunk);
		buf = Buffer.concat(chunks);
	}

	/* The new OpenSSH internal format abuses PEM headers */
	if (alg && alg.toLowerCase() === 'openssh')
		return (sshpriv.readSSHPrivate(type, buf, options));
	if (alg && alg.toLowerCase() === 'ssh2')
		return (rfc4253.readType(type, buf, options));

	var der = new asn1.BerReader(buf);
	der.originalInput = input;

	/*
	 * All of the PEM file types start with a sequence tag, so chop it
	 * off here
	 */
	der.readSequence();

	/* PKCS#1 type keys name an algorithm in the banner explicitly */
	if (alg) {
		if (forceType)
			assert.strictEqual(forceType, 'pkcs1');
		return (pkcs1.readPkcs1(alg, type, der));
	} else {
		if (forceType)
			assert.strictEqual(forceType, 'pkcs8');
		return (pkcs8.readPkcs8(alg, type, der));
	}
}
			it("for cy", function () {
				assert.equal(i18niso.getName("cy", lang), "Cyprus");
			});
Exemplo n.º 24
0
 fido.bark(function (message) {
   assert.equal(message, 'Fido says "woof!"');
 });
		it("alpha2ToAlpha3 SG => SGP", function() {
			assert.equal(i18niso.alpha2ToAlpha3("SG"), "SGP");
		});
		it("length", function() {
			assert.equal(Object.keys(i18niso.getNumericCodes()).length, 249);
		});
		it("toAlpha2 true => undefined", function() {
			assert.equal(i18niso.toAlpha2(true), undefined);
		});
		it("missing name", function() {
			assert.equal(i18niso.getAlpha2Code("XXX", "de"), undefined);
		});
		it("alpha3ToAlpha2 DEU => DE", function() {
			assert.equal(i18niso.alpha3ToAlpha2("DEU"), "DE");
		});
		it("numericToAlpha3 '004' => AFG", function() {
			assert.equal(i18niso.numericToAlpha3("004"), "AFG");
		});