Skip to content

Commit

Permalink
fix: support origins in nodebb: NodeBB/NodeBB#5472
Browse files Browse the repository at this point in the history
  • Loading branch information
AccaliaDeElementia committed Mar 9, 2017
1 parent 76b18ae commit 20057d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
7 changes: 4 additions & 3 deletions providers/nodebb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class Forum extends EventEmitter {
const cookies = this._cookiejar.getCookieString(this.url);
this.socket = Forum.io(this.url, {
extraHeaders: {
'Origin': this.url,
'User-Agent': this.useragent,
'Cookie': cookies
}
Expand Down Expand Up @@ -417,18 +418,18 @@ class Forum extends EventEmitter {
];

let support = false;

if (Array.isArray(supportString)) {
support = supportString.reduce((value, item) => {
return value && this.supports(item);
}, true);
return support;
}

if (supported.indexOf(supportString) > -1) {
support = true;
}

return support;
}

Expand Down
27 changes: 15 additions & 12 deletions test/providers/nodebb/indexTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,15 @@ describe('providers/nodebb', () => {
data.config.core.forum = url;
data.useragent = agent;
return forum.connectWebsocket().then(() => {
Forum.io.calledWith(url, {
extraHeaders: {
'User-Agent': agent,
'Cookie': cookies
Forum.io.firstCall.args.should.deep.eql([
url, {
extraHeaders: {
'Origin': url,
'User-Agent': agent,
'Cookie': cookies
}
}
}).should.be.true;
]);
});
});
it('should register for websocket `pong` event', () => {
Expand Down Expand Up @@ -870,16 +873,16 @@ describe('providers/nodebb', () => {
sandbox.stub(forum.Chat, 'deactivate');
});
afterEach(() => sandbox.restore());

it('must expose a method named supports', () => {
forum.supports.should.be.a('function');
});

it('must return false if a capability is unsupported', () => {
forum.supports('Jack').should.be.false;
forum.supports('PMs').should.be.false;
});

it('must return true if a capability is supported', () => {
forum.supports('PrivateMessage').should.be.true;
forum.supports('Users').should.be.true;
Expand All @@ -889,20 +892,20 @@ describe('providers/nodebb', () => {
forum.supports('Notifications').should.be.true;
forum.supports('Formatting').should.be.true;
});

it('must return false if a sub-capability is not supported', () => {
forum.supports('Jack.Skellington').should.be.false;
forum.supports('Chats.WithJackSkellington').should.be.false;
});

it('must return true if a sub-capability is supported', () => {
forum.supports('Users.Avatars').should.be.true;
});

it('should return true if all items in an array are supported', () => {
forum.supports(['Users', 'PrivateMessage']).should.be.true;
});

it('must return false if any items in an array are not supported', () => {
forum.supports(['Users', 'PrivateMessage', 'Halloween']).should.be.false;
});
Expand Down

0 comments on commit 20057d7

Please sign in to comment.