hapijs / nes

WebSocket adapter plugin for hapi routes
Other
502 stars 87 forks source link

Error is thrown, if client.connect({auth: 'somestring'}) #324

Open janwo opened 1 year ago

janwo commented 1 year ago

Support plan

Context

What are you trying to achieve or the steps to reproduce?

Dear all, just found out that the server code crashes if the auth variable on the client side is not an object, e.g. a string. Client values should be validated first.

 describe('direct', () => {

        it('protects an endpoint', async () => {

            const server = Hapi.server();

            server.auth.scheme('custom', internals.implementation);
            server.auth.strategy('default', 'custom');
            server.auth.default('default');

            await server.register(Nes);

            server.route({
                method: 'GET',
                path: '/',
                handler: () => 'hello'
            });

            await server.start();
            const client = new Nes.Client(getUri(server.info));
            await client.connect({ auth:  'somestring' });
            const { payload, statusCode } = await client.request('/');
            expect(payload).to.equal('hello');
            expect(statusCode).to.equal(200);

            client.disconnect();
            await server.stop();
        });

What was the result you got?

Server crashed as headers cannot be assigned to string".

What result did you expect?

Validation of the auth object in some way.