Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: remoting/webapp/unittests/xmpp_login_handler_unittest.js

Issue 534853002: Reduce number of roundtrips required in XMPP handshake (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webapp_tls
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | remoting/webapp/xmpp_login_handler.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function() { 5 (function() {
6 6
7 'use strict'; 7 'use strict';
8 8
9 var testUsername = 'testUsername@gmail.com'; 9 var testUsername = 'testUsername@gmail.com';
10 var testToken = 'testToken'; 10 var testToken = 'testToken';
(...skipping 20 matching lines...) Expand all
31 onHandshakeDone, onError); 31 onHandshakeDone, onError);
32 } 32 }
33 }); 33 });
34 34
35 // Executes handshake base. 35 // Executes handshake base.
36 function handshakeBase() { 36 function handshakeBase() {
37 loginHandler.start(); 37 loginHandler.start();
38 sinon.assert.calledWith( 38 sinon.assert.calledWith(
39 sendMessage, 39 sendMessage,
40 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' + 40 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' +
41 'xmlns:stream="http://etherx.jabber.org/streams">'); 41 'xmlns:stream="http://etherx.jabber.org/streams">' +
42 '<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>');
42 sendMessage.reset(); 43 sendMessage.reset();
43 44
44 loginHandler.onDataReceived(base.encodeUtf8( 45 loginHandler.onDataReceived(base.encodeUtf8(
45 '<stream:stream from="google.com" id="78A87C70559EF28A" version="1.0" ' + 46 '<stream:stream from="google.com" id="78A87C70559EF28A" version="1.0" ' +
46 'xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">' + 47 'xmlns:stream="http://etherx.jabber.org/streams"' +
47 '<stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">' + 48 'xmlns="jabber:client">' +
48 '<required/></starttls><mechanisms ' + 49 '<stream:features>' +
49 'xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' + 50 '<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">' +
50 '<mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism>' + 51 '<required/>' +
51 '</mechanisms></stream:features>')); 52 '</starttls>' +
52 sinon.assert.calledWith( 53 '<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' +
53 sendMessage, '<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>'); 54 '<mechanism>X-OAUTH2</mechanism>' +
54 sendMessage.reset(); 55 '<mechanism>X-GOOGLE-TOKEN</mechanism>' +
56 '</mechanisms>' +
57 '</stream:features>'));
55 58
56 loginHandler.onDataReceived( 59 loginHandler.onDataReceived(
57 base.encodeUtf8('<proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>')); 60 base.encodeUtf8('<proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>'));
58 sinon.assert.calledWith(startTls); 61 sinon.assert.calledWith(startTls);
59 startTls.reset(); 62 startTls.reset();
60 63
61 loginHandler.onTlsStarted(); 64 loginHandler.onTlsStarted();
65 var cookie = window.btoa("\0" + testUsername + "\0" + testToken);
62 sinon.assert.calledWith( 66 sinon.assert.calledWith(
63 sendMessage, 67 sendMessage,
64 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' + 68 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' +
65 'xmlns:stream="http://etherx.jabber.org/streams">'); 69 'xmlns:stream="http://etherx.jabber.org/streams">' +
66 sendMessage.reset();
67
68 loginHandler.onDataReceived(base.encodeUtf8(
69 '<stream:stream from="google.com" id="DCDDE5171CB2154A" version="1.0" ' +
70 'xmlns:stream="http://etherx.jabber.org/streams" ' +
71 'xmlns="jabber:client"><stream:features>' +
72 '<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' +
73 '<mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism>' +
74 '<mechanism>PLAIN</mechanism></mechanisms></stream:features>'));
75 var cookie = window.btoa("\0" + testUsername + "\0" + testToken);
76 sinon.assert.calledWith(
77 sendMessage,
78 '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="X-OAUTH2" ' + 70 '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="X-OAUTH2" ' +
79 'auth:service="oauth2" auth:allow-generated-jid="true" ' + 71 'auth:service="oauth2" auth:allow-generated-jid="true" ' +
80 'auth:client-uses-full-bind-result="true" ' + 72 'auth:client-uses-full-bind-result="true" ' +
81 'auth:allow-non-google-login="true" ' + 73 'auth:allow-non-google-login="true" ' +
82 'xmlns:auth="http://www.google.com/talk/protocol/auth">' + cookie + 74 'xmlns:auth="http://www.google.com/talk/protocol/auth">' + cookie +
83 '</auth>'); 75 '</auth>');
84 sendMessage.reset(); 76 sendMessage.reset();
77
78 loginHandler.onDataReceived(base.encodeUtf8(
79 '<stream:stream from="google.com" id="DCDDE5171CB2154A" version="1.0" ' +
80 'xmlns:stream="http://etherx.jabber.org/streams" ' +
81 'xmlns="jabber:client">' +
82 '<stream:features>' +
83 '<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' +
84 '<mechanism>X-OAUTH2</mechanism>' +
85 '<mechanism>X-GOOGLE-TOKEN</mechanism>' +
86 '<mechanism>PLAIN</mechanism>' +
87 '</mechanisms>' +
88 '</stream:features>'));
85 } 89 }
86 90
87 test('should authenticate', function() { 91 test('should authenticate', function() {
88 handshakeBase(); 92 handshakeBase();
89 93
90 loginHandler.onDataReceived( 94 loginHandler.onDataReceived(
91 base.encodeUtf8('<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>')); 95 base.encodeUtf8('<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>'));
92 sinon.assert.calledWith( 96 sinon.assert.calledWith(
93 sendMessage, 97 sendMessage,
94 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' + 98 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' +
95 'xmlns:stream="http://etherx.jabber.org/streams">'); 99 'xmlns:stream="http://etherx.jabber.org/streams">' +
100 '<iq type="set" id="0">' +
101 '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">' +
102 '<resource>chromoting</resource>' +
103 '</bind>' +
104 '</iq>' +
105 '<iq type="set" id="1">' +
106 '<session xmlns="urn:ietf:params:xml:ns:xmpp-session"/>' +
107 '</iq>');
96 sendMessage.reset(); 108 sendMessage.reset();
97 109
98 loginHandler.onDataReceived(base.encodeUtf8( 110 loginHandler.onDataReceived(base.encodeUtf8(
99 '<stream:stream from="google.com" id="104FA10576E2AA80" version="1.0" ' + 111 '<stream:stream from="google.com" id="104FA10576E2AA80" version="1.0" ' +
100 'xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">' + 112 'xmlns:stream="http://etherx.jabber.org/streams" ' +
101 '<stream:features><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/>' + 113 'xmlns="jabber:client">' +
102 '<session xmlns="urn:ietf:params:xml:ns:xmpp-session"/>' + 114 '<stream:features>' +
103 '</stream:features>')); 115 '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/>' +
104 sinon.assert.calledWith( 116 '<session xmlns="urn:ietf:params:xml:ns:xmpp-session"/>' +
105 sendMessage, 117 '</stream:features>' +
106 '<iq type="set" id="0"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">' + 118 '<iq id="0" type="result">' +
107 '<resource>chromoting</resource></bind></iq>'); 119 '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">' +
108 sendMessage.reset(); 120 '<jid>' + testUsername + '/chromoting52B4920E</jid>' +
121 '</bind>' +
122 '</iq>' +
123 '<iq type="result" id="1"/>'));
109 124
110 loginHandler.onDataReceived(
111 base.encodeUtf8('<iq id="0" type="result">' +
112 '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>' +
113 testUsername + '/chromoting52B4920E</jid></bind></iq>'));
114 sinon.assert.calledWith(
115 sendMessage,
116 '<iq type="set" id="1"><session ' +
117 'xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>');
118 sendMessage.reset();
119
120 loginHandler.onDataReceived(base.encodeUtf8('<iq type="result" id="1"/>'));
121 sinon.assert.calledWith(onHandshakeDone); 125 sinon.assert.calledWith(onHandshakeDone);
122 }); 126 });
123 127
124 test('should return AUTHENTICATION_FAILED error when failed to authenticate', 128 test('should return AUTHENTICATION_FAILED error when failed to authenticate',
125 function() { 129 function() {
126 handshakeBase(); 130 handshakeBase();
127 131
128 loginHandler.onDataReceived( 132 loginHandler.onDataReceived(
129 base.encodeUtf8('<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' + 133 base.encodeUtf8('<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' +
130 '<not-authorized/></failure>')); 134 '<not-authorized/></failure>'));
131 sinon.assert.calledWith(onError, remoting.Error.AUTHENTICATION_FAILED); 135 sinon.assert.calledWith(onError, remoting.Error.AUTHENTICATION_FAILED);
132 }); 136 });
133 137
134 test('should return UNEXPECTED error when failed to parse stream', 138 test('should return UNEXPECTED error when failed to parse stream',
135 function() { 139 function() {
136 loginHandler.start(); 140 loginHandler.start();
137 loginHandler.onDataReceived( 141 loginHandler.onDataReceived(
138 base.encodeUtf8('BAD DATA')); 142 base.encodeUtf8('BAD DATA'));
139 sinon.assert.calledWith(onError, remoting.Error.UNEXPECTED); 143 sinon.assert.calledWith(onError, remoting.Error.UNEXPECTED);
140 }); 144 });
141 145
142 })(); 146 })();
OLDNEW
« no previous file with comments | « no previous file | remoting/webapp/xmpp_login_handler.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698