-
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.
Use getChildElements to fix bugs in SASL and XMPPError (#966)
Fixes #952
- Loading branch information
Showing
5 changed files
with
83 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"use strict"; | ||
|
||
const test = require("ava"); | ||
const XMPPError = require("."); | ||
// eslint-disable-next-line node/no-extraneous-require | ||
const parse = require("@xmpp/xml/lib/parse.js"); | ||
|
||
test("fromElement", (t) => { | ||
const application_element = ( | ||
<escape-your-data xmlns="http://example.org/ns" /> | ||
); | ||
|
||
const nonza = ( | ||
<stream:error> | ||
<some-condition xmlns="urn:ietf:params:xml:ns:xmpp-streams" /> | ||
<text xmlns="urn:ietf:params:xml:ns:xmpp-streams" xml:lang="langcode"> | ||
foo | ||
</text> | ||
{application_element} | ||
</stream:error> | ||
); | ||
|
||
const error = XMPPError.fromElement(nonza); | ||
|
||
t.is(error instanceof Error, true); | ||
t.is(error.name, "XMPPError"); | ||
t.is(error.condition, "some-condition"); | ||
t.is(error.text, "foo"); | ||
t.is(error.application, application_element); | ||
}); | ||
|
||
test("fromElement - whitespaces", (t) => { | ||
const nonza = parse( | ||
` | ||
<stream:error> | ||
<some-condition xmlns="urn:ietf:params:xml:ns:xmpp-streams" /> | ||
<text xmlns="urn:ietf:params:xml:ns:xmpp-streams" xml:lang="langcode"> | ||
foo | ||
</text> | ||
<escape-your-data xmlns='http://example.org/ns'/> | ||
</stream:error> | ||
`.trim(), | ||
); | ||
|
||
const error = XMPPError.fromElement(nonza); | ||
|
||
t.is(error instanceof Error, true); | ||
t.is(error.name, "XMPPError"); | ||
t.is(error.condition, "some-condition"); | ||
t.is(error.text, "\n foo\n "); | ||
t.is( | ||
error.application.toString(), | ||
`<escape-your-data xmlns="http://example.org/ns"/>`, | ||
); | ||
}); |
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