ldap-authentication 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/codeql-analysis.yml +12 -10
- package/AGENTS.md +8 -6
- package/README.md +7 -0
- package/docker/ldap/10-ldap-test-data.ldif +14 -0
- package/index.d.ts +18 -3
- package/index.js +330 -469
- package/package.json +1 -1
- package/test/authentication-result.spec.js +82 -41
- package/test/binary.spec.js +11 -10
- package/test/config.js +9 -0
- package/test/fetch-users.spec.js +23 -32
- package/test/fixtures/jpeg-photo.b64 +1 -0
- package/test/starttls.spec.js +12 -12
- package/test/test.spec.js +123 -41
- package/.github/workflows/publish.yml +0 -53
|
@@ -31,15 +31,20 @@ jobs:
|
|
|
31
31
|
language: [ 'javascript' ]
|
|
32
32
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
|
33
33
|
# Learn more:
|
|
34
|
-
# https://docs.github.com/en/
|
|
34
|
+
# https://docs.github.com/en/code-security/code-scanning/defining-your-code-scanning-policy/configuring-code-scanning-for-your-personal-account-and-repositories/changing-your-code-scanning-configuration#changing-the-languages-that-are-analyzed
|
|
35
35
|
|
|
36
36
|
steps:
|
|
37
37
|
- name: Checkout repository
|
|
38
|
-
uses: actions/checkout@
|
|
38
|
+
uses: actions/checkout@v4
|
|
39
|
+
|
|
40
|
+
- name: Use Node.js 24.x
|
|
41
|
+
uses: actions/setup-node@v4
|
|
42
|
+
with:
|
|
43
|
+
node-version: 24.x
|
|
39
44
|
|
|
40
45
|
# Initializes the CodeQL tools for scanning.
|
|
41
46
|
- name: Initialize CodeQL
|
|
42
|
-
uses: github/codeql-action/init@
|
|
47
|
+
uses: github/codeql-action/init@v4
|
|
43
48
|
with:
|
|
44
49
|
languages: ${{ matrix.language }}
|
|
45
50
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
@@ -47,13 +52,10 @@ jobs:
|
|
|
47
52
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
48
53
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
|
49
54
|
|
|
50
|
-
# Autobuild attempts to build any compiled languages
|
|
51
|
-
# If this step fails, then you should remove it and run the build manually (see below)
|
|
55
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
|
56
|
+
# If this step fails, then you should remove it and run the build manually (see below).
|
|
52
57
|
- name: Autobuild
|
|
53
|
-
uses: github/codeql-action/autobuild@
|
|
54
|
-
|
|
55
|
-
# ℹ️ Command-line programs to run using the OS shell.
|
|
56
|
-
# 📚 https://git.io/JvXDl
|
|
58
|
+
uses: github/codeql-action/autobuild@v4
|
|
57
59
|
|
|
58
60
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
|
59
61
|
# and modify them (or add more) to build your code if your project
|
|
@@ -64,4 +66,4 @@ jobs:
|
|
|
64
66
|
# make release
|
|
65
67
|
|
|
66
68
|
- name: Perform CodeQL Analysis
|
|
67
|
-
uses: github/codeql-action/analyze@
|
|
69
|
+
uses: github/codeql-action/analyze@v4
|
package/AGENTS.md
CHANGED
|
@@ -29,8 +29,13 @@ The specs are integration tests against a seeded OpenLDAP container:
|
|
|
29
29
|
|
|
30
30
|
Or all of the above in one shot: `npm run test:local` (`scripts/test-local.sh`).
|
|
31
31
|
|
|
32
|
+
After changing the seed ldifs, rebuild the container first (`docker compose -f
|
|
33
|
+
docker-compose.yml build`) - `up -d` reuses the existing image and the seed
|
|
34
|
+
data is baked into it at build time.
|
|
35
|
+
|
|
32
36
|
Seeded data (see `docker/ldap/*.ldif`): domain `dc=example,dc=com`; users
|
|
33
|
-
`cn=gauss
|
|
37
|
+
`cn=gauss`, `cn=einstein` and `cn=Doe, John` (uid `doe`, used to test DNs with a
|
|
38
|
+
comma in the CN) in `ou=users` (all with password `password`); group
|
|
34
39
|
`cn=科学A部` in `ou=groups` containing gauss; admin
|
|
35
40
|
`cn=read-only-admin,dc=example,dc=com` (password `password`).
|
|
36
41
|
`test/binary.spec.js` MUTATES the directory (adds `jpegPhoto` to gauss), so spec
|
|
@@ -77,16 +82,13 @@ with a single descriptive message, e.g.
|
|
|
77
82
|
`npm view ldap-authentication@N.N.N`. Note that the npm registry's packument
|
|
78
83
|
can lag the publish by a couple of minutes - check the
|
|
79
84
|
`https://registry.npmjs.org/ldap-authentication` `time`/`versions` before
|
|
80
|
-
re-publishing.
|
|
81
|
-
its `npm publish` step fails with E404 because it duplicates the other
|
|
82
|
-
workflow - that failure is expected/harmless; `publish.yml` is a candidate
|
|
83
|
-
for deletion.
|
|
85
|
+
re-publishing.
|
|
84
86
|
|
|
85
87
|
## CI
|
|
86
88
|
|
|
87
89
|
`integration-test.yml` runs on push/PR to `master`: builds the LDAP container from
|
|
88
90
|
`docker-compose.yml`, runs `npm ci` + `npm run test` with `INGITHUB=true` on a
|
|
89
|
-
Node 22.x/24.x matrix. Release events
|
|
91
|
+
Node 22.x/24.x matrix. Release events trigger `npm-publish.yml` (OIDC publish).
|
|
90
92
|
|
|
91
93
|
## When adding a new option
|
|
92
94
|
|
package/README.md
CHANGED
|
@@ -281,6 +281,13 @@ The user object if `authenticate()` is success.
|
|
|
281
281
|
|
|
282
282
|
In version 4, a new function is added: `authenticateResult()`. It has the same call signature as `authenticate()` but returns an object `AuthenticationResult` with more details.
|
|
283
283
|
|
|
284
|
+
`authenticate()` and `fetchUsers()` throw a `LdapAuthenticationError` on failure:
|
|
285
|
+
- `authenticate()`: when the failure corresponds to a known outcome, the
|
|
286
|
+
error's `code` property holds the matching AUTH_RESULT_* constant (the same
|
|
287
|
+
value `authenticateResult()` reports).
|
|
288
|
+
- Missing required options throw a `LdapAuthenticationError` too, with all
|
|
289
|
+
missing fields listed in the message in a single error.
|
|
290
|
+
|
|
284
291
|
`fetchUsers()` returns an array of user objects, one per matched LDAP entry (each with its `dn` and the returned attributes), or an empty array if no user matches the filter.
|
|
285
292
|
|
|
286
293
|
|
|
@@ -30,6 +30,20 @@ gidNumber: 1000
|
|
|
30
30
|
homeDirectory: /home/gauss
|
|
31
31
|
userPassword: {SSHA}u/l8yXCyiWhP3iXpt0UWMyM9ch5sZGFwLXRlc3QtMjAyNg==
|
|
32
32
|
|
|
33
|
+
# Note: the DN line needs the comma in the RDN value escaped (\,), the
|
|
34
|
+
# attribute value line does not - LDIF values are raw strings, but `dn:` is
|
|
35
|
+
# parsed as LDAP DN syntax (RFC 4514)
|
|
36
|
+
dn: cn=Doe\, John,ou=users,dc=example,dc=com
|
|
37
|
+
objectClass: inetOrgPerson
|
|
38
|
+
objectClass: posixAccount
|
|
39
|
+
cn: Doe, John
|
|
40
|
+
sn: Doe
|
|
41
|
+
uid: doe
|
|
42
|
+
uidNumber: 1002
|
|
43
|
+
gidNumber: 1002
|
|
44
|
+
homeDirectory: /home/doe
|
|
45
|
+
userPassword: {SSHA}u/l8yXCyiWhP3iXpt0UWMyM9ch5sZGFwLXRlc3QtMjAyNg==
|
|
46
|
+
|
|
33
47
|
dn: cn=einstein,ou=users,dc=example,dc=com
|
|
34
48
|
objectClass: inetOrgPerson
|
|
35
49
|
objectClass: posixAccount
|
package/index.d.ts
CHANGED
|
@@ -84,10 +84,16 @@ declare module 'ldap-authentication' {
|
|
|
84
84
|
/**
|
|
85
85
|
* Authenticate a user against the LDAP server. Kept as `Promise<any>` for
|
|
86
86
|
* backward compatibility; the resolved value has the shape of
|
|
87
|
-
* {@link LdapUserEntry}. Throws {@link LdapAuthenticationError} on failure
|
|
87
|
+
* {@link LdapUserEntry}. Throws {@link LdapAuthenticationError} on failure
|
|
88
|
+
* (the error's `code` then holds the corresponding AUTH_RESULT_* constant)
|
|
89
|
+
* or when required options are missing.
|
|
88
90
|
*/
|
|
89
91
|
export function authenticate(options: AuthenticationOptions): Promise<any>
|
|
90
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Same options as {@link authenticate} but never throws on failure; returns an
|
|
94
|
+
* {@link AuthenticationResult}. Throws {@link LdapAuthenticationError} when
|
|
95
|
+
* required options are missing.
|
|
96
|
+
*/
|
|
91
97
|
export function authenticateResult(options: AuthenticationOptions): Promise<AuthenticationResult>
|
|
92
98
|
|
|
93
99
|
/**
|
|
@@ -99,8 +105,17 @@ declare module 'ldap-authentication' {
|
|
|
99
105
|
*/
|
|
100
106
|
export function fetchUsers(options: FetchUsersOptions): Promise<LdapUserEntry[]>
|
|
101
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Thrown by authenticate()/authenticateResult()/fetchUsers() on failure.
|
|
110
|
+
* `message` describes the failure. When the failure corresponds to a known
|
|
111
|
+
* authentication outcome, `code` holds the matching AUTH_RESULT_* constant
|
|
112
|
+
* (the same value authenticateResult() reports in `AuthenticationResult.code`).
|
|
113
|
+
* Missing required options also throw this error, with all missing fields
|
|
114
|
+
* listed in `message`.
|
|
115
|
+
*/
|
|
102
116
|
export class LdapAuthenticationError extends Error {
|
|
103
|
-
constructor(message: any)
|
|
117
|
+
constructor(message: any, code?: number)
|
|
104
118
|
name: string
|
|
119
|
+
code?: number
|
|
105
120
|
}
|
|
106
121
|
}
|