-
-
Notifications
You must be signed in to change notification settings - Fork 795
Expand file tree
/
Copy pathsocketio.test.ts
More file actions
68 lines (55 loc) · 1.97 KB
/
socketio.test.ts
File metadata and controls
68 lines (55 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { io } from 'socket.io-client';
import assert from 'assert';
import { feathers, Application } from '@feathersjs/feathers';
import socketio from '@feathersjs/socketio';
import socketioClient from '@feathersjs/socketio-client';
import authClient from '../../src';
import getApp from './fixture';
import commonTests from './commons';
describe('@feathersjs/authentication-client Socket.io integration', () => {
let app: Application;
before(async () => {
app = getApp(feathers().configure(socketio()));
await app.listen(9777);
});
after(done => app.io.close(() => done()));
it('allows to authenticate with handshake headers and sends login event', async () => {
const user = { email: 'authtest@example.com', password: 'alsosecret' };
await app.service('users').create(user);
const { accessToken } = await app.service('authentication').create({
strategy: 'local',
...user
});
const socket = io('http://localhost:9777', {
transports: [ 'websocket' ],
transportOptions: {
websocket: {
extraHeaders: {
Authorization: `Bearer ${accessToken}`
}
}
}
});
const authResult: any = await new Promise(resolve =>
app.once('login', res => resolve(res))
);
assert.strictEqual(authResult.accessToken, accessToken);
const dummy: any = await new Promise((resolve, reject) => {
socket.emit('find', 'dummy', {}, (error: Error, page: any) =>
error ? reject(error) : resolve(page)
);
});
assert.strictEqual(dummy.user.email, user.email);
assert.strictEqual(dummy.authentication.accessToken, accessToken);
assert.strictEqual(dummy.headers.authorization, `Bearer ${accessToken}`);
});
commonTests(() => app, () => {
return feathers()
.configure(socketioClient(io('http://localhost:9777')))
.configure(authClient());
}, {
email: 'socketioauth@feathersjs.com',
password: 'secretive',
provider: 'socketio'
});
});