Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit e2c9b12

Browse files
authored
Apply standard linting to the code base (#539)
* Apply standard linting to the code base * Specify files to lint * Run lint as first stage * Update travis config
1 parent 332de11 commit e2c9b12

File tree

110 files changed

+7194
-7610
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+7194
-7610
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ cache:
1414
npm: true
1515

1616
stages:
17+
- lint
1718
- test
1819

1920
jobs:
2021
include:
21-
# - stage: lint ✨
22-
# script: npm run lint
23-
# node_js: lts/*
22+
- stage: lint ✨
23+
script: npm run lint:ci
24+
node_js: lts/*
2425

2526
- stage: test 👩🏽‍💻
2627
script: npm run test:cov

examples/inmemory.js

Lines changed: 107 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,199 +1,177 @@
1-
var ldap = require('../lib/index');
1+
var ldap = require('../lib/index')
22

3+
/// --- Shared handlers
34

4-
///--- Shared handlers
5-
6-
function authorize(req, res, next) {
5+
function authorize (req, res, next) {
76
/* Any user may search after bind, only cn=root has full power */
8-
var isSearch = (req instanceof ldap.SearchRequest);
9-
if (!req.connection.ldap.bindDN.equals('cn=root') && !isSearch)
10-
return next(new ldap.InsufficientAccessRightsError());
7+
var isSearch = (req instanceof ldap.SearchRequest)
8+
if (!req.connection.ldap.bindDN.equals('cn=root') && !isSearch) { return next(new ldap.InsufficientAccessRightsError()) }
119

12-
return next();
10+
return next()
1311
}
1412

13+
/// --- Globals
1514

16-
///--- Globals
17-
18-
var SUFFIX = 'o=smartdc';
19-
var db = {};
20-
var server = ldap.createServer();
21-
22-
15+
var SUFFIX = 'o=smartdc'
16+
var db = {}
17+
var server = ldap.createServer()
2318

2419
server.bind('cn=root', function (req, res, next) {
25-
if (req.dn.toString() !== 'cn=root' || req.credentials !== 'secret')
26-
return next(new ldap.InvalidCredentialsError());
20+
if (req.dn.toString() !== 'cn=root' || req.credentials !== 'secret') { return next(new ldap.InvalidCredentialsError()) }
2721

28-
res.end();
29-
return next();
30-
});
22+
res.end()
23+
return next()
24+
})
3125

3226
server.add(SUFFIX, authorize, function (req, res, next) {
33-
var dn = req.dn.toString();
27+
var dn = req.dn.toString()
3428

35-
if (db[dn])
36-
return next(new ldap.EntryAlreadyExistsError(dn));
29+
if (db[dn]) { return next(new ldap.EntryAlreadyExistsError(dn)) }
3730

38-
db[dn] = req.toObject().attributes;
39-
res.end();
40-
return next();
41-
});
31+
db[dn] = req.toObject().attributes
32+
res.end()
33+
return next()
34+
})
4235

4336
server.bind(SUFFIX, function (req, res, next) {
44-
var dn = req.dn.toString();
45-
if (!db[dn])
46-
return next(new ldap.NoSuchObjectError(dn));
37+
var dn = req.dn.toString()
38+
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
4739

48-
if (!db[dn].userpassword)
49-
return next(new ldap.NoSuchAttributeError('userPassword'));
40+
if (!db[dn].userpassword) { return next(new ldap.NoSuchAttributeError('userPassword')) }
5041

51-
if (db[dn].userpassword.indexOf(req.credentials) === -1)
52-
return next(new ldap.InvalidCredentialsError());
42+
if (db[dn].userpassword.indexOf(req.credentials) === -1) { return next(new ldap.InvalidCredentialsError()) }
5343

54-
res.end();
55-
return next();
56-
});
44+
res.end()
45+
return next()
46+
})
5747

5848
server.compare(SUFFIX, authorize, function (req, res, next) {
59-
var dn = req.dn.toString();
60-
if (!db[dn])
61-
return next(new ldap.NoSuchObjectError(dn));
49+
var dn = req.dn.toString()
50+
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
6251

63-
if (!db[dn][req.attribute])
64-
return next(new ldap.NoSuchAttributeError(req.attribute));
52+
if (!db[dn][req.attribute]) { return next(new ldap.NoSuchAttributeError(req.attribute)) }
6553

66-
var matches = false;
67-
var vals = db[dn][req.attribute];
54+
var matches = false
55+
var vals = db[dn][req.attribute]
6856
for (var i = 0; i < vals.length; i++) {
6957
if (vals[i] === req.value) {
70-
matches = true;
71-
break;
58+
matches = true
59+
break
7260
}
7361
}
7462

75-
res.end(matches);
76-
return next();
77-
});
63+
res.end(matches)
64+
return next()
65+
})
7866

7967
server.del(SUFFIX, authorize, function (req, res, next) {
80-
var dn = req.dn.toString();
81-
if (!db[dn])
82-
return next(new ldap.NoSuchObjectError(dn));
68+
var dn = req.dn.toString()
69+
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
8370

84-
delete db[dn];
71+
delete db[dn]
8572

86-
res.end();
87-
return next();
88-
});
73+
res.end()
74+
return next()
75+
})
8976

