Skip to content

Commit

Permalink
Add test for starttls
Browse files Browse the repository at this point in the history
  • Loading branch information
dborkan committed Aug 12, 2014
1 parent 114533c commit 5718b1c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
42 changes: 41 additions & 1 deletion test/data/firefox_tests/tcp_socket.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe("sockets", function() {
describe("tcp sockets", function() {
var clientSocket, serverSocket;
beforeEach(function() {
serverSocket = new ServerSocket("localhost", 8081);
Expand Down Expand Up @@ -36,4 +36,44 @@ describe("sockets", function() {
}
return buf;
}
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
};

it("secures socket with starttls", function(done) {
var INIT_XMPP = '<stream:stream ' +
'xmlns:stream="http://etherx.jabber.org/streams" ' +
'version="1.0" xmlns="jabber:client" to="chat.facebook.com" ' +
'xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace">';
var START_TLS = '<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>';
var X_FACEBOOK_PLATFORM_AUTH =
'<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" ' +
'mechanism="X-FACEBOOK-PLATFORM"></auth>';

// Test that we can connect to chat.facebook.com, then upgrade to a tls
// socket and get the challenge. If we fail to upgrade the socket to tls
// facebook will not return a challenge.
var onDataCount = 0;
var dispatchEvent = function (eventType, data) {
if (eventType == 'onData') {
var xmlString = ab2str(data.data);
if (xmlString.indexOf('<challenge') >= 0) {
done();
}
++onDataCount;
if (onDataCount == 1) {
socket.write(str2ab(START_TLS), continuation);
} else if (onDataCount == 2) {
socket.secure(continuation);
socket.write(str2ab(INIT_XMPP), continuation);
} else if (onDataCount == 3) {
socket.write(str2ab(X_FACEBOOK_PLATFORM_AUTH), continuation);
}
}
};
var continuation = function() {};
var socket = new Socket_firefox(undefined, dispatchEvent, undefined);
socket.connect('chat.facebook.com', 5222, continuation);
socket.write(str2ab(INIT_XMPP), continuation);
});
});
4 changes: 3 additions & 1 deletion test/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ const jasmine = require("jasmine.js");

var providers = ["firefox_providers/client_socket.js",
"firefox_providers/server_socket.js",
"firefox_providers/tcp_socket.js",
"firefox_providers/udp_socket.js"];

var tests = [
"firefox_tests/client_socket.spec.js",
"firefox_tests/udp_socket.spec.js"
"firefox_tests/udp_socket.spec.js",
"firefox_tests/tcp_socket.spec.js"
];


Expand Down

0 comments on commit 5718b1c

Please sign in to comment.