Skip to content

Commit 413f25f

Browse files
committed
fix(fileop) authCheck
1 parent 2ba1d88 commit 413f25f

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ app.use(fileop({
9898
fileop.listen(socket, {
9999
prefix: '/fileop', /* default */
100100
root: '/', /* string or function */
101-
authCheck: (username, password, accept, reject) => {
101+
authCheck: (accept, reject) => (username, password) => {
102102
if (username === 'root' && password === 'toor')
103103
accept();
104104

server/listen.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ function listen(socket, options) {
3737
return connection(root, socket);
3838

3939
const reject = () => socket.emit('reject');
40-
socket.on('auth', (username, password) => {
41-
authCheck(username, password, connectionWraped(root, socket), reject);
42-
})
40+
socket.on('auth', authCheck(connectionWraped(root, socket), reject));
4341
});
4442
}
4543

test/client/fileop.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ test('client: disconnect', async (t) => {
228228
});
229229
});
230230

231-
test('client: auth', async (t) => {
232-
const authCheck = (username, password, accept, reject) => {
231+
test('client: auth: reject', async (t) => {
232+
const authCheck = (accept, reject) => () => {
233233
reject();
234234
};
235235

@@ -252,8 +252,8 @@ test('client: auth', async (t) => {
252252
});
253253

254254
test('client: options', async (t) => {
255-
const authCheck = (username, password, accept, reject) => {
256-
reject();
255+
const authCheck = (accept) => () => {
256+
accept();
257257
};
258258

259259
const prefix = '/hello';
@@ -268,12 +268,12 @@ test('client: options', async (t) => {
268268
const destroy = getDestroy(operator);
269269

270270
operator.emit('auth');
271-
operator.on('reject', () => {
271+
operator.on('accept', () => {
272272
after();
273273
done();
274274
destroy();
275275

276-
t.pass('shoud reject');
276+
t.pass('shoud accept');
277277
t.end();
278278
});
279279
});

test/server/fileop.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const test = require('tape');
44
const tryToCatch = require('try-to-catch');
5+
const currify = require('currify');
56

67
const connect = require('../lib/connect');
78

@@ -33,7 +34,7 @@ test('fileop: options: authCheck not function', async (t) => {
3334
});
3435

3536
test('fileop: options: authCheck: reject', async (t) => {
36-
const authCheck = (username, password, accept, reject) => {
37+
const authCheck = (accept, reject) => () => {
3738
reject();
3839
};
3940

@@ -49,7 +50,7 @@ test('fileop: options: authCheck: reject', async (t) => {
4950
});
5051

5152
test('fileop: options: authCheck: accept', async (t) => {
52-
const authCheck = (username, password, accept) => {
53+
const authCheck = (accept) => () => {
5354
accept();
5455
};
5556

@@ -65,6 +66,23 @@ test('fileop: options: authCheck: accept', async (t) => {
6566
});
6667
});
6768

69+
test('fileop: options: authCheck: accept', async (t) => {
70+
const user = 'bill';
71+
const pass = 'world';
72+
73+
const authCheck = currify((accept, reject, username, password) => {
74+
done();
75+
76+
t.equal(username, user, 'should pass username');
77+
t.equal(password, pass, 'should pass password');
78+
t.end();
79+
});
80+
81+
const {socket, done} = await connect({authCheck});
82+
83+
socket.emit('auth', user, pass);
84+
});
85+
6886
test('fileop: listen: wrong operation', async (t) => {
6987
const {socket, done} = await connect();
7088

0 commit comments

Comments
 (0)