Skip to content

Commit

Permalink
test(ap): use 'password', set mode for 'adhoc'
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Sep 1, 2016
1 parent 2354828 commit e9d1a42
Showing 1 changed file with 85 additions and 15 deletions.
100 changes: 85 additions & 15 deletions test/unit/access-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ exports['Tessel.prototype.createAccessPoint'] = {
},

newAccessPoint: function(test) {
test.expect(20);
test.expect(21);
var creds = {
ssid: 'test',
pass: 'test-password',
security: 'psk2'
password: 'test-password',
security: 'psk2',
mode: 'ap'
};

// Immediately close any opened connections
Expand Down Expand Up @@ -94,8 +95,71 @@ exports['Tessel.prototype.createAccessPoint'] = {
test.equal(this.reconnectDnsmasq.callCount, 1);
test.equal(this.reconnectDhcp.callCount, 1);
test.ok(this.setAccessPointSSID.lastCall.calledWith(creds.ssid));
test.ok(this.setAccessPointPassword.lastCall.calledWith(creds.pass));
test.ok(this.setAccessPointPassword.lastCall.calledWith(creds.password));
test.ok(this.setAccessPointSecurity.lastCall.calledWith(creds.security));
test.ok(this.setAccessPointMode.lastCall.calledWith(creds.mode));

test.done();
})
.catch(error => {
test.ok(false, error.toString());
test.done();
});
},

newAdhoc: function(test) {
test.expect(21);
var creds = {
ssid: 'test',
password: 'test-password',
security: 'psk2',
mode: 'adhoc'
};

// Immediately close any opened connections
this.tessel._rps.on('control', () => {
setImmediate(() => {
this.tessel._rps.emit('close');
});
});

// tessel.receive is called twice but needs to be rejected the first time
var count = 0;
this.sandbox.stub(this.tessel, 'receive', function(remoteProcess, callback) {
if (typeof callback !== 'function') {
callback = function() {};
}
if (count === 0) {
count++;
return callback(new Error('uci: Entry not found'));
} else {
return callback(null, new Buffer(0));
}
});

this.tessel.createAccessPoint(creds)
.then(() => {
test.equal(this.getAccessPoint.callCount, 1);
test.equal(this.setAccessPoint.callCount, 1);
test.equal(this.setAccessPointDevice.callCount, 1);
test.equal(this.setAccessPointNetwork.callCount, 1);
test.equal(this.setAccessPointMode.callCount, 1);
test.equal(this.setAccessPointSSID.callCount, 1);
test.equal(this.setAccessPointPassword.callCount, 1);
test.equal(this.setAccessPointSecurity.callCount, 1);
test.equal(this.setLanNetwork.callCount, 1);
test.equal(this.setLanNetworkIfname.callCount, 1);
test.equal(this.setLanNetworkProto.callCount, 1);
test.equal(this.setLanNetworkIP.callCount, 1);
test.equal(this.setLanNetworkNetmask.callCount, 1);
test.equal(this.commitNetwork.callCount, 1);
test.equal(this.reconnectWifi.callCount, 1);
test.equal(this.reconnectDnsmasq.callCount, 1);
test.equal(this.reconnectDhcp.callCount, 1);
test.ok(this.setAccessPointSSID.lastCall.calledWith(creds.ssid));
test.ok(this.setAccessPointPassword.lastCall.calledWith(creds.password));
test.ok(this.setAccessPointSecurity.lastCall.calledWith(creds.security));
test.ok(this.setAccessPointMode.lastCall.calledWith(creds.mode));

test.done();
})
Expand All @@ -106,11 +170,12 @@ exports['Tessel.prototype.createAccessPoint'] = {
},

noPasswordNoSecurity: function(test) {
test.expect(9);
test.expect(10);
var creds = {
ssid: 'test',
pass: undefined,
security: undefined
password: undefined,
security: undefined,
mode: 'ap'
};

// Test is expecting two closes...;
Expand All @@ -126,6 +191,7 @@ exports['Tessel.prototype.createAccessPoint'] = {
test.equal(this.setAccessPointSSID.callCount, 1);
test.equal(this.setAccessPointPassword.callCount, 0);
test.equal(this.setAccessPointSecurity.callCount, 1);
test.equal(this.setAccessPointMode.callCount, 1);
test.equal(this.reconnectWifi.callCount, 1);
test.equal(this.reconnectDnsmasq.callCount, 1);
test.equal(this.reconnectDhcp.callCount, 1);
Expand All @@ -140,11 +206,12 @@ exports['Tessel.prototype.createAccessPoint'] = {
},

properCredentials: function(test) {
test.expect(10);
test.expect(11);
var creds = {
ssid: 'test',
pass: 'test-password',
security: 'psk2'
password: 'test-password',
security: 'psk2',
mode: 'ap'
};

// Test is expecting two closes...;
Expand All @@ -160,11 +227,12 @@ exports['Tessel.prototype.createAccessPoint'] = {
test.equal(this.setAccessPointSSID.callCount, 1);
test.equal(this.setAccessPointPassword.callCount, 1);
test.equal(this.setAccessPointSecurity.callCount, 1);
test.equal(this.setAccessPointMode.callCount, 1);
test.equal(this.reconnectWifi.callCount, 1);
test.equal(this.reconnectDnsmasq.callCount, 1);
test.equal(this.reconnectDhcp.callCount, 1);
test.ok(this.setAccessPointSSID.lastCall.calledWith(creds.ssid));
test.ok(this.setAccessPointPassword.lastCall.calledWith(creds.pass));
test.ok(this.setAccessPointPassword.lastCall.calledWith(creds.password));
test.ok(this.setAccessPointSecurity.lastCall.calledWith(creds.security));
test.done();
})
Expand All @@ -175,11 +243,12 @@ exports['Tessel.prototype.createAccessPoint'] = {
},

passwordNoSecurity: function(test) {
test.expect(10);
test.expect(11);
var creds = {
ssid: 'test',
pass: 'test-password',
security: undefined
password: 'test-password',
security: undefined,
mode: 'ap'
};

// Test is expecting two closes...;
Expand All @@ -195,11 +264,12 @@ exports['Tessel.prototype.createAccessPoint'] = {
test.equal(this.setAccessPointSSID.callCount, 1);
test.equal(this.setAccessPointPassword.callCount, 1);
test.equal(this.setAccessPointSecurity.callCount, 1);
test.equal(this.setAccessPointMode.callCount, 1);
test.equal(this.reconnectWifi.callCount, 1);
test.equal(this.reconnectDnsmasq.callCount, 1);
test.equal(this.reconnectDhcp.callCount, 1);
test.ok(this.setAccessPointSSID.lastCall.calledWith(creds.ssid));
test.ok(this.setAccessPointPassword.lastCall.calledWith(creds.pass));
test.ok(this.setAccessPointPassword.lastCall.calledWith(creds.password));
test.ok(this.setAccessPointSecurity.lastCall.calledWith('psk2'));
test.done();
})
Expand Down

0 comments on commit e9d1a42

Please sign in to comment.