1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 02:42:17 -05:00

[WO-625] Catch exception on socket.oncert

Mozilla's socket is not extensible via Object.preventExtensions(obj)
and throws exceptions when non-prototype function .oncert is added.
The callback function is needed for the other shims.
This commit is contained in:
Felix Hammerl 2014-09-30 12:30:08 +02:00
parent 5c9f8dac23
commit 297f7c493f
2 changed files with 36 additions and 6 deletions

View File

@ -162,12 +162,18 @@ define(function(require) {
socket.ondata = function() {}; // we don't actually care about the data socket.ondata = function() {}; // we don't actually care about the data
socket.oncert = function() { // [WO-625] Mozilla forbids extensions to the TCPSocket object,
if (options.ca) { // throws an exception when assigned unexpected callback functions.
// the certificate we already have is outdated // The exception can be safely ignored since we need the callback
error = createError(TLS_WRONG_CERT, strings.connDocTlsWrongCert.replace('{0}', host)); // for the other shims
} try {
}; socket.oncert = function() {
if (options.ca) {
// the certificate we already have is outdated
error = createError(TLS_WRONG_CERT, strings.connDocTlsWrongCert.replace('{0}', host));
}
};
} catch (e) {}
socket.onerror = function(e) { socket.onerror = function(e) {
if (!error) { if (!error) {

View File

@ -23,6 +23,7 @@ define(function(require) {
this.onclose(); this.onclose();
} }
}; };
imapStub = sinon.createStubInstance(ImapClient); imapStub = sinon.createStubInstance(ImapClient);
smtpStub = sinon.createStubInstance(SmtpClient); smtpStub = sinon.createStubInstance(SmtpClient);
@ -95,6 +96,29 @@ define(function(require) {
socketStub.onopen(); socketStub.onopen();
}); });
it('should catch Mozilla TCPSocket exception', function(done) {
// Mozilla forbids extensions to the TCPSocket object
Object.defineProperty(socketStub, 'oncert', {
set: function() {
throw 'Mozilla specific behavior';
}
});
doctor._checkReachable(credentials.imap, function(error) {
expect(error).to.not.exist;
expect(TCPSocket.open.calledOnce).to.be.true;
expect(TCPSocket.open.calledWith(credentials.imap.host, credentials.imap.port, {
binaryType: 'arraybuffer',
useSecureTransport: credentials.imap.secure,
ca: credentials.imap.ca
})).to.be.true;
done();
});
socketStub.onopen();
});
it('should fail w/ wrong cert', function(done) { it('should fail w/ wrong cert', function(done) {
doctor._checkReachable(credentials.imap, function(error) { doctor._checkReachable(credentials.imap, function(error) {
expect(error).to.exist; expect(error).to.exist;