Skip to content

Commit

Permalink
Remove sasl2 SASLError
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Dec 22, 2024
1 parent 195cda5 commit 2e1782f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 12 deletions.
2 changes: 2 additions & 0 deletions packages/error/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test("fromElement", () => {
const error = XMPPError.fromElement(nonza);

expect(error instanceof Error).toBe(true);
expect(error instanceof XMPPError).toBe(true);
expect(error.name).toBe("XMPPError");
expect(error.condition).toBe("some-condition");
expect(error.text).toBe("foo");
Expand All @@ -42,6 +43,7 @@ test("fromElement - whitespaces", () => {
const error = XMPPError.fromElement(nonza);

expect(error instanceof Error).toBe(true);
expect(error instanceof XMPPError).toBe(true);
expect(error.name).toBe("XMPPError");
expect(error.condition).toBe("some-condition");
expect(error.text).toBe("\n foo\n ");
Expand Down
71 changes: 71 additions & 0 deletions packages/sasl/lib/SASLError.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import XMPPError from "@xmpp/error";
import SASLError from "./SASLError.js";

// https://xmpp.org/rfcs/rfc6120.html#rfc.section.6.4.5
// https://xmpp.org/rfcs/rfc6120.html#rfc.section.A.4

test("SASL", () => {
const nonza = (
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
<not-authorized />
</failure>
);

const error = SASLError.fromElement(nonza);

expect(error instanceof Error).toBe(true);
expect(error instanceof XMPPError).toBe(true);
expect(error instanceof SASLError).toBe(true);
expect(error.name).toBe("SASLError");
expect(error.condition).toBe("not-authorized");
expect(error.text).toBe("");
});

test("SASL with text", () => {
const nonza = (
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
<aborted />
<text>foo</text>
</failure>
);
expect(SASLError.fromElement(nonza).text).toBe("foo");
});

// https://xmpp.org/extensions/xep-0388.html#failure
// https://github.com/xsf/xeps/pull/1411
// https://xmpp.org/extensions/xep-0388.html#sect-idm46365286031040

test("SASL2", () => {
const nonza = (
<failure xmlns="urn:xmpp:sasl:2">
<aborted xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />
</failure>
);

const error = SASLError.fromElement(nonza);

expect(error instanceof Error).toBe(true);
expect(error instanceof XMPPError).toBe(true);
expect(error instanceof SASLError).toBe(true);
expect(error.name).toBe("SASLError");
expect(error.condition).toBe("aborted");
});

test("SASL2 with text and application", () => {
const application = (
<optional-application-specific xmlns="urn:something:else" />
);

const nonza = (
<failure xmlns="urn:xmpp:sasl:2">
<aborted xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />
<text>This is a terrible example.</text>
{application}
</failure>
);

const error = SASLError.fromElement(nonza);

expect(error.text).toBe("This is a terrible example.");
expect(error.application).toBe(application);
});
12 changes: 0 additions & 12 deletions packages/sasl2/lib/SASLError.js

This file was deleted.

0 comments on commit 2e1782f

Please sign in to comment.