Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed IP whitelist authorisation #1157

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/middleware/authorisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function authoriseIP(channel, ctx) {
if ((channel.whitelist != null ? channel.whitelist.length : undefined) > 0) {
return Array.from(channel.whitelist).includes(ctx.ip)
} else {
return true // whitelist auth not required
return false
}
}

Expand All @@ -52,8 +52,9 @@ export async function authorise(ctx, done) {

if (
channel != null &&
authoriseIP(channel, ctx) &&
(channel.authType === 'public' || authoriseClient(channel, ctx))
(channel.authType === 'public' ||
authoriseClient(channel, ctx) ||
authoriseIP(channel, ctx))
) {
// authorisation succeeded
ctx.authorisedChannel = channel
Expand Down
4 changes: 2 additions & 2 deletions test/integration/httpTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,13 @@ describe('HTTP tests', () => {
.expect(201)
})

it('should deny access on POST - Private Channel with whitelisted IP but incorrect client role', async () => {
it('should allow access on POST - Private Channel with whitelisted IP but incorrect client role', async () => {
await promisify(server.start)({httpPort: SERVER_PORTS.httpPort})
await request(constants.HTTP_BASE_URL)
.post('/un-auth')
.send(testDoc)
.auth('testApp', 'password')
.expect(401)
.expect(201)
})

it('should return 201 CREATED on POST - Private Channel with whitelisted IP and correct client role', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/authorisationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ describe('Authorisation middleware', () => {
return actual.should.be.false()
})

it('should return true if there are no whitelist entires', () => {
it('should return false if there are no whitelist entires', () => {
const ctx = {ip: '192.168.0.11'}
const channel = {whitelist: null}
const authoriseIP = authorisation.__get__('authoriseIP')
const actual = authoriseIP(channel, ctx)
return actual.should.be.true()
return actual.should.be.false()
})
})
})