Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / remoting / webapp / base / js / xmpp_error_cache_unittest.js
blobf06aa15b8bbc89efa8112c4572370712c16b4b9d
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 (function() {
7 'use strict';
9 QUnit.module('XmppErrorCache');
11 /**
12  * @param {string} stanza
13  * @param {string} expected
14  * @param {QUnit.Assert} assert
15  */
16 function runStanzaTest(stanza, expected, assert) {
17   var monitor = new remoting.XmppErrorCache();
18   var parser = new DOMParser();
19   var xml = parser.parseFromString(stanza, 'text/xml');
20   monitor.processStanza(xml.firstElementChild);
21   var error = monitor.getFirstError();
22   assert.equal(error.raw_stanza, expected);
25 QUnit.test('should strip PII from session-initiate.', function(assert) {
26   var input =
27     '<iq xmlns="jabber:client" to="foo@google.com/chromotingE5A" ' +
28         'type="error" id="12747556118995360108" ' +
29         'from="123@chromoting.gserviceaccount.com/chromoting21B21C01">' +
30         '<jingle xmlns="urn:xmpp:jingle:1" sid="3953621430175055977" ' +
31                 'action="session-initiate" ' +
32                 'initiator="foo@google.com/chromotingE5A">' +
33           '<content name="chromoting" creator="initiator">' +
34             '<description xmlns="google:remoting">' +
35               '<standard-ice/>' +
36                 '<control transport="mux-stream" version="3"/>' +
37                 '<control transport="quic-stream" version="3"/>' +
38                 '<event transport="mux-stream" version="2"/>' +
39                 '<event transport="quic-stream" version="2"/>' +
40                 '<video transport="stream" version="2" codec="vp9"/>' +
41                 '<video transport="stream" version="2" codec="vp8"/>' +
42                 '<video transport="quic-stream" version="2" codec="vp9"/>' +
43                 '<video transport="quic-stream" version="2" codec="vp8"/>' +
44                 '<audio transport="mux-stream" version="2" codec="opus"/>' +
45                 '<audio transport="quic-stream" version="2" codec="opus"/>' +
46                 '<audio transport="none"/>' +
47                 '<initial-resolution width="640" height="480"/>' +
48                 '<authentication supported-methods="spake2_plain"/>' +
49                 '<quic-config>AAADwAAAAYAA=</quic-config>' +
50               '</description>' +
51               '<unknown-field-that-contains-pii unknown-attribute="pii">' +
52                 'This is PII' +
53               '</unknown-field-that-contains-pii>' +
54             '</content>' +
55           '</jingle>' +
56           '<error code="503" type="cancel">' +
57             '<service-unavailable xmlns="urn:ietf:xml:ns:xmpp-stanzas"/>' +
58           '</error>' +
59         '</iq>';
60   var expected =
61       '<iq xmlns="jabber:client" to="REDACTED" type="error" ' +
62           'id="12747556118995360108" from="REDACTED">' +
63         '<jingle xmlns="urn:xmpp:jingle:1" sid="3953621430175055977" ' +
64                 'action="session-initiate" initiator="REDACTED">' +
65           '<content name="chromoting" creator="initiator">' +
66             '<description xmlns="google:remoting">' +
67               '<standard-ice/>' +
68                 '<control transport="mux-stream" version="3"/>' +
69                 '<control transport="quic-stream" version="3"/>' +
70                 '<event transport="mux-stream" version="2"/>' +
71                 '<event transport="quic-stream" version="2"/>' +
72                 '<video transport="stream" version="2" codec="vp9"/>' +
73                 '<video transport="stream" version="2" codec="vp8"/>' +
74                 '<video transport="quic-stream" version="2" codec="vp9"/>' +
75                 '<video transport="quic-stream" version="2" codec="vp8"/>' +
76                 '<audio transport="mux-stream" version="2" codec="opus"/>' +
77                 '<audio transport="quic-stream" version="2" codec="opus"/>' +
78                 '<audio transport="none"/>' +
79                 '<initial-resolution width="640" height="480"/>' +
80                 '<authentication supported-methods="spake2_plain"/>' +
81                 '<quic-config>AAADwAAAAYAA=</quic-config>' +
82               '</description>' +
83               '<unknown-field-that-contains-pii unknown-attribute="REDACTED">'+
84                 'REDACTED' +
85               '</unknown-field-that-contains-pii>' +
86             '</content>' +
87           '</jingle>' +
88           '<error code="503" type="cancel">' +
89             '<service-unavailable xmlns="urn:ietf:xml:ns:xmpp-stanzas"/>' +
90           '</error>' +
91         '</iq>';
92   runStanzaTest(input, expected, assert);
93 });
95 })();