Skip to content

Commit 20057d7

Browse files
fix: support origins in nodebb: NodeBB/NodeBB#5472
1 parent 76b18ae commit 20057d7

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

providers/nodebb/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ class Forum extends EventEmitter {
264264
const cookies = this._cookiejar.getCookieString(this.url);
265265
this.socket = Forum.io(this.url, {
266266
extraHeaders: {
267+
'Origin': this.url,
267268
'User-Agent': this.useragent,
268269
'Cookie': cookies
269270
}
@@ -417,18 +418,18 @@ class Forum extends EventEmitter {
417418
];
418419

419420
let support = false;
420-
421+
421422
if (Array.isArray(supportString)) {
422423
support = supportString.reduce((value, item) => {
423424
return value && this.supports(item);
424425
}, true);
425426
return support;
426427
}
427-
428+
428429
if (supported.indexOf(supportString) > -1) {
429430
support = true;
430431
}
431-
432+
432433
return support;
433434
}
434435

test/providers/nodebb/indexTest.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,15 @@ describe('providers/nodebb', () => {
556556
data.config.core.forum = url;
557557
data.useragent = agent;
558558
return forum.connectWebsocket().then(() => {
559-
Forum.io.calledWith(url, {
560-
extraHeaders: {
561-
'User-Agent': agent,
562-
'Cookie': cookies
559+
Forum.io.firstCall.args.should.deep.eql([
560+
url, {
561+
extraHeaders: {
562+
'Origin': url,
563+
'User-Agent': agent,
564+
'Cookie': cookies
565+
}
563566
}
564-
}).should.be.true;
567+
]);
565568
});
566569
});
567570
it('should register for websocket `pong` event', () => {
@@ -870,16 +873,16 @@ describe('providers/nodebb', () => {
870873
sandbox.stub(forum.Chat, 'deactivate');
871874
});
872875
afterEach(() => sandbox.restore());
873-
876+
874877
it('must expose a method named supports', () => {
875878
forum.supports.should.be.a('function');
876879
});
877-
880+
878881
it('must return false if a capability is unsupported', () => {
879882
forum.supports('Jack').should.be.false;
880883
forum.supports('PMs').should.be.false;
881884
});
882-
885+
883886
it('must return true if a capability is supported', () => {
884887
forum.supports('PrivateMessage').should.be.true;
885888
forum.supports('Users').should.be.true;
@@ -889,20 +892,20 @@ describe('providers/nodebb', () => {
889892
forum.supports('Notifications').should.be.true;
890893
forum.supports('Formatting').should.be.true;
891894
});
892-
895+
893896
it('must return false if a sub-capability is not supported', () => {
894897
forum.supports('Jack.Skellington').should.be.false;
895898
forum.supports('Chats.WithJackSkellington').should.be.false;
896899
});
897-
900+
898901
it('must return true if a sub-capability is supported', () => {
899902
forum.supports('Users.Avatars').should.be.true;
900903
});
901-
904+
902905
it('should return true if all items in an array are supported', () => {
903906
forum.supports(['Users', 'PrivateMessage']).should.be.true;
904907
});
905-
908+
906909
it('must return false if any items in an array are not supported', () => {
907910
forum.supports(['Users', 'PrivateMessage', 'Halloween']).should.be.false;
908911
});

0 commit comments

Comments
 (0)