9077
server.modify(SUFFIX, authorize, function (req, res, next) {
91-
var dn = req.dn.toString();
92-
if (!req.changes.length)
93-
return next(new ldap.ProtocolError('changes required'));
94-
if (!db[dn])
95-
return next(new ldap.NoSuchObjectError(dn));
78+
var dn = req.dn.toString()
79+
if (!req.changes.length) { return next(new ldap.ProtocolError('changes required')) }
80+
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
9681

97-
var entry = db[dn];
82+
var entry = db[dn]
9883

84+
let mod
9985
for (var i = 0; i < req.changes.length; i++) {
100-
mod = req.changes[i].modification;
86+
mod = req.changes[i].modification
10187
switch (req.changes[i].operation) {
102-
case 'replace':
103-
if (!entry[mod.type])
104-
return next(new ldap.NoSuchAttributeError(mod.type));
105-
106-
if (!mod.vals || !mod.vals.length) {
107-
delete entry[mod.type];
108-
} else {
109-
entry[mod.type] = mod.vals;
110-
}
88+
case 'replace':
89+
if (!entry[mod.type]) { return next(new ldap.NoSuchAttributeError(mod.type)) }
11190

112-
break;
91+
if (!mod.vals || !mod.vals.length) {
92+
delete entry[mod.type]
93+
} else {
94+
entry[mod.type] = mod.vals
95+
}
11396

114-
case 'add':
115-
if (!entry[mod.type]) {
116-
entry[mod.type] = mod.vals;
117-
} else {
118-
mod.vals.forEach(function (v) {
119-
if (entry[mod.type].indexOf(v) === -1)
120-
entry[mod.type].push(v);
121-
});
122-
}
97+
break
98+
99+
case 'add':
100+
if (!entry[mod.type]) {
101+
entry[mod.type] = mod.vals
102+
} else {
103+
mod.vals.forEach(function (v) {
104+
if (entry[mod.type].indexOf(v) === -1) { entry[mod.type].push(v) }
105+
})
106+
}
123107

124-
break;
108+
break
125109

126-
case 'delete':
127-
if (!entry[mod.type])
128-
return next(new ldap.NoSuchAttributeError(mod.type));
110+
case 'delete':
111+
if (!entry[mod.type]) { return next(new ldap.NoSuchAttributeError(mod.type)) }
129112

130-
delete entry[mod.type];
113+
delete entry[mod.type]
131114

132-
break;
115+
break
133116
}
134117
}
135118

136-
res.end();
137-
return next();
138-
});
119+
res.end()
120+
return next()
121+
})
139122

140123
server.search(SUFFIX, authorize, function (req, res, next) {
141-
var dn = req.dn.toString();
142-
if (!db[dn])
143-
return next(new ldap.NoSuchObjectError(dn));
124+
var dn = req.dn.toString()
125+
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
144126

145-
var scopeCheck;
127+
var scopeCheck
146128

147129
switch (req.scope) {
148-
case 'base':
149-
if (req.filter.matches(db[dn])) {
150-
res.send({
151-
dn: dn,
152-
attributes: db[dn]
153-
});
154-
}
130+
case 'base':
131+
if (req.filter.matches(db[dn])) {
132+
res.send({
133+
dn: dn,
134+
attributes: db[dn]
135+
})
136+
}
155137

156-
res.end();
157-
return next();
138+
res.end()
139+
return next()
158140

159-
case 'one':
160-
scopeCheck = function (k) {
161-
if (req.dn.equals(k))
162-
return true;
141+
case 'one':
142+
scopeCheck = function (k) {
143+
if (req.dn.equals(k)) { return true }
163144

164-
var parent = ldap.parseDN(k).parent();
165-
return (parent ? parent.equals(req.dn) : false);
166-
};
167-
break;
145+
var parent = ldap.parseDN(k).parent()
146+
return (parent ? parent.equals(req.dn) : false)
147+
}
148+
break
168149

169-
case 'sub':
170-
scopeCheck = function (k) {
171-
return (req.dn.equals(k) || req.dn.parentOf(k));
172-
};
150+
case 'sub':
151+
scopeCheck = function (k) {
152+
return (req.dn.equals(k) || req.dn.parentOf(k))
153+
}
173154

174-
break;
155+
break
175156
}
176157

177158
Object.keys(db).forEach(function (key) {
178-
if (!scopeCheck(key))
179-
return;
159+
if (!scopeCheck(key)) { return }
180160

181161
if (req.filter.matches(db[key])) {
182162
res.send({
183163
dn: key,
184164
attributes: db[key]
185-
});
165+
})
186166
}
187-
});
188-
189-
res.end();
190-
return next();
191-
});
192-
167+
})
193168

169+
res.end()
170+
return next()
171+
})
194172

195-
///--- Fire it up
173+
/// --- Fire it up
196174

197175
server.listen(1389, function () {
198-
console.log('LDAP server up at: %s', server.url);
199-
});
176+
console.log('LDAP server up at: %s', server.url)
177+
})

0 commit comments

Comments
 (0)