Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Dec 29, 2024
1 parent 6c2ffc2 commit 0ca97e7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/client-core/lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class Client extends Connection {
// after the confidentiality and integrity of the stream are protected via TLS
// or an equivalent security layer.
// https://xmpp.org/rfcs/rfc6120.html#rfc.section.4.7.1
headerElement.attrs.from =
(this.socket?.isSecure?.() && this.jid?.bare().toString()) || null;
const from = this.socket?.isSecure?.() && this.jid?.bare().toString();
if (from) headerElement.attrs.from = from;
return this.Transport.prototype.header(headerElement, ...args);
}

Expand Down
11 changes: 11 additions & 0 deletions packages/client-core/test/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,21 @@ test("header", () => {

const entity = new Client();
entity.Transport = Transport;
entity.socket = {};

entity.jid = null;
entity.socket.isSecure = () => false;
expect(entity.header(<foo />)).toEqual(<foo />);

entity.jid = null;
entity.socket.isSecure = () => true;
expect(entity.header(<foo />)).toEqual(<foo />);

entity.jid = new JID("foo@bar/example");
entity.socket.isSecure = () => false;
expect(entity.header(<foo />)).toEqual(<foo />);

entity.jid = new JID("foo@bar/example");
entity.socket.isSecure = () => true;
expect(entity.header(<foo />)).toEqual(<foo from="foo@bar" />);
});
1 change: 1 addition & 0 deletions packages/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function client(options = {}) {
}

const entity = new Client(params);
entity.jid = jid(username, params.domain);

const reconnect = _reconnect({ entity });
const websocket = _websocket({ entity });
Expand Down
3 changes: 1 addition & 2 deletions packages/sasl-anonymous/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"main": "index.js",
"keywords": [
"XMPP",
"sasl",
"anonymous"
"sasl"
],
"dependencies": {
"sasl-anonymous": "^0.1.0"
Expand Down
3 changes: 1 addition & 2 deletions packages/sasl-plain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"main": "index.js",
"keywords": [
"XMPP",
"sasl",
"plain"
"sasl"
],
"dependencies": {
"sasl-plain": "^0.1.0"
Expand Down
3 changes: 1 addition & 2 deletions packages/sasl-scram-sha-1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"main": "index.js",
"keywords": [
"XMPP",
"sasl",
"plain"
"sasl"
],
"dependencies": {
"sasl-scram-sha-1": "^1.3.0"
Expand Down

0 comments on commit 0ca97e7

Please sign in to comment.