Skip to content

Commit 0c5019b

Browse files
committed
test: parsing of endpoint URLs with extra dots and slashes
1 parent 8a8b56f commit 0c5019b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/server.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,54 @@ describe('RPCServer', function(){
341341

342342
});
343343

344+
it('should correctly parse endpoints with double slashes and dots', async () => {
345+
346+
const identity = 'XX';
347+
const {endpoint, close, server} = await createServer({});
348+
349+
try {
350+
const endpointPaths = [
351+
{append: '/ocpp', expect: '/ocpp'},
352+
{append: '//', expect: '//'},
353+
{append: '//ocpp', expect: '//ocpp'},
354+
{append: '/ocpp/', expect: '/ocpp/'},
355+
{append: '/', expect: '/'},
356+
{append: '///', expect: '///'},
357+
{append: '/../', expect: '/'},
358+
{append: '//../', expect: '/'},
359+
{append: '/ocpp/..', expect: '/'},
360+
{append: '/ocpp/../', expect: '/'},
361+
{append: '//ocpp/../', expect: '//'},
362+
{append: '', expect: '/'},
363+
];
364+
365+
for (const endpointPath of endpointPaths) {
366+
const fullEndpoint = endpoint + endpointPath.append;
367+
368+
let hs;
369+
server.auth((accept, reject, handshake) => {
370+
hs = handshake;
371+
accept();
372+
});
373+
374+
const cli = new RPCClient({
375+
endpoint: fullEndpoint,
376+
identity,
377+
});
378+
379+
await cli.connect();
380+
await cli.close({force: true});
381+
382+
assert.equal(hs.endpoint, endpointPath.expect);
383+
assert.equal(hs.identity, identity);
384+
}
385+
386+
} finally {
387+
close();
388+
}
389+
390+
});
391+
344392
it('should attach session properties to client', async () => {
345393

346394
let serverClient;

0 commit comments

Comments
 (0)