keycloak-api-manager 6.0.3 → 6.0.4
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/README.md +43 -22
- package/docs/api/configuration.md +6 -16
- package/docs/api-reference.md +6 -6
- package/docs/architecture.md +2 -3
- package/docs/guides/PKCE-Login-Flow.md +4 -17
- package/docs/test-configuration.md +2 -58
- package/docs/testing.md +160 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,11 +25,13 @@ It provides a stable, function-oriented interface for managing Keycloak resource
|
|
|
25
25
|
npm install keycloak-api-manager
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
## OIDC Deprecation Notice
|
|
29
|
+
|
|
30
|
+
DEPRECATION NOTICE (v6.0.0): The OIDC authentication methods (login(), loginPKCE(), generateAuthorizationUrl(), auth()) have been deprecated and moved to keycloak-express-middleware.
|
|
31
|
+
|
|
32
|
+
This package is now exclusively for Keycloak admin resource management. For user authentication flows, use keycloak-express-middleware instead.
|
|
33
|
+
|
|
34
|
+
See [OIDC_MIGRATION_PLAN.md](OIDC_MIGRATION_PLAN.md) for migration details.
|
|
33
35
|
|
|
34
36
|
## Quick Start
|
|
35
37
|
|
|
@@ -46,6 +48,8 @@ await KeycloakManager.configure({
|
|
|
46
48
|
tokenLifeSpan: 60
|
|
47
49
|
});
|
|
48
50
|
|
|
51
|
+
// Alternative after configure(): update runtime context (for example realm)
|
|
52
|
+
// without re-authenticating or calling configure() again.
|
|
49
53
|
KeycloakManager.setConfig({ realmName: 'my-realm' });
|
|
50
54
|
|
|
51
55
|
const users = await KeycloakManager.users.find({ max: 20 });
|
|
@@ -54,19 +58,41 @@ console.log(users.length);
|
|
|
54
58
|
KeycloakManager.stop();
|
|
55
59
|
```
|
|
56
60
|
|
|
57
|
-
> **💡 Tip:** For user authentication (including Authorization Code + PKCE), use [`keycloak-express-middleware`](https://github.com/smartenv-crs4/keycloak-express-middleware). OIDC methods in this package are deprecated and kept only for backward compatibility.
|
|
58
|
-
|
|
59
61
|
## Keycloak Feature Flags
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
Some APIs exposed by this package depend on Keycloak server features that are disabled by default. Enable these flags when you want full endpoint coverage (local dev, CI, or production environments that use these modules):
|
|
62
64
|
|
|
63
65
|
```bash
|
|
64
66
|
--features=admin-fine-grained-authz:v1,organization,client-policies
|
|
65
67
|
```
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
What each flag is for:
|
|
70
|
+
|
|
71
|
+
- `admin-fine-grained-authz:v1`: enables management-permissions endpoints used by group/user fine-grained permission flows.
|
|
72
|
+
- `organization`: enables Organizations APIs.
|
|
73
|
+
- `client-policies`: enables Client Policies and Client Profiles APIs.
|
|
74
|
+
|
|
75
|
+
When you can skip them:
|
|
76
|
+
|
|
77
|
+
- If you only use core admin operations (for example realms/users/clients CRUD), the package still works without these flags.
|
|
78
|
+
- If you use `organizations`, `clientPolicies`, or management-permissions methods, these flags are required.
|
|
79
|
+
|
|
80
|
+
### Why `admin-fine-grained-authz:v1` in Keycloak 26.x
|
|
68
81
|
|
|
69
|
-
In Keycloak 26.x, management-permissions APIs used by
|
|
82
|
+
In Keycloak 26.x, the management-permissions APIs used by this package are compatible with the `v1` variant, so `admin-fine-grained-authz:v1` is the recommended setting.
|
|
83
|
+
|
|
84
|
+
### Example (Docker)
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
docker run -d --name keycloak \
|
|
88
|
+
-p 8080:8080 \
|
|
89
|
+
-e KEYCLOAK_ADMIN=admin \
|
|
90
|
+
-e KEYCLOAK_ADMIN_PASSWORD=admin \
|
|
91
|
+
-e KC_FEATURES=admin-fine-grained-authz:v1,organization,client-policies \
|
|
92
|
+
quay.io/keycloak/keycloak:latest start-dev
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
See [Keycloak Setup and Feature Flags](docs/keycloak-setup.md) for full setup details.
|
|
70
96
|
|
|
71
97
|
## Public API Entry Points
|
|
72
98
|
|
|
@@ -74,12 +100,6 @@ In Keycloak 26.x, management-permissions APIs used by group/user fine-grained te
|
|
|
74
100
|
- `setConfig(overrides)`
|
|
75
101
|
- `getToken()`
|
|
76
102
|
- `stop()`
|
|
77
|
-
- ~~`login(credentials)`~~ **DEPRECATED** - moved to keycloak-express-middleware
|
|
78
|
-
- ~~`generateAuthorizationUrl(options)`~~ **DEPRECATED** - moved to keycloak-express-middleware
|
|
79
|
-
- ~~`loginPKCE(credentials)`~~ **DEPRECATED** - moved to keycloak-express-middleware
|
|
80
|
-
- ~~`auth(credentials)`~~ **DEPRECATED** - moved to keycloak-express-middleware
|
|
81
|
-
|
|
82
|
-
**Note:** OIDC authentication methods have been deprecated in v6.0.0. Use [`keycloak-express-middleware`](https://github.com/smartenv-crs4/keycloak-express-middleware) for user authentication flows.
|
|
83
103
|
|
|
84
104
|
Configured handler namespaces:
|
|
85
105
|
|
|
@@ -104,7 +124,7 @@ All documentation is centralized under `docs/`.
|
|
|
104
124
|
|
|
105
125
|
### Guides
|
|
106
126
|
|
|
107
|
-
- [OIDC Migration Plan](OIDC_MIGRATION_PLAN.md) -
|
|
127
|
+
- [OIDC Migration Plan](OIDC_MIGRATION_PLAN.md) - Migration notes for legacy OIDC helpers
|
|
108
128
|
|
|
109
129
|
### API Reference
|
|
110
130
|
|
|
@@ -129,13 +149,13 @@ All documentation is centralized under `docs/`.
|
|
|
129
149
|
|
|
130
150
|
- [Architecture and Runtime](docs/architecture.md)
|
|
131
151
|
- [Keycloak Setup and Feature Flags](docs/keycloak-setup.md)
|
|
132
|
-
- [Testing Guide](docs/testing.md)
|
|
133
|
-
- [Test Configuration](docs/test-configuration.md)
|
|
152
|
+
- [Testing Guide](docs/testing.md) — setup, configuration, commands, and test architecture
|
|
134
153
|
- [Deployment (Local/Remote, HTTP/HTTPS)](docs/deployment.md)
|
|
135
154
|
|
|
136
155
|
## Testing
|
|
137
156
|
|
|
138
157
|
```bash
|
|
158
|
+
npm run setup-keycloak
|
|
139
159
|
npm test
|
|
140
160
|
```
|
|
141
161
|
|
|
@@ -145,6 +165,8 @@ Or test workspace only:
|
|
|
145
165
|
npm --prefix test test
|
|
146
166
|
```
|
|
147
167
|
|
|
168
|
+
`npm run setup-keycloak` is an interactive helper that can start Keycloak via Docker Compose (local/remote, HTTP/HTTPS) and update the test `baseUrl` in config.
|
|
169
|
+
|
|
148
170
|
The suite runs against a real Keycloak instance and provisions a shared test realm during setup.
|
|
149
171
|
|
|
150
172
|
## Repository Structure
|
|
@@ -163,14 +185,13 @@ docs/ # Centralized documentation
|
|
|
163
185
|
|
|
164
186
|
## Versioning and Compatibility
|
|
165
187
|
|
|
166
|
-
- Package version: `6.0.
|
|
188
|
+
- Package version: `6.0.3`
|
|
167
189
|
- Keycloak Admin client dependency: `@keycloak/keycloak-admin-client`
|
|
168
190
|
- Main compatibility target: Keycloak 25/26
|
|
169
191
|
|
|
170
192
|
### Breaking Changes in v6.0.0
|
|
171
193
|
|
|
172
|
-
OIDC
|
|
173
|
-
These methods will be removed in v7.0.0. Migrate to `keycloak-express-middleware` for user authentication.
|
|
194
|
+
See OIDC Deprecation Notice.
|
|
174
195
|
|
|
175
196
|
## License
|
|
176
197
|
|
|
@@ -7,7 +7,7 @@ Core API methods for initializing and managing the Keycloak Admin Client connect
|
|
|
7
7
|
- [configure()](#configure)
|
|
8
8
|
- [setConfig()](#setconfig)
|
|
9
9
|
- [getToken()](#gettoken)
|
|
10
|
-
- [
|
|
10
|
+
- [OIDC Deprecation Notice](#oidc-deprecation-notice)
|
|
11
11
|
- [stop()](#stop)
|
|
12
12
|
|
|
13
13
|
---
|
|
@@ -243,23 +243,13 @@ const response = await axios.get('https://keycloak.example.com/admin/realms/mast
|
|
|
243
243
|
|
|
244
244
|
---
|
|
245
245
|
|
|
246
|
-
##
|
|
246
|
+
## OIDC Deprecation Notice
|
|
247
247
|
|
|
248
|
-
|
|
248
|
+
OIDC authentication helpers are deprecated and retained only for backward compatibility.
|
|
249
249
|
|
|
250
|
-
|
|
251
|
-
- `login(credentials)`
|
|
252
|
-
- `generateAuthorizationUrl(options)`
|
|
253
|
-
- `loginPKCE(credentials)`
|
|
254
|
-
|
|
255
|
-
These methods will be removed in v7.0.0.
|
|
256
|
-
|
|
257
|
-
For all user authentication flows (including Authorization Code + PKCE), use keycloak-express-middleware:
|
|
258
|
-
|
|
259
|
-
- https://github.com/smartenv-crs4/keycloak-express-middleware
|
|
260
|
-
|
|
261
|
-
Migration notes:
|
|
250
|
+
For the canonical deprecation notice and migration path, see:
|
|
262
251
|
|
|
252
|
+
- [README - OIDC Deprecation Notice](../../README.md#oidc-deprecation-notice)
|
|
263
253
|
- [OIDC Migration Plan](../../OIDC_MIGRATION_PLAN.md)
|
|
264
254
|
|
|
265
255
|
---
|
|
@@ -338,7 +328,7 @@ process.on('SIGTERM', () => {
|
|
|
338
328
|
### Notes
|
|
339
329
|
|
|
340
330
|
- Always call `stop()` before application exit to prevent dangling timers.
|
|
341
|
-
- After calling `stop()`, you can call `configure()`
|
|
331
|
+
- After calling `stop()`, you can call `configure()` again to restart.
|
|
342
332
|
- Not calling `stop()` may prevent Node.js process from exiting cleanly.
|
|
343
333
|
|
|
344
334
|
---
|
package/docs/api-reference.md
CHANGED
|
@@ -5,7 +5,7 @@ Complete API documentation for keycloak-api-manager.
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
7
7
|
### Guides
|
|
8
|
-
- [OIDC Migration Plan](../OIDC_MIGRATION_PLAN.md) -
|
|
8
|
+
- [OIDC Migration Plan](../OIDC_MIGRATION_PLAN.md) - Migration notes for legacy OIDC helpers
|
|
9
9
|
|
|
10
10
|
### Core API
|
|
11
11
|
- [Configuration & Authentication](api/configuration.md) - Setup, authentication, and lifecycle management
|
|
@@ -61,7 +61,8 @@ await KeycloakManager.configure({
|
|
|
61
61
|
tokenLifeSpan: 60
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
//
|
|
64
|
+
// Alternative after configure(): switch runtime context without calling
|
|
65
|
+
// configure() again (no new login/token flow is performed).
|
|
65
66
|
KeycloakManager.setConfig({ realmName: 'my-realm' });
|
|
66
67
|
|
|
67
68
|
// Use handlers
|
|
@@ -79,10 +80,7 @@ KeycloakManager.stop();
|
|
|
79
80
|
| `configure()` | Authentication and setup | Core |
|
|
80
81
|
| `setConfig()` | Runtime configuration | Core |
|
|
81
82
|
| `getToken()` | Get current access/refresh token pair | Core |
|
|
82
|
-
|
|
|
83
|
-
| `generateAuthorizationUrl()` | Deprecated PKCE helper (moved to keycloak-express-middleware) | Core |
|
|
84
|
-
| `loginPKCE()` | Deprecated PKCE token exchange helper (moved to keycloak-express-middleware) | Core |
|
|
85
|
-
| `auth()` | Deprecated backward-compatible alias of `login()` | Core |
|
|
83
|
+
| Legacy OIDC helpers | Backward-compatibility methods (`login`, `generateAuthorizationUrl`, `loginPKCE`, `auth`) | Core |
|
|
86
84
|
| `stop()` | Stop token refresh timer | Core |
|
|
87
85
|
| `realms` | Realm management | realmsHandler |
|
|
88
86
|
| `users` | User management | usersHandler |
|
|
@@ -99,6 +97,8 @@ KeycloakManager.stop();
|
|
|
99
97
|
| `clientPolicies` | Client policy management | clientPoliciesHandler |
|
|
100
98
|
| `serverInfo` | Server information | serverInfoHandler |
|
|
101
99
|
|
|
100
|
+
For deprecation status and migration guidance, see [README - OIDC Deprecation Notice](../README.md#oidc-deprecation-notice).
|
|
101
|
+
|
|
102
102
|
## Parameter Conventions
|
|
103
103
|
|
|
104
104
|
Throughout the API:
|
package/docs/architecture.md
CHANGED
|
@@ -15,10 +15,9 @@ This package exposes a single runtime (`index.js`) that initializes one Keycloak
|
|
|
15
15
|
- Keeps active session/token management in place.
|
|
16
16
|
|
|
17
17
|
3. `login(credentials)`
|
|
18
|
-
-
|
|
19
|
-
- Intended for application-level third-party authentication use-cases.
|
|
18
|
+
- Legacy OIDC helper kept for backward compatibility.
|
|
20
19
|
- Does not mutate the internal admin client session established by `configure()`.
|
|
21
|
-
-
|
|
20
|
+
- For deprecation and migration guidance, see the README OIDC Deprecation Notice.
|
|
22
21
|
|
|
23
22
|
4. `stop()`
|
|
24
23
|
- Stops refresh timer for clean process termination.
|
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
# PKCE Login Flow
|
|
1
|
+
# PKCE Login Flow
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
PKCE and user-authentication helpers in this package are deprecated and retained only for backward compatibility.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
- `generateAuthorizationUrl(options)`
|
|
8
|
-
- `loginPKCE(credentials)`
|
|
9
|
-
- `login(credentials)`
|
|
10
|
-
- `auth(credentials)`
|
|
11
|
-
|
|
12
|
-
These methods are planned for removal in v7.0.0.
|
|
13
|
-
|
|
14
|
-
For production user authentication flows (including Authorization Code + PKCE), use:
|
|
15
|
-
|
|
16
|
-
- https://github.com/smartenv-crs4/keycloak-express-middleware
|
|
17
|
-
|
|
18
|
-
Migration references:
|
|
5
|
+
For the canonical deprecation notice and migration path, see:
|
|
19
6
|
|
|
7
|
+
- [README - OIDC Deprecation Notice](../../README.md#oidc-deprecation-notice)
|
|
20
8
|
- [OIDC Migration Plan](../../OIDC_MIGRATION_PLAN.md)
|
|
21
|
-
- [Configuration & Authentication](../api/configuration.md)
|
|
@@ -1,61 +1,5 @@
|
|
|
1
1
|
# Test Configuration
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This file has been merged into the unified [Testing Guide](testing.md).
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
1. `test/config/default.json` (committed defaults)
|
|
8
|
-
2. `test/config/secrets.json` (gitignored sensitive values)
|
|
9
|
-
3. `test/config/local.json` (gitignored machine-specific overrides)
|
|
10
|
-
|
|
11
|
-
The active section is selected by `NODE_ENV` (defaults to `test` in suite bootstrap).
|
|
12
|
-
|
|
13
|
-
## Required Keys
|
|
14
|
-
|
|
15
|
-
- `test.keycloak.baseUrl`
|
|
16
|
-
- `test.keycloak.realmName`
|
|
17
|
-
- `test.keycloak.clientId`
|
|
18
|
-
- `test.keycloak.username`
|
|
19
|
-
- `test.keycloak.password` (typically in `secrets.json`)
|
|
20
|
-
- `test.keycloak.grantType`
|
|
21
|
-
|
|
22
|
-
## Recommended Local Setup
|
|
23
|
-
|
|
24
|
-
1. Keep non-sensitive defaults in `default.json`.
|
|
25
|
-
2. Put secrets in `secrets.json`.
|
|
26
|
-
3. Override per-machine host/ports in `local.json`.
|
|
27
|
-
|
|
28
|
-
Example `local.json` for local Docker Keycloak:
|
|
29
|
-
|
|
30
|
-
```json
|
|
31
|
-
{
|
|
32
|
-
"test": {
|
|
33
|
-
"keycloak": {
|
|
34
|
-
"baseUrl": "http://127.0.0.1:8080"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Example `secrets.json`
|
|
41
|
-
|
|
42
|
-
```json
|
|
43
|
-
{
|
|
44
|
-
"test": {
|
|
45
|
-
"keycloak": {
|
|
46
|
-
"password": "your-admin-password-here"
|
|
47
|
-
},
|
|
48
|
-
"realm": {
|
|
49
|
-
"user": {
|
|
50
|
-
"password": "test-password"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## Security Rules
|
|
58
|
-
|
|
59
|
-
- Never commit `secrets.json`.
|
|
60
|
-
- Never commit production credentials.
|
|
61
|
-
- Keep `default.json` non-sensitive.
|
|
5
|
+
See [Testing Guide — Test Configuration](testing.md#test-configuration) for all config details.
|
package/docs/testing.md
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
# Testing Guide
|
|
2
2
|
|
|
3
|
-
The test suite validates the package against a real Keycloak server.
|
|
3
|
+
The test suite validates the package against a real Keycloak server. This guide covers both test environment setup and configuration.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Quick Start](#quick-start-end-to-end)
|
|
8
|
+
- [Test Configuration](#test-configuration)
|
|
9
|
+
- [Test Architecture](#test-architecture)
|
|
10
|
+
- [Test Layout](#current-test-layout)
|
|
11
|
+
- [Commands](#commands)
|
|
12
|
+
- [HTTPS Variant](#https-variant)
|
|
13
|
+
- [Setup Flow](#setup-flow)
|
|
14
|
+
- [Writing New Tests](#writing-new-tests)
|
|
6
15
|
|
|
7
|
-
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Quick Start (End-to-End)
|
|
8
19
|
|
|
9
20
|
### 1) Install dependencies
|
|
10
21
|
|
|
@@ -15,7 +26,7 @@ npm --prefix test install
|
|
|
15
26
|
|
|
16
27
|
### 2) Prepare local test config
|
|
17
28
|
|
|
18
|
-
Create local override files from examples:
|
|
29
|
+
Create local override files from the provided examples:
|
|
19
30
|
|
|
20
31
|
```bash
|
|
21
32
|
cp test/config/local.json.example test/config/local.json
|
|
@@ -27,7 +38,7 @@ Then edit:
|
|
|
27
38
|
- `test/config/local.json` to set the Keycloak URL you can reach locally.
|
|
28
39
|
- `test/config/secrets.json` to set admin credentials.
|
|
29
40
|
|
|
30
|
-
For local Docker on default HTTP port
|
|
41
|
+
For local Docker on default HTTP port:
|
|
31
42
|
|
|
32
43
|
```json
|
|
33
44
|
{
|
|
@@ -40,7 +51,54 @@ For local Docker on default HTTP port, a common value is:
|
|
|
40
51
|
}
|
|
41
52
|
```
|
|
42
53
|
|
|
43
|
-
### 3)
|
|
54
|
+
### 3) Prepare Keycloak for tests (choose one mode)
|
|
55
|
+
|
|
56
|
+
Choose one of the following modes.
|
|
57
|
+
|
|
58
|
+
#### Mode A: Existing Keycloak instance (no Docker startup here)
|
|
59
|
+
|
|
60
|
+
If you already have a reachable Keycloak instance:
|
|
61
|
+
|
|
62
|
+
- set `test.keycloak.baseUrl` in `test/config/local.json` to that instance URL
|
|
63
|
+
- ensure admin credentials in `test/config/secrets.json` are valid for that instance
|
|
64
|
+
- skip any startup command and run tests directly
|
|
65
|
+
|
|
66
|
+
Example using an existing instance:
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"test": {
|
|
71
|
+
"keycloak": {
|
|
72
|
+
"baseUrl": "https://my-keycloak.company.net"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Then run:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npm test
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Mode B: Automated setup with `npm run setup-keycloak`
|
|
85
|
+
|
|
86
|
+
Use this when you do not already have a ready instance and want the helper to provision one.
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npm run setup-keycloak
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
What this command does:
|
|
93
|
+
|
|
94
|
+
- runs an interactive setup (local or remote, HTTP or HTTPS)
|
|
95
|
+
- starts Keycloak via Docker Compose in the selected mode
|
|
96
|
+
- waits for readiness
|
|
97
|
+
- updates `test/config/default.json` with the generated `test.keycloak.baseUrl`
|
|
98
|
+
|
|
99
|
+
#### Mode C: Manual Docker startup
|
|
100
|
+
|
|
101
|
+
Use this if you prefer full manual control instead of the setup helper:
|
|
44
102
|
|
|
45
103
|
```bash
|
|
46
104
|
docker compose -f test/docker-keycloak/docker-compose.yml up -d
|
|
@@ -65,12 +123,78 @@ npm test
|
|
|
65
123
|
docker compose -f test/docker-keycloak/docker-compose.yml down
|
|
66
124
|
```
|
|
67
125
|
|
|
68
|
-
|
|
126
|
+
To also remove container volumes:
|
|
69
127
|
|
|
70
128
|
```bash
|
|
71
129
|
docker compose -f test/docker-keycloak/docker-compose.yml down -v
|
|
72
130
|
```
|
|
73
131
|
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Test Configuration
|
|
135
|
+
|
|
136
|
+
Test configuration uses `propertiesmanager` with a layered file strategy. Files are merged in this priority order (higher overrides lower):
|
|
137
|
+
|
|
138
|
+
1. `test/config/default.json` — committed defaults, non-sensitive
|
|
139
|
+
2. `test/config/secrets.json` — gitignored, admin credentials and passwords
|
|
140
|
+
3. `test/config/local.json` — gitignored, machine-specific host/port overrides
|
|
141
|
+
|
|
142
|
+
The active section is selected by `NODE_ENV` (defaults to `test` in suite bootstrap).
|
|
143
|
+
|
|
144
|
+
### Required Configuration Keys
|
|
145
|
+
|
|
146
|
+
| Key | Description |
|
|
147
|
+
|-----|-------------|
|
|
148
|
+
| `test.keycloak.baseUrl` | Keycloak server URL |
|
|
149
|
+
| `test.keycloak.realmName` | Realm used for authentication |
|
|
150
|
+
| `test.keycloak.clientId` | Client ID (usually `admin-cli`) |
|
|
151
|
+
| `test.keycloak.username` | Admin username |
|
|
152
|
+
| `test.keycloak.password` | Admin password (put in `secrets.json`) |
|
|
153
|
+
| `test.keycloak.grantType` | Usually `password` |
|
|
154
|
+
|
|
155
|
+
### Recommended Pattern
|
|
156
|
+
|
|
157
|
+
- Keep defaults and non-sensitive values in `default.json`.
|
|
158
|
+
- Put admin passwords and test user passwords in `secrets.json`.
|
|
159
|
+
- Put local machine-specific URLs/ports in `local.json`.
|
|
160
|
+
|
|
161
|
+
Example `local.json`:
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"test": {
|
|
166
|
+
"keycloak": {
|
|
167
|
+
"baseUrl": "http://127.0.0.1:8080"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Example `secrets.json`:
|
|
174
|
+
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"test": {
|
|
178
|
+
"keycloak": {
|
|
179
|
+
"password": "your-admin-password-here"
|
|
180
|
+
},
|
|
181
|
+
"realm": {
|
|
182
|
+
"user": {
|
|
183
|
+
"password": "test-password"
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Security Rules
|
|
191
|
+
|
|
192
|
+
- Never commit `secrets.json` or `local.json`.
|
|
193
|
+
- Never commit production credentials.
|
|
194
|
+
- Keep `default.json` non-sensitive.
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
74
198
|
## Test Architecture
|
|
75
199
|
|
|
76
200
|
The suite uses a shared realm strategy:
|
|
@@ -81,6 +205,8 @@ The suite uses a shared realm strategy:
|
|
|
81
205
|
|
|
82
206
|
This improves speed and keeps the environment deterministic.
|
|
83
207
|
|
|
208
|
+
---
|
|
209
|
+
|
|
84
210
|
## Current Test Layout
|
|
85
211
|
|
|
86
212
|
```text
|
|
@@ -95,9 +221,14 @@ test/
|
|
|
95
221
|
testConfig.js
|
|
96
222
|
```
|
|
97
223
|
|
|
224
|
+
---
|
|
225
|
+
|
|
98
226
|
## Commands
|
|
99
227
|
|
|
100
228
|
```bash
|
|
229
|
+
# interactive provisioning helper (starts docker and sets baseUrl)
|
|
230
|
+
npm run setup-keycloak
|
|
231
|
+
|
|
101
232
|
# full suite
|
|
102
233
|
npm test
|
|
103
234
|
|
|
@@ -109,6 +240,24 @@ npm --prefix test test -- --grep "Organizations Handler Tests"
|
|
|
109
240
|
npm --prefix test test -- --grep "Matrix -"
|
|
110
241
|
```
|
|
111
242
|
|
|
243
|
+
### Command Difference: `npm test` vs `npm --prefix test test`
|
|
244
|
+
|
|
245
|
+
- `npm test` (from repository root): runs the root test script, which first installs test workspace dependencies and then executes the suite.
|
|
246
|
+
- `npm --prefix test test`: runs the test workspace script directly, without performing the install step.
|
|
247
|
+
|
|
248
|
+
Current root script behavior:
|
|
249
|
+
|
|
250
|
+
```text
|
|
251
|
+
npm test => npm --prefix test install && npm --prefix test test
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Practical rule:
|
|
255
|
+
|
|
256
|
+
- use `npm test` when setting up a fresh environment or after dependency changes
|
|
257
|
+
- use `npm --prefix test test` for faster repeated runs when dependencies are already installed
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
112
261
|
## HTTPS Variant
|
|
113
262
|
|
|
114
263
|
For HTTPS-like environments use the dedicated compose file:
|
|
@@ -124,6 +273,8 @@ The cert directory must contain:
|
|
|
124
273
|
- `keycloak.crt`
|
|
125
274
|
- `keycloak.key`
|
|
126
275
|
|
|
276
|
+
---
|
|
277
|
+
|
|
127
278
|
## Setup Flow
|
|
128
279
|
|
|
129
280
|
`test/support/setup.js` runs before all suites and executes `test/support/enableServerFeatures.js` to provision:
|
|
@@ -138,6 +289,8 @@ The cert directory must contain:
|
|
|
138
289
|
|
|
139
290
|
The same bootstrap also performs cleanup in global teardown by deleting the shared test realm.
|
|
140
291
|
|
|
292
|
+
---
|
|
293
|
+
|
|
141
294
|
## Writing New Tests
|
|
142
295
|
|
|
143
296
|
- Import config from `test/testConfig.js`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keycloak-api-manager",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.4",
|
|
4
4
|
"description": "Enhanced Node.js wrapper for Keycloak Admin REST API. Professional alternative to @keycloak/keycloak-admin-client with advanced features, bug fixes, automatic token refresh, Organizations API support, fine-grained permissions, and comprehensive resource management. Battle-tested with 113+ integration tests.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|