Skip to content

Commit ec01674

Browse files
committed
lint
1 parent ee863d7 commit ec01674

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

spec/Middlewares.spec.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,42 @@ describe('middlewares', () => {
153153
});
154154

155155
it('can allow all with masterKeyIPs', async () => {
156-
const logger = require('../lib/logger').logger;
157-
spyOn(logger, 'error').and.callFake(() => {});
158-
AppCache.put(fakeReq.body._ApplicationId, {
159-
masterKey: 'masterKey',
160-
masterKeyIps: ['::/0'],
161-
});
162-
fakeReq.ip = '::ffff:192.168.0.101';
163-
fakeReq.headers['x-parse-master-key'] = 'masterKey';
164-
await new Promise(resolve => middlewares.handleParseHeaders(fakeReq, fakeRes, resolve));
165-
expect(fakeReq.auth.isMaster).toBe(true);
156+
const combinations = [
157+
{
158+
masterKeyIps: ['::/0'],
159+
ips: ['::ffff:192.168.0.101', '192.168.0.101'],
160+
id: 'allowAllIpV6',
161+
},
162+
{
163+
masterKeyIps: ['0.0.0.0'],
164+
ips: ['192.168.0.101'],
165+
id: 'allowAllIpV4',
166+
},
167+
];
168+
for (const combination of combinations) {
169+
AppCache.put(combination.id, {
170+
masterKey: 'masterKey',
171+
masterKeyIps: combination.masterKeyIps,
172+
});
173+
await new Promise(resolve => setTimeout(resolve, 10));
174+
for (const ip of combination.ips) {
175+
fakeReq = {
176+
originalUrl: 'http://example.com/parse/',
177+
url: 'http://example.com/',
178+
body: {
179+
_ApplicationId: combination.id,
180+
},
181+
headers: {},
182+
get: key => {
183+
return fakeReq.headers[key.toLowerCase()];
184+
},
185+
};
186+
fakeReq.ip = ip;
187+
fakeReq.headers['x-parse-master-key'] = 'masterKey';
188+
await new Promise(resolve => middlewares.handleParseHeaders(fakeReq, fakeRes, resolve));
189+
expect(fakeReq.auth.isMaster).toBe(true);
190+
}
191+
}
166192
});
167193

168194
it('can allow localhost with masterKeyIPs', async () => {

src/middlewares.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import PostgresStorageAdapter from './Adapters/Storage/Postgres/PostgresStorageA
1010
import rateLimit from 'express-rate-limit';
1111
import { RateLimitOptions } from './Options/Definitions';
1212
import { pathToRegexp } from 'path-to-regexp';
13-
import ipRangeCheck from 'ip-range-check';
1413
import RedisStore from 'rate-limit-redis';
1514
import { createClient } from 'redis';
1615
import { BlockList, isIPv4 } from 'net';
@@ -32,7 +31,7 @@ const checkIpRanges = (ip, ranges = []) => {
3231
if ((range === '::/0' || range === '::') && clientType === 'ipv6') {
3332
return true;
3433
}
35-
if (range === '0.0.0.0' && clientType === 'ipv6') {
34+
if (range === '0.0.0.0' && clientType === 'ipv4') {
3635
return true;
3736
}
3837
const [addr, prefix] = range.split('/');

0 commit comments

Comments
 (0)