Browse Source

Skip tls tests on windows and stunnel

This will also remove the libwrap option to work on arch
internal
Ruben Bridgewater 9 years ago
parent
commit
b91692e928
  1. 2
      .gitignore
  2. 2
      .travis.yml
  3. 8
      index.js
  4. 1
      test/conf/stunnel.conf.template
  5. 8
      test/connection.spec.js
  6. 28
      test/tls.spec.js

2
.gitignore

@ -4,3 +4,5 @@ node_modules
coverage
*.log
*.rdb
stunnel.conf
stunnel.pid

2
.travis.yml

@ -8,6 +8,8 @@ addons:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
env:
- TRAVIS=true
node_js:
- "0.10"
- "0.12"

8
index.js

@ -46,6 +46,7 @@ function RedisClient (options) {
cnx_options.family = (!options.family && net.isIP(cnx_options.host)) || (options.family === 'IPv6' ? 6 : 4);
this.address = cnx_options.host + ':' + cnx_options.port;
}
/* istanbul ignore next: travis does not work with stunnel atm. Therefor the tls tests are skipped on travis */
for (var tls_option in options.tls) { // jshint ignore: line
cnx_options[tls_option] = options.tls[tls_option];
}
@ -91,7 +92,7 @@ function RedisClient (options) {
this.options = options;
// Init parser once per instance
this.init_parser();
self.create_stream();
this.create_stream();
}
util.inherits(RedisClient, events.EventEmitter);
@ -105,6 +106,7 @@ RedisClient.prototype.create_stream = function () {
this.stream.destroy();
}
/* istanbul ignore if: travis does not work with stunnel atm. Therefor the tls tests are skipped on travis */
if (this.options.tls) {
this.stream = tls.connect(this.connection_options);
} else {
@ -118,8 +120,9 @@ RedisClient.prototype.create_stream = function () {
});
}
/* istanbul ignore next: travis does not work with stunnel atm. Therefor the tls tests are skipped on travis */
var connect_event = this.options.tls ? "secureConnect" : "connect";
this.stream.on(connect_event, function () {
this.stream.once(connect_event, function () {
this.removeAllListeners("timeout");
self.on_connect();
});
@ -134,6 +137,7 @@ RedisClient.prototype.create_stream = function () {
self.on_error(err);
});
/* istanbul ignore next: travis does not work with stunnel atm. Therefor the tls tests are skipped on travis */
this.stream.on('clientError', function (err) {
self.on_error(err);
});

1
test/conf/stunnel.conf.template

@ -5,7 +5,6 @@ cert = __dirname/redis.js.org.cert
key = __dirname/redis.js.org.key
client = no
foreground = yes
libwrap = no
debug = 7
[redis]
accept = 127.0.0.1:6380

8
test/connection.spec.js

@ -103,7 +103,7 @@ describe("connection tests", function () {
max_attempts: 1
};
client = redis.createClient(options);
assert.strictEqual(client.connection_option.family, ip === 'IPv6' ? 6 : 4);
assert.strictEqual(client.connection_options.family, ip === 'IPv6' ? 6 : 4);
assert.strictEqual(Object.keys(options).length, 4);
var end = helper.callFuncAfter(done, 2);
@ -142,7 +142,7 @@ describe("connection tests", function () {
assert(client.stream._events.timeout);
});
assert.strictEqual(client.address, '192.168.74.167:6379');
assert.strictEqual(client.connection_option.family, 4);
assert.strictEqual(client.connection_options.family, 4);
var time = Date.now();
client.on("reconnecting", function (params) {
@ -162,7 +162,7 @@ describe("connection tests", function () {
host: '2001:db8::ff00:42:8329' // auto detect ip v6
});
assert.strictEqual(client.address, '2001:db8::ff00:42:8329:6379');
assert.strictEqual(client.connection_option.family, 6);
assert.strictEqual(client.connection_options.family, 6);
process.nextTick(function() {
assert.strictEqual(client.stream._events.timeout, undefined);
});
@ -240,7 +240,7 @@ describe("connection tests", function () {
it("connects with a port only", function (done) {
client = redis.createClient(6379);
assert.strictEqual(client.connection_option.family, 4);
assert.strictEqual(client.connection_options.family, 4);
client.on("error", done);
client.once("ready", function () {

28
test/tls.spec.js

@ -15,14 +15,29 @@ var tls_options = {
var tls_port = 6380;
if (process.platform === 'win32') {
return;
}
// Wait until stunnel4 is in the travis whitelist
// Check: https://github.com/travis-ci/apt-package-whitelist/issues/403
// If this is merged, remove the travis env checks
describe("TLS connection tests", function () {
before(function (done) {
if (process.env.TRAVIS === 'true') {
done();
return;
}
helper.stopStunnel(function () {
helper.startStunnel(done);
});
});
after(function (done) {
if (process.env.TRAVIS === 'true') {
done();
return;
}
helper.stopStunnel(done);
});
@ -33,13 +48,12 @@ describe("TLS connection tests", function () {
var client;
afterEach(function () {
if (client) {
client.end();
}
client.end(true);
});
describe("on lost connection", function () {
it("emit an error after max retry attempts and do not try to reconnect afterwards", function (done) {
if (process.env.TRAVIS === 'true') this.skip();
var max_attempts = 4;
var options = {
parser: parser,
@ -69,6 +83,7 @@ describe("TLS connection tests", function () {
});
it("emit an error after max retry timeout and do not try to reconnect afterwards", function (done) {
if (process.env.TRAVIS === 'true') this.skip();
var connect_timeout = 500; // in ms
client = redis.createClient({
parser: parser,
@ -97,6 +112,7 @@ describe("TLS connection tests", function () {
});
it("end connection while retry is still ongoing", function (done) {
if (process.env.TRAVIS === 'true') this.skip();
var connect_timeout = 1000; // in ms
client = redis.createClient({
parser: parser,
@ -116,6 +132,7 @@ describe("TLS connection tests", function () {
});
it("can not connect with wrong host / port in the options object", function (done) {
if (process.env.TRAVIS === 'true') this.skip();
var options = {
host: 'somewhere',
max_attempts: 1,
@ -136,6 +153,7 @@ describe("TLS connection tests", function () {
describe("when not connected", function () {
it("connect with host and port provided in the options object", function (done) {
if (process.env.TRAVIS === 'true') this.skip();
client = redis.createClient({
host: 'localhost',
parser: parser,
@ -150,6 +168,7 @@ describe("TLS connection tests", function () {
});
it("connects correctly with args", function (done) {
if (process.env.TRAVIS === 'true') this.skip();
var args_host = args[1];
var args_options = args[2] || {};
args_options.tls = tls_options;
@ -166,6 +185,7 @@ describe("TLS connection tests", function () {
if (ip === 'IPv4') {
it('allows connecting with the redis url and no auth and options as second parameter', function (done) {
if (process.env.TRAVIS === 'true') this.skip();
var options = {
detect_buffers: false,
magic: Math.random(),
@ -176,6 +196,7 @@ describe("TLS connection tests", function () {
// verify connection is using TCP, not UNIX socket
assert.strictEqual(client.connection_options.host, config.HOST[ip]);
assert.strictEqual(client.connection_options.port, tls_port);
assert(typeof client.stream.getCipher === 'function');
// verify passed options are in use
assert.strictEqual(client.options.magic, options.magic);
client.on("ready", function () {
@ -184,6 +205,7 @@ describe("TLS connection tests", function () {
});
it('allows connecting with the redis url and no auth and options as third parameter', function (done) {
if (process.env.TRAVIS === 'true') this.skip();
client = redis.createClient('redis://' + config.HOST[ip] + ':' + tls_port, null, {
detect_buffers: false,
tls: tls_options

Loading…
Cancel
Save