-
Notifications
You must be signed in to change notification settings - Fork 375
/
Copy pathbind2.test.js
90 lines (78 loc) · 2.45 KB
/
bind2.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { mockClient } from "@xmpp/test";
test("enable", async () => {
const { entity, streamManagement: sm } = mockClient();
entity.mockInput(
<features xmlns="http://etherx.jabber.org/streams">
<authentication xmlns="urn:xmpp:sasl:2">
<mechanism>PLAIN</mechanism>
<inline>
<bind xmlns="urn:xmpp:bind:0">
<inline>
<feature var="urn:xmpp:sm:3" />
</inline>
</bind>
<sm xmlns="urn:xmpp:sm:3" />
</inline>
</authentication>
</features>,
);
const stanza_out = await entity.catchOutgoing();
const enable = stanza_out
.getChild("bind", "urn:xmpp:bind:0")
.getChild("enable");
enable.parent = null;
expect(enable).toEqual(<enable xmlns="urn:xmpp:sm:3" resume="true" />);
expect(sm.enabled).toBe(false);
expect(sm.id).toBe("");
expect(sm.max).toBe(null);
entity.mockInput(
<success xmlns="urn:xmpp:sasl:2">
<bound xmlns="urn:xmpp:bind:0">
<enabled resume="1" xmlns="urn:xmpp:sm:3" id="2j44j2" max="600" />
</bound>
</success>,
);
expect(sm.enabled).toBe(true);
expect(sm.id).toBe("2j44j2");
expect(sm.max).toBe("600");
});
// https://xmpp.org/extensions/xep-0198.html#example-29
test("Client failed to enable stream management", async () => {
const { entity, streamManagement: sm } = mockClient();
entity.mockInput(
<features xmlns="http://etherx.jabber.org/streams">
<authentication xmlns="urn:xmpp:sasl:2">
<mechanism>PLAIN</mechanism>
<inline>
<bind xmlns="urn:xmpp:bind:0">
<inline>
<feature var="urn:xmpp:sm:3" />
</inline>
</bind>
<sm xmlns="urn:xmpp:sm:3" />
</inline>
</authentication>
</features>,
);
const stanza_out = await entity.catchOutgoing();
const enable = stanza_out
.getChild("bind", "urn:xmpp:bind:0")
.getChild("enable");
enable.parent = null;
expect(enable).toEqual(<enable xmlns="urn:xmpp:sm:3" resume="true" />);
expect(sm.enabled).toBe(false);
expect(sm.id).toBe("");
expect(sm.max).toBe(null);
entity.mockInput(
<success xmlns="urn:xmpp:sasl:2">
<bound xmlns="urn:xmpp:bind:0">
<failed xmlns="urn:xmpp:sm:3">
<internal-server-error xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
</failed>
</bound>
</success>,
);
expect(sm.enabled).toBe(false);
expect(sm.id).toBe("");
expect(sm.max).toBe(null);
});