-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
199 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
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(); | ||
expect(stanza_out).toEqual( | ||
<authenticate xmlns="urn:xmpp:sasl:2" mechanism="PLAIN"> | ||
{stanza_out.getChild("initial-response")} | ||
<bind xmlns="urn:xmpp:bind:0"> | ||
<enable xmlns="urn:xmpp:sm:3" resume="true" /> | ||
</bind> | ||
</authenticate>, | ||
); | ||
|
||
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(); | ||
expect(stanza_out).toEqual( | ||
<authenticate xmlns="urn:xmpp:sasl:2" mechanism="PLAIN"> | ||
{stanza_out.getChild("initial-response")} | ||
<bind xmlns="urn:xmpp:bind:0"> | ||
<enable xmlns="urn:xmpp:sm:3" resume="true" /> | ||
</bind> | ||
</authenticate>, | ||
); | ||
|
||
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
}); |
File renamed without changes.