Skip to content

Commit 7b24884

Browse files
committed
chore: add and use prettier
1 parent 7d7eb35 commit 7b24884

12 files changed

Lines changed: 295 additions & 270 deletions

.eslintrc.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
},
55
"extends": "eslint:recommended",
66
"rules": {
7-
"indent": ["error", 2],
87
"linebreak-style": ["error", "unix"],
98
"quotes": ["error", "single"],
109
"semi": ["error", "always"],
1110
"valid-jsdoc": ["error"],
1211
"require-jsdoc": ["error"],
1312
"object-curly-spacing": ["error", "always"],
14-
"space-before-function-paren": ["error", "never"],
1513
"default-case": ["error"],
1614
"guard-for-in": ["error"],
1715
"no-caller": ["error"],
@@ -54,7 +52,6 @@
5452
"block-spacing": ["error", "always"],
5553
"brace-style": ["error"],
5654
"camelcase": ["error"],
57-
"comma-dangle": ["error", "never"],
5855
"comma-spacing": ["error", { "before": false, "after": true }],
5956
"comma-style": ["error", "last"],
6057
"eol-last": ["error"],

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
test/*.js
44
out
55
tmp
6+
.vscode

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"arrowParens": "always",
5+
"printWidth": 100,
6+
"trailingComma": "es5"
7+
}

CHANGES.md

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,39 @@
22

33
## 5.0.3
44

5-
- [pull request #99] Ensure `groupDnProperty` is included in `attributes`
5+
- [pull request #99] Ensure `groupDnProperty` is included in `attributes`
66

77
## 5.0.2
88

9-
- [pull request #97] Sanitize group search filters
9+
- [pull request #97] Sanitize group search filters
1010

1111
## 5.0.0
1212

13-
- Update `ldapjs` to version 2
13+
- Update `ldapjs` to version 2
1414

1515
## 4.3.3
1616

17-
- [pull request #86] Fix typedef of tlsOptions
17+
- [pull request #86] Fix typedef of tlsOptions
1818

1919
## 4.3.2
2020

21-
- [pull request #83] Allow any @types/node version
21+
- [pull request #83] Allow any @types/node version
2222

2323
## 4.3.0
2424

25-
- [issue #59, pull request #80] Add starttls
25+
- [issue #59, pull request #80] Add starttls
2626

2727
## 4.2.0
2828

29-
- [issue #69, pull request #71] Defer installation of reconnect event listener
29+
- [issue #69, pull request #71] Defer installation of reconnect event listener
3030

3131
## 4.1.1
3232

33-
- [issue #74] Remove direct moment.js dependency
33+
- [issue #74] Remove direct moment.js dependency
3434

3535
## 4.1.0
3636

37-
- [pull request #68] Rebind admin client after reconnect
37+
- [pull request #68] Rebind admin client after reconnect
3838

3939
## 4.0.2
4040

@@ -100,17 +100,15 @@
100100

101101
```javascript
102102
new LdapAuth({
103-
"url": "ldaps://ldap.example.com:636",
104-
"adminDn": "cn=LdapAdmin,dc=local",
105-
"adminPassword": "LdapAdminPassword",
106-
"searchBase": "dc=users,dc=local",
107-
"searchFilter": "(&(objectClass=person)(sAMAccountName={{username}}))",
108-
"searchAttributes": [
109-
"dn", "cn", "givenName", "name", "memberOf", "sAMAccountName"
110-
],
111-
"groupSearchBase": "dc=groups,dc=local",
112-
"groupSearchFilter": "(member={{dn}})",
113-
"groupSearchAttributes": ["dn", "cn", "sAMAccountName"]
103+
url: 'ldaps://ldap.example.com:636',
104+
adminDn: 'cn=LdapAdmin,dc=local',
105+
adminPassword: 'LdapAdminPassword',
106+
searchBase: 'dc=users,dc=local',
107+
searchFilter: '(&(objectClass=person)(sAMAccountName={{username}}))',
108+
searchAttributes: ['dn', 'cn', 'givenName', 'name', 'memberOf', 'sAMAccountName'],
109+
groupSearchBase: 'dc=groups,dc=local',
110+
groupSearchFilter: '(member={{dn}})',
111+
groupSearchAttributes: ['dn', 'cn', 'sAMAccountName'],
114112
});
115113
```
116114

@@ -184,39 +182,31 @@ new LdapAuth({
184182

185183
(nothing yet)
186184

187-
188185
## 2.2.2
189186

190187
- [issue #5] update to bcrypt 0.7.5 (0.7.3 fixes potential mem issues)
191188

192-
193189
## 2.2.1
194190

195191
- Fix a bug where ldapauth `authenticate()` would raise an example on an empty
196192
username.
197193

198-
199194
## 2.2.0
200195

201196
- Update to latest ldapjs (0.5.6) and other deps.
202197
Note: This makes ldapauth only work with node >=0.8 (because of internal dep
203198
in ldapjs 0.5).
204199

205-
206200
## 2.1.0
207201

208202
- Update to ldapjs 0.4 (from 0.3). Crossing fingers that this doesn't cause breakage.
209203

210-
211204
## 2.0.0
212205

213206
- Add `make check` for checking jsstyle.
214207
- [issue #1] Update to bcrypt 0.5. This means increasing the base node from 0.4
215208
to 0.6, hence the major version bump.
216209

217-
218210
## 1.0.2
219211

220212
First working version.
221-
222-

README.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,44 +38,44 @@ auth.close(function(err) { ... })
3838

3939
Required ldapjs client options:
4040

41-
- `url` - LDAP server URL, eg. *ldaps://ldap.example.org:636*, or a list of URLs, e.g. `["ldaps://ldap.example.org:636"]`
41+
- `url` - LDAP server URL, eg. _ldaps://ldap.example.org:636_, or a list of URLs, e.g. `["ldaps://ldap.example.org:636"]`
4242

4343
ldapauth-fork options:
4444

45-
- `bindDN` - Admin connection DN, e.g. *uid=myapp,ou=users,dc=example,dc=org*. Optional. If not given at all, admin client is not bound. Giving empty string may result in anonymous bind when allowed.
46-
- `bindCredentials` - Password for bindDN.
47-
- `searchBase` - The base DN from which to search for users by username. E.g. *ou=users,dc=example,dc=org*
48-
- `searchFilter` - LDAP search filter with which to find a user by username, e.g. *(uid={{username}})*. Use the literal *{{username}}* to have the given username interpolated in for the LDAP search.
49-
- `searchAttributes` - Optional, default all. Array of attributes to fetch from LDAP server.
50-
- `bindProperty` - Optional, default *dn*. Property of the LDAP user object to use when binding to verify the password. E.g. *name*, *email*
51-
- `searchScope` - Optional, default *sub*. Scope of the search, one of *base*, *one*, or *sub*.
45+
- `bindDN` - Admin connection DN, e.g. _uid=myapp,ou=users,dc=example,dc=org_. Optional. If not given at all, admin client is not bound. Giving empty string may result in anonymous bind when allowed.
46+
- `bindCredentials` - Password for bindDN.
47+
- `searchBase` - The base DN from which to search for users by username. E.g. _ou=users,dc=example,dc=org_
48+
- `searchFilter` - LDAP search filter with which to find a user by username, e.g. _(uid={{username}})_. Use the literal _{{username}}_ to have the given username interpolated in for the LDAP search.
49+
- `searchAttributes` - Optional, default all. Array of attributes to fetch from LDAP server.
50+
- `bindProperty` - Optional, default _dn_. Property of the LDAP user object to use when binding to verify the password. E.g. _name_, _email_
51+
- `searchScope` - Optional, default _sub_. Scope of the search, one of _base_, _one_, or _sub_.
5252

5353
ldapauth-fork can look for valid users groups too. Related options:
5454

55-
- `groupSearchBase` - Optional. The base DN from which to search for groups. If defined, also `groupSearchFilter` must be defined for the search to work.
56-
- `groupSearchFilter` - Optional. LDAP search filter for groups. Place literal *{{dn}}* in the filter to have it replaced by the property defined with `groupDnProperty` of the found user object. *{{username}}* is also available and will be replaced with the *uid* of the found user. This is useful for example to filter PosixGroups by *memberUid*. Optionally you can also assign a function instead. The found user is passed to the function and it should return a valid search filter for the group search.
57-
- `groupSearchAttributes` - Optional, default all. Array of attributes to fetch from LDAP server.
58-
- `groupDnProperty` - Optional, default *dn*. The property of user object to use in *{{dn}}* interpolation of `groupSearchFilter`.
59-
- `groupSearchScope` - Optional, default *sub*.
55+
- `groupSearchBase` - Optional. The base DN from which to search for groups. If defined, also `groupSearchFilter` must be defined for the search to work.
56+
- `groupSearchFilter` - Optional. LDAP search filter for groups. Place literal _{{dn}}_ in the filter to have it replaced by the property defined with `groupDnProperty` of the found user object. _{{username}}_ is also available and will be replaced with the _uid_ of the found user. This is useful for example to filter PosixGroups by _memberUid_. Optionally you can also assign a function instead. The found user is passed to the function and it should return a valid search filter for the group search.
57+
- `groupSearchAttributes` - Optional, default all. Array of attributes to fetch from LDAP server.
58+
- `groupDnProperty` - Optional, default _dn_. The property of user object to use in _{{dn}}_ interpolation of `groupSearchFilter`.
59+
- `groupSearchScope` - Optional, default _sub_.
6060

6161
Other ldapauth-fork options:
6262

63-
- `includeRaw` - Optional, default false. Set to true to add property `_raw` containing the original buffers to the returned user object. Useful when you need to handle binary attributes
64-
- `cache` - Optional, default false. If true, then up to 100 credentials at a time will be cached for 5 minutes.
65-
- `log` - Bunyan logger instance, optional. If given this will result in TRACE-level error logging for component:ldapauth. The logger is also passed forward to ldapjs.
63+
- `includeRaw` - Optional, default false. Set to true to add property `_raw` containing the original buffers to the returned user object. Useful when you need to handle binary attributes
64+
- `cache` - Optional, default false. If true, then up to 100 credentials at a time will be cached for 5 minutes.
65+
- `log` - Bunyan logger instance, optional. If given this will result in TRACE-level error logging for component:ldapauth. The logger is also passed forward to ldapjs.
6666

6767
Optional ldapjs options, see [ldapjs documentation](https://github.com/mcavage/node-ldapjs/blob/v1.0.1/docs/client.md):
6868

69-
- `tlsOptions` - Needed for TLS connection. See [Node.js documentation](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback)
70-
- `socketPath`
71-
- `timeout`
72-
- `connectTimeout`
73-
- `idleTimeout`
74-
- `reconnect`
75-
- `strictDN`
76-
- `queueSize`
77-
- `queueTimeout`
78-
- `queueDisable`
69+
- `tlsOptions` - Needed for TLS connection. See [Node.js documentation](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback)
70+
- `socketPath`
71+
- `timeout`
72+
- `connectTimeout`
73+
- `idleTimeout`
74+
- `reconnect`
75+
- `strictDN`
76+
- `queueSize`
77+
- `queueTimeout`
78+
- `queueDisable`
7979

8080
## How it works
8181

@@ -98,22 +98,22 @@ var ldap = new LdapAuth({
9898
bindCredentials: 'mypassword',
9999
searchBase: 'ou=users,dc=example,dc=org',
100100
searchFilter: '(uid={{username}})',
101-
reconnect: true
101+
reconnect: true,
102102
});
103103

104-
var rejectBasicAuth = function(res) {
104+
var rejectBasicAuth = function (res) {
105105
res.statusCode = 401;
106106
res.setHeader('WWW-Authenticate', 'Basic realm="Example"');
107107
res.end('Access denied');
108-
}
108+
};
109109

110-
var basicAuthMiddleware = function(req, res, next) {
110+
var basicAuthMiddleware = function (req, res, next) {
111111
var credentials = basicAuth(req);
112112
if (!credentials) {
113113
return rejectBasicAuth(res);
114114
}
115115

116-
ldap.authenticate(credentials.name, credentials.pass, function(err, user) {
116+
ldap.authenticate(credentials.name, credentials.pass, function (err, user) {
117117
if (err) {
118118
return rejectBasicAuth(res);
119119
}

lib/cache.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
var assert = require('assert');
1616
var LRU = require('lru-cache');
1717

18-
1918
/**
2019
* A LRU and expiring cache.
2120
*
@@ -31,7 +30,7 @@ function Cache(size, expiry, log, name) {
3130
this.size = size;
3231
this.expiry = expiry * 1000;
3332
this.log = log;
34-
this.name = (name ? name + ' ' : '');
33+
this.name = name ? name + ' ' : '';
3534
this.items = new LRU({ max: this.size });
3635
}
3736

@@ -57,7 +56,7 @@ Cache.prototype.get = function get(key) {
5756
assert.ok(key !== undefined);
5857
var cached = this.items.get(key);
5958
if (cached) {
60-
if (((new Date()).getTime() - cached.ctime) <= this.expiry) {
59+
if (new Date().getTime() - cached.ctime <= this.expiry) {
6160
if (this.log) {
6261
this.log.trace('%scache hit: key="%s": %o', this.name, key, cached);
6362
}
@@ -81,7 +80,7 @@ Cache.prototype.set = function set(key, value) {
8180
assert.ok(key !== undefined);
8281
var item = {
8382
value: value,
84-
ctime: new Date().getTime()
83+
ctime: new Date().getTime(),
8584
};
8685
if (this.log) {
8786
this.log.trace('%scache set: key="%s": %o', this.name, key, item);
@@ -103,5 +102,4 @@ Cache.prototype.del = function del(key) {
103102
this.items.del(key);
104103
};
105104

106-
107105
module.exports = Cache;

0 commit comments

Comments
 (0)