-
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.
Implement sasl2 stream management (#1037)
--- Co-authored-by: Stephen Paul Weber [email protected]
- Loading branch information
Showing
16 changed files
with
368 additions
and
67 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
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
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); | ||
}); |
Oops, something went wrong.