-
Notifications
You must be signed in to change notification settings - Fork 376
/
Copy pathsasl2.test.js
78 lines (64 loc) · 2.22 KB
/
sasl2.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
import { mockClient } from "@xmpp/test";
test("resume", async () => {
const { entity, streamManagement: sm } = mockClient();
sm.id = Math.random().toString().slice(2);
entity.mockInput(
<features xmlns="http://etherx.jabber.org/streams">
<authentication xmlns="urn:xmpp:sasl:2">
<mechanism>PLAIN</mechanism>
<inline>
<sm xmlns="urn:xmpp:sm:3" />
</inline>
</authentication>
</features>,
);
sm.outbound = 45;
sm.inbound = 54;
// eslint-disable-next-line unicorn/no-await-expression-member
const element_resume = (await entity.catchOutgoing()).getChild("resume");
element_resume.parent = null;
expect(element_resume).toEqual(
<resume xmlns="urn:xmpp:sm:3" h="0" previd={sm.id} />,
);
entity.mockInput(
<success xmlns="urn:xmpp:sasl:2">
<resumed xmlns="urn:xmpp:sm:3" previd={sm.id} h="0" />
</success>,
);
expect(entity.streamManagement.outbound).toBe(45);
expect(entity.streamManagement.inbound).toBe(54);
expect(entity.streamManagement.enabled).toBe(true);
});
// https://xmpp.org/extensions/xep-0198.html#example-30
test("Client failed to resume stream", async () => {
const { entity, streamManagement: sm } = mockClient();
sm.id = Math.random().toString().slice(2);
entity.mockInput(
<features xmlns="http://etherx.jabber.org/streams">
<authentication xmlns="urn:xmpp:sasl:2">
<mechanism>PLAIN</mechanism>
<inline>
<sm xmlns="urn:xmpp:sm:3" />
</inline>
</authentication>
</features>,
);
sm.outbound = 45;
sm.inbound = 54;
// eslint-disable-next-line unicorn/no-await-expression-member
const element_resume = (await entity.catchOutgoing()).getChild("resume");
element_resume.parent = null;
expect(element_resume).toEqual(
<resume xmlns="urn:xmpp:sm:3" h="0" previd={sm.id} />,
);
entity.mockInput(
<success xmlns="urn:xmpp:sasl:2">
<failed xmlns="urn:xmpp:sm:3" h="another-sequence-number">
<item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
</failed>
</success>,
);
expect(entity.streamManagement.outbound).toBe(45);
expect(entity.streamManagement.inbound).toBe(54);
expect(entity.streamManagement.enabled).toBe(false);
});