OLD | NEW |
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 14 matching lines...) Expand all Loading... |
25 var onHandshakeDone = function(name, parser) {}; | 25 var onHandshakeDone = function(name, parser) {}; |
26 | 26 |
27 /** @type {(sinon.Spy|function(remoting.Error, string):void)} */ | 27 /** @type {(sinon.Spy|function(remoting.Error, string):void)} */ |
28 var onError_spy = function(error, message) {}; | 28 var onError_spy = function(error, message) {}; |
29 /** @type {function(remoting.Error, string):void} */ | 29 /** @type {function(remoting.Error, string):void} */ |
30 var onError = function(error, message) {}; | 30 var onError = function(error, message) {}; |
31 | 31 |
32 /** @type {remoting.XmppLoginHandler} */ | 32 /** @type {remoting.XmppLoginHandler} */ |
33 var loginHandler = null; | 33 var loginHandler = null; |
34 | 34 |
35 module('XmppLoginHandler', { | 35 QUnit.module('XmppLoginHandler', { |
36 setup: function() { | 36 beforeEach: function() { |
37 sendMessage_spy = sinon.spy(); | 37 sendMessage_spy = sinon.spy(); |
38 sendMessage = /** @type {function(string):void} */ (sendMessage_spy); | 38 sendMessage = /** @type {function(string):void} */ (sendMessage_spy); |
39 startTls_spy = sinon.spy(); | 39 startTls_spy = sinon.spy(); |
40 startTls = /** @type {function():void} */ (startTls_spy); | 40 startTls = /** @type {function():void} */ (startTls_spy); |
41 onHandshakeDone_spy = sinon.spy(); | 41 onHandshakeDone_spy = sinon.spy(); |
42 onHandshakeDone = | 42 onHandshakeDone = |
43 /** @type {function(string, remoting.XmppStreamParser):void} */ | 43 /** @type {function(string, remoting.XmppStreamParser):void} */ |
44 (onHandshakeDone_spy); | 44 (onHandshakeDone_spy); |
45 onError_spy = sinon.spy(); | 45 onError_spy = sinon.spy(); |
46 onError = /** @type {function(remoting.Error, string):void} */(onError_spy); | 46 onError = /** @type {function(remoting.Error, string):void} */(onError_spy); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 'xmlns="jabber:client">' + | 78 'xmlns="jabber:client">' + |
79 '<stream:features>' + | 79 '<stream:features>' + |
80 '<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' + | 80 '<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' + |
81 '<mechanism>X-OAUTH2</mechanism>' + | 81 '<mechanism>X-OAUTH2</mechanism>' + |
82 '<mechanism>X-GOOGLE-TOKEN</mechanism>' + | 82 '<mechanism>X-GOOGLE-TOKEN</mechanism>' + |
83 '<mechanism>PLAIN</mechanism>' + | 83 '<mechanism>PLAIN</mechanism>' + |
84 '</mechanisms>' + | 84 '</mechanisms>' + |
85 '</stream:features>')); | 85 '</stream:features>')); |
86 } | 86 } |
87 | 87 |
88 test('should authenticate', function() { | 88 QUnit.test('should authenticate', function() { |
89 handshakeBase(); | 89 handshakeBase(); |
90 | 90 |
91 loginHandler.onDataReceived( | 91 loginHandler.onDataReceived( |
92 base.encodeUtf8('<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>')); | 92 base.encodeUtf8('<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>')); |
93 sinon.assert.calledWith( | 93 sinon.assert.calledWith( |
94 sendMessage, | 94 sendMessage, |
95 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' + | 95 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' + |
96 'xmlns:stream="http://etherx.jabber.org/streams">' + | 96 'xmlns:stream="http://etherx.jabber.org/streams">' + |
97 '<iq type="set" id="0">' + | 97 '<iq type="set" id="0">' + |
98 '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">' + | 98 '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">' + |
(...skipping 16 matching lines...) Expand all Loading... |
115 '<iq id="0" type="result">' + | 115 '<iq id="0" type="result">' + |
116 '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">' + | 116 '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">' + |
117 '<jid>' + testUsername + '/chromoting52B4920E</jid>' + | 117 '<jid>' + testUsername + '/chromoting52B4920E</jid>' + |
118 '</bind>' + | 118 '</bind>' + |
119 '</iq>' + | 119 '</iq>' + |
120 '<iq type="result" id="1"/>')); | 120 '<iq type="result" id="1"/>')); |
121 | 121 |
122 sinon.assert.calledWith(onHandshakeDone); | 122 sinon.assert.calledWith(onHandshakeDone); |
123 }); | 123 }); |
124 | 124 |
125 test('use <starttls> handshake', function() { | 125 QUnit.test('use <starttls> handshake', function() { |
126 loginHandler = new remoting.XmppLoginHandler( | 126 loginHandler = new remoting.XmppLoginHandler( |
127 'google.com', testUsername, testToken, true, sendMessage, | 127 'google.com', testUsername, testToken, true, sendMessage, |
128 startTls, onHandshakeDone, onError); | 128 startTls, onHandshakeDone, onError); |
129 loginHandler.start(); | 129 loginHandler.start(); |
130 | 130 |
131 sinon.assert.calledWith( | 131 sinon.assert.calledWith( |
132 sendMessage, | 132 sendMessage, |
133 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' + | 133 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' + |
134 'xmlns:stream="http://etherx.jabber.org/streams">' + | 134 'xmlns:stream="http://etherx.jabber.org/streams">' + |
135 '<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>'); | 135 '<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>'); |
(...skipping 12 matching lines...) Expand all Loading... |
148 '<mechanism>X-GOOGLE-TOKEN</mechanism>' + | 148 '<mechanism>X-GOOGLE-TOKEN</mechanism>' + |
149 '</mechanisms>' + | 149 '</mechanisms>' + |
150 '</stream:features>')); | 150 '</stream:features>')); |
151 | 151 |
152 loginHandler.onDataReceived( | 152 loginHandler.onDataReceived( |
153 base.encodeUtf8('<proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>')); | 153 base.encodeUtf8('<proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>')); |
154 | 154 |
155 sinon.assert.calledWith(startTls); | 155 sinon.assert.calledWith(startTls); |
156 }); | 156 }); |
157 | 157 |
158 test('should return AUTHENTICATION_FAILED error when failed to authenticate', | 158 QUnit.test( |
159 function() { | 159 'should return AUTHENTICATION_FAILED error when failed to authenticate', |
| 160 function() { |
160 handshakeBase(); | 161 handshakeBase(); |
161 | 162 |
162 loginHandler.onDataReceived( | 163 loginHandler.onDataReceived( |
163 base.encodeUtf8('<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' + | 164 base.encodeUtf8('<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' + |
164 '<not-authorized/></failure>')); | 165 '<not-authorized/></failure>')); |
165 sinon.assert.calledWith(onError, new remoting.Error( | 166 sinon.assert.calledWith(onError, new remoting.Error( |
166 remoting.Error.Tag.AUTHENTICATION_FAILED)); | 167 remoting.Error.Tag.AUTHENTICATION_FAILED)); |
167 }); | 168 }); |
168 | 169 |
169 test('should return UNEXPECTED error when failed to parse stream', | 170 QUnit.test('should return UNEXPECTED error when failed to parse stream', |
170 function() { | 171 function() { |
171 handshakeBase(); | 172 handshakeBase(); |
172 loginHandler.onDataReceived( | 173 loginHandler.onDataReceived( |
173 base.encodeUtf8('BAD DATA')); | 174 base.encodeUtf8('BAD DATA')); |
174 sinon.assert.calledWith(onError, remoting.Error.unexpected()); | 175 sinon.assert.calledWith(onError, remoting.Error.unexpected()); |
175 }); | 176 }); |
176 | 177 |
177 })(); | 178 })(); |
OLD | NEW |