@authrim/setup 0.1.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/README.md +303 -0
- package/dist/__tests__/config.test.d.ts +5 -0
- package/dist/__tests__/config.test.d.ts.map +1 -0
- package/dist/__tests__/config.test.js +115 -0
- package/dist/__tests__/config.test.js.map +1 -0
- package/dist/__tests__/keys.test.d.ts +5 -0
- package/dist/__tests__/keys.test.d.ts.map +1 -0
- package/dist/__tests__/keys.test.js +87 -0
- package/dist/__tests__/keys.test.js.map +1 -0
- package/dist/__tests__/naming.test.d.ts +5 -0
- package/dist/__tests__/naming.test.d.ts.map +1 -0
- package/dist/__tests__/naming.test.js +84 -0
- package/dist/__tests__/naming.test.js.map +1 -0
- package/dist/cli/commands/config.d.ts +13 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +231 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/deploy.d.ts +21 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -0
- package/dist/cli/commands/deploy.js +304 -0
- package/dist/cli/commands/deploy.js.map +1 -0
- package/dist/cli/commands/init.d.ts +14 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +1248 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/core/admin.d.ts +64 -0
- package/dist/core/admin.d.ts.map +1 -0
- package/dist/core/admin.js +247 -0
- package/dist/core/admin.js.map +1 -0
- package/dist/core/cloudflare.d.ts +157 -0
- package/dist/core/cloudflare.d.ts.map +1 -0
- package/dist/core/cloudflare.js +452 -0
- package/dist/core/cloudflare.js.map +1 -0
- package/dist/core/config.d.ts +891 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +208 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/deploy.d.ts +81 -0
- package/dist/core/deploy.d.ts.map +1 -0
- package/dist/core/deploy.js +389 -0
- package/dist/core/deploy.js.map +1 -0
- package/dist/core/keys.d.ts +111 -0
- package/dist/core/keys.d.ts.map +1 -0
- package/dist/core/keys.js +287 -0
- package/dist/core/keys.js.map +1 -0
- package/dist/core/lock.d.ts +220 -0
- package/dist/core/lock.d.ts.map +1 -0
- package/dist/core/lock.js +230 -0
- package/dist/core/lock.js.map +1 -0
- package/dist/core/naming.d.ts +151 -0
- package/dist/core/naming.d.ts.map +1 -0
- package/dist/core/naming.js +209 -0
- package/dist/core/naming.js.map +1 -0
- package/dist/core/source.d.ts +68 -0
- package/dist/core/source.d.ts.map +1 -0
- package/dist/core/source.js +285 -0
- package/dist/core/source.js.map +1 -0
- package/dist/core/wrangler.d.ts +87 -0
- package/dist/core/wrangler.d.ts.map +1 -0
- package/dist/core/wrangler.js +398 -0
- package/dist/core/wrangler.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -0
- package/dist/web/api.d.ts +21 -0
- package/dist/web/api.d.ts.map +1 -0
- package/dist/web/api.js +423 -0
- package/dist/web/api.js.map +1 -0
- package/dist/web/server.d.ts +12 -0
- package/dist/web/server.d.ts.map +1 -0
- package/dist/web/server.js +112 -0
- package/dist/web/server.js.map +1 -0
- package/dist/web/ui.d.ts +7 -0
- package/dist/web/ui.d.ts.map +1 -0
- package/dist/web/ui.js +765 -0
- package/dist/web/ui.js.map +1 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# @authrim/setup
|
|
2
|
+
|
|
3
|
+
> CLI and Web UI for setting up Authrim OIDC Provider on Cloudflare Workers
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@authrim/setup)
|
|
6
|
+
[](../../LICENSE)
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
`@authrim/setup` is the official setup tool for deploying [Authrim](https://github.com/sgrastar/authrim) to Cloudflare Workers. It provides both an interactive CLI and a Web UI to guide you through:
|
|
11
|
+
|
|
12
|
+
- Provisioning Cloudflare resources (D1 databases, KV namespaces, Queues)
|
|
13
|
+
- Generating cryptographic keys and secrets
|
|
14
|
+
- Configuring environment-specific settings
|
|
15
|
+
- Deploying all Authrim workers in the correct order
|
|
16
|
+
- Setting up the initial administrator account
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# Using npx (recommended)
|
|
22
|
+
npx @authrim/setup
|
|
23
|
+
|
|
24
|
+
# Or install globally
|
|
25
|
+
npm install -g @authrim/setup
|
|
26
|
+
authrim-setup
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage Modes
|
|
30
|
+
|
|
31
|
+
### 1. Web UI Mode (Default)
|
|
32
|
+
|
|
33
|
+
Run without arguments to launch the interactive Web UI:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx @authrim/setup
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
This opens a browser with a step-by-step wizard that guides you through the entire setup process.
|
|
40
|
+
|
|
41
|
+
### 2. CLI Mode
|
|
42
|
+
|
|
43
|
+
For terminal-based setup or CI/CD integration:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npx @authrim/setup --cli
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 3. Deploy Existing Configuration
|
|
50
|
+
|
|
51
|
+
If you already have an `authrim-config.json`:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx @authrim/setup deploy --config ./authrim-config.json --env prod
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Commands
|
|
58
|
+
|
|
59
|
+
### `init`
|
|
60
|
+
|
|
61
|
+
Initialize a new Authrim project:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
authrim-setup init [options]
|
|
65
|
+
|
|
66
|
+
Options:
|
|
67
|
+
-e, --env <env> Environment name (default: "dev")
|
|
68
|
+
-d, --dir <dir> Output directory (default: ".")
|
|
69
|
+
--keys-dir <dir> Directory for keys (default: ".keys")
|
|
70
|
+
--skip-keys Skip key generation
|
|
71
|
+
--skip-provision Skip resource provisioning
|
|
72
|
+
-y, --yes Skip confirmation prompts
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### `deploy`
|
|
76
|
+
|
|
77
|
+
Deploy Authrim to Cloudflare:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
authrim-setup deploy [options]
|
|
81
|
+
|
|
82
|
+
Options:
|
|
83
|
+
-c, --config <path> Config file path (default: "authrim-config.json")
|
|
84
|
+
-e, --env <env> Environment name
|
|
85
|
+
--component <name> Deploy single component
|
|
86
|
+
--dry-run Preview without deploying
|
|
87
|
+
--skip-secrets Skip secrets upload
|
|
88
|
+
--skip-ui Skip UI deployment
|
|
89
|
+
-y, --yes Skip confirmation prompts
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### `status`
|
|
93
|
+
|
|
94
|
+
Check deployment status:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
authrim-setup status [options]
|
|
98
|
+
|
|
99
|
+
Options:
|
|
100
|
+
-c, --config <path> Config file path
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Configuration Files
|
|
104
|
+
|
|
105
|
+
### authrim-config.json
|
|
106
|
+
|
|
107
|
+
The main configuration file containing all environment settings:
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"version": "1.0.0",
|
|
112
|
+
"environment": {
|
|
113
|
+
"prefix": "prod"
|
|
114
|
+
},
|
|
115
|
+
"urls": {
|
|
116
|
+
"api": {
|
|
117
|
+
"custom": "https://auth.example.com",
|
|
118
|
+
"auto": "https://prod-ar-router.workers.dev"
|
|
119
|
+
},
|
|
120
|
+
"loginUi": {
|
|
121
|
+
"custom": "https://login.example.com",
|
|
122
|
+
"auto": "https://prod-ar-ui.pages.dev"
|
|
123
|
+
},
|
|
124
|
+
"adminUi": {
|
|
125
|
+
"custom": null,
|
|
126
|
+
"auto": "https://prod-ar-ui.pages.dev/admin"
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"components": {
|
|
130
|
+
"api": true,
|
|
131
|
+
"loginUi": true,
|
|
132
|
+
"adminUi": true,
|
|
133
|
+
"saml": false,
|
|
134
|
+
"async": false,
|
|
135
|
+
"vc": false
|
|
136
|
+
},
|
|
137
|
+
"keys": {
|
|
138
|
+
"keyId": "kid-xxxxxxxx",
|
|
139
|
+
"secretsPath": "./.keys/"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### authrim-lock.json
|
|
145
|
+
|
|
146
|
+
Records provisioned resource IDs for re-deployment:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"version": "1.0.0",
|
|
151
|
+
"env": "prod",
|
|
152
|
+
"d1": {
|
|
153
|
+
"DB": { "name": "prod-authrim-core-db", "id": "..." },
|
|
154
|
+
"PII_DB": { "name": "prod-authrim-pii-db", "id": "..." }
|
|
155
|
+
},
|
|
156
|
+
"kv": {
|
|
157
|
+
"CLIENTS_CACHE": { "name": "prod-CLIENTS_CACHE", "id": "..." },
|
|
158
|
+
"SETTINGS": { "name": "prod-SETTINGS", "id": "..." }
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### .keys/ Directory
|
|
164
|
+
|
|
165
|
+
Contains sensitive cryptographic material (gitignored):
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
.keys/
|
|
169
|
+
├── private.pem # RSA private key for JWT signing
|
|
170
|
+
├── public.jwk.json # Public key in JWK format
|
|
171
|
+
├── rp_token_encryption_key.txt
|
|
172
|
+
├── admin_api_secret.txt
|
|
173
|
+
├── key_manager_secret.txt
|
|
174
|
+
└── setup_token.txt # Initial admin setup token
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Deployment Order
|
|
178
|
+
|
|
179
|
+
Authrim workers are deployed in a specific order to satisfy dependencies:
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
Level 0: ar-lib-core # Durable Objects definitions (always first)
|
|
183
|
+
Level 1: ar-discovery # Discovery endpoint
|
|
184
|
+
Level 2: ar-auth, ar-token, ar-userinfo, ar-management # Core services (parallel)
|
|
185
|
+
Level 3: ar-async, ar-saml, ar-vc, ar-bridge # Optional (parallel)
|
|
186
|
+
Level 4: ar-router # Service bindings (always last)
|
|
187
|
+
Level 5: ar-ui # Cloudflare Pages (optional)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Initial Admin Setup
|
|
191
|
+
|
|
192
|
+
After deployment, the CLI displays a one-time setup URL:
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
━━━ Initial Admin Setup ━━━
|
|
196
|
+
|
|
197
|
+
To create the initial administrator account, visit:
|
|
198
|
+
|
|
199
|
+
https://auth.example.com/setup?token=abc123...
|
|
200
|
+
|
|
201
|
+
⚠️ Important:
|
|
202
|
+
• This link expires in 1 hour
|
|
203
|
+
• Setup can only be completed once
|
|
204
|
+
• You will need to register a Passkey (biometric/security key)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
This URL allows you to:
|
|
208
|
+
1. Register a Passkey as the system administrator
|
|
209
|
+
2. Access the Admin Dashboard
|
|
210
|
+
3. Create OAuth clients and configure settings
|
|
211
|
+
|
|
212
|
+
## Security Features
|
|
213
|
+
|
|
214
|
+
- **Session Token Authentication**: API endpoints require session tokens to prevent unauthorized access
|
|
215
|
+
- **Path Traversal Prevention**: Key storage directory is validated to prevent directory traversal attacks
|
|
216
|
+
- **Command Injection Prevention**: Browser launch URLs are validated to prevent shell injection
|
|
217
|
+
- **Error Sanitization**: Error messages are sanitized to prevent information leakage
|
|
218
|
+
- **Operation Locking**: Concurrent operations are serialized to prevent race conditions
|
|
219
|
+
- **Localhost-Only Web UI**: Web UI only binds to localhost for security
|
|
220
|
+
|
|
221
|
+
## Environment Variables
|
|
222
|
+
|
|
223
|
+
| Variable | Description | Default |
|
|
224
|
+
|----------|-------------|---------|
|
|
225
|
+
| `PORT` | Web UI server port | `3456` |
|
|
226
|
+
| `HOST` | Web UI server host | `localhost` |
|
|
227
|
+
|
|
228
|
+
## Development
|
|
229
|
+
|
|
230
|
+
### Local Testing
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
# From the authrim repository root
|
|
234
|
+
cd packages/setup
|
|
235
|
+
|
|
236
|
+
# Run in development mode
|
|
237
|
+
pnpm dev
|
|
238
|
+
|
|
239
|
+
# Build and run
|
|
240
|
+
pnpm build
|
|
241
|
+
pnpm start
|
|
242
|
+
|
|
243
|
+
# Run tests
|
|
244
|
+
pnpm test
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Using with pnpm link
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# In packages/setup
|
|
251
|
+
pnpm build
|
|
252
|
+
pnpm link --global
|
|
253
|
+
|
|
254
|
+
# In another directory
|
|
255
|
+
authrim-setup --help
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Requirements
|
|
259
|
+
|
|
260
|
+
- Node.js >= 20.0.0
|
|
261
|
+
- [Wrangler CLI](https://developers.cloudflare.com/workers/wrangler/) installed and authenticated
|
|
262
|
+
- Cloudflare account with Workers Paid plan (for D1, KV, Durable Objects)
|
|
263
|
+
|
|
264
|
+
## Troubleshooting
|
|
265
|
+
|
|
266
|
+
### "Wrangler is not installed"
|
|
267
|
+
|
|
268
|
+
Install wrangler globally:
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
npm install -g wrangler
|
|
272
|
+
wrangler login
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### "Not logged in to Cloudflare"
|
|
276
|
+
|
|
277
|
+
Authenticate with Cloudflare:
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
wrangler login
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### "Lock file not found"
|
|
284
|
+
|
|
285
|
+
Run the init command first to provision resources:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
authrim-setup init --env prod
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Deployment fails with "Service Bindings"
|
|
292
|
+
|
|
293
|
+
Ensure all dependent workers are deployed. The ar-router must be deployed last as it references other workers via Service Bindings.
|
|
294
|
+
|
|
295
|
+
## License
|
|
296
|
+
|
|
297
|
+
Apache License 2.0 - see [LICENSE](../../LICENSE) for details.
|
|
298
|
+
|
|
299
|
+
## Related
|
|
300
|
+
|
|
301
|
+
- [Authrim Documentation](https://github.com/sgrastar/authrim/tree/main/docs)
|
|
302
|
+
- [Deployment Guide](https://github.com/sgrastar/authrim/blob/main/docs/getting-started/deployment.md)
|
|
303
|
+
- [Development Guide](https://github.com/sgrastar/authrim/blob/main/docs/getting-started/development.md)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/config.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Module Tests
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect } from 'vitest';
|
|
5
|
+
import { AuthrimConfigSchema, createDefaultConfig, parseConfig } from '../core/config.js';
|
|
6
|
+
describe('AuthrimConfigSchema', () => {
|
|
7
|
+
it('should validate a minimal config', () => {
|
|
8
|
+
const config = {
|
|
9
|
+
version: '1.0.0',
|
|
10
|
+
createdAt: new Date().toISOString(),
|
|
11
|
+
environment: { prefix: 'test' },
|
|
12
|
+
tenant: { name: 'default' },
|
|
13
|
+
components: { api: true },
|
|
14
|
+
profile: 'basic-op',
|
|
15
|
+
oidc: {},
|
|
16
|
+
sharding: {},
|
|
17
|
+
features: {},
|
|
18
|
+
keys: {},
|
|
19
|
+
};
|
|
20
|
+
const result = AuthrimConfigSchema.safeParse(config);
|
|
21
|
+
expect(result.success).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
it('should reject invalid profile', () => {
|
|
24
|
+
const config = {
|
|
25
|
+
version: '1.0.0',
|
|
26
|
+
createdAt: new Date().toISOString(),
|
|
27
|
+
environment: { prefix: 'test' },
|
|
28
|
+
tenant: { name: 'default' },
|
|
29
|
+
components: { api: true },
|
|
30
|
+
profile: 'invalid-profile',
|
|
31
|
+
oidc: {},
|
|
32
|
+
sharding: {},
|
|
33
|
+
features: {},
|
|
34
|
+
keys: {},
|
|
35
|
+
};
|
|
36
|
+
const result = AuthrimConfigSchema.safeParse(config);
|
|
37
|
+
expect(result.success).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
it('should validate URL configuration', () => {
|
|
40
|
+
const config = {
|
|
41
|
+
version: '1.0.0',
|
|
42
|
+
createdAt: new Date().toISOString(),
|
|
43
|
+
environment: { prefix: 'prod' },
|
|
44
|
+
tenant: { name: 'default' },
|
|
45
|
+
components: { api: true },
|
|
46
|
+
profile: 'basic-op',
|
|
47
|
+
urls: {
|
|
48
|
+
api: {
|
|
49
|
+
custom: 'https://auth.example.com',
|
|
50
|
+
auto: 'https://prod-ar-router.workers.dev',
|
|
51
|
+
},
|
|
52
|
+
loginUi: {
|
|
53
|
+
custom: null,
|
|
54
|
+
auto: 'https://prod-ar-ui.pages.dev',
|
|
55
|
+
},
|
|
56
|
+
adminUi: {
|
|
57
|
+
custom: null,
|
|
58
|
+
auto: 'https://prod-ar-ui.pages.dev/admin',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
oidc: {},
|
|
62
|
+
sharding: {},
|
|
63
|
+
features: {},
|
|
64
|
+
keys: {},
|
|
65
|
+
};
|
|
66
|
+
const result = AuthrimConfigSchema.safeParse(config);
|
|
67
|
+
expect(result.success).toBe(true);
|
|
68
|
+
if (result.success) {
|
|
69
|
+
expect(result.data.urls?.api?.custom).toBe('https://auth.example.com');
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('createDefaultConfig', () => {
|
|
74
|
+
it('should create a default config with prod prefix', () => {
|
|
75
|
+
const config = createDefaultConfig('prod');
|
|
76
|
+
expect(config.environment.prefix).toBe('prod');
|
|
77
|
+
expect(config.profile).toBe('basic-op');
|
|
78
|
+
expect(config.components.api).toBe(true);
|
|
79
|
+
expect(config.components.loginUi).toBe(true);
|
|
80
|
+
expect(config.components.adminUi).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
it('should create a default config with custom prefix', () => {
|
|
83
|
+
const config = createDefaultConfig('staging');
|
|
84
|
+
expect(config.environment.prefix).toBe('staging');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe('parseConfig', () => {
|
|
88
|
+
it('should parse and validate a config object', () => {
|
|
89
|
+
const rawConfig = {
|
|
90
|
+
version: '1.0.0',
|
|
91
|
+
createdAt: new Date().toISOString(),
|
|
92
|
+
environment: { prefix: 'dev' },
|
|
93
|
+
tenant: { name: 'test-tenant' },
|
|
94
|
+
components: { api: true, loginUi: true },
|
|
95
|
+
profile: 'fapi-rw',
|
|
96
|
+
oidc: { accessTokenTtl: 7200 },
|
|
97
|
+
sharding: { authCodeShards: 32 },
|
|
98
|
+
features: {},
|
|
99
|
+
keys: {},
|
|
100
|
+
};
|
|
101
|
+
const config = parseConfig(rawConfig);
|
|
102
|
+
expect(config.environment.prefix).toBe('dev');
|
|
103
|
+
expect(config.tenant.name).toBe('test-tenant');
|
|
104
|
+
expect(config.profile).toBe('fapi-rw');
|
|
105
|
+
expect(config.oidc.accessTokenTtl).toBe(7200);
|
|
106
|
+
});
|
|
107
|
+
it('should throw on invalid config', () => {
|
|
108
|
+
const invalidConfig = {
|
|
109
|
+
version: '1.0.0',
|
|
110
|
+
// Missing required fields
|
|
111
|
+
};
|
|
112
|
+
expect(() => parseConfig(invalidConfig)).toThrow();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=config.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.test.js","s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AAE,OAAO,EAAE,IAAI,EAAE;YACxC,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE;YAC9B,QAAQ,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE;YAChC,QAAQ,EAAE,EAAE;YACZ,IAAI,EAAE,EAAE;SACT,CAAC;QAEF,MAAM,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;QAEtC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC/C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACxC,MAAM,aAAa,GAAG;YACpB,OAAO,EAAE,OAAO;YAChB,0BAA0B;SAC3B,CAAC;QAEF,MAAM,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/keys.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keys Module Tests
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect } from 'vitest';
|
|
5
|
+
import { generateKeyId, generateRsaKeyPair, generateHexSecret, generateBase64Secret, generateAllSecrets, validatePrivateKey, validatePublicKeyJwk, } from '../core/keys.js';
|
|
6
|
+
describe('generateKeyId', () => {
|
|
7
|
+
it('should generate a key ID with default prefix', () => {
|
|
8
|
+
const keyId = generateKeyId();
|
|
9
|
+
expect(keyId).toMatch(/^dev-key-\d+-[a-zA-Z0-9_-]+$/);
|
|
10
|
+
});
|
|
11
|
+
it('should generate a key ID with custom prefix', () => {
|
|
12
|
+
const keyId = generateKeyId('prod');
|
|
13
|
+
expect(keyId).toMatch(/^prod-key-\d+-[a-zA-Z0-9_-]+$/);
|
|
14
|
+
});
|
|
15
|
+
it('should generate unique key IDs', () => {
|
|
16
|
+
const keyId1 = generateKeyId('test');
|
|
17
|
+
const keyId2 = generateKeyId('test');
|
|
18
|
+
expect(keyId1).not.toBe(keyId2);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe('generateRsaKeyPair', () => {
|
|
22
|
+
it('should generate a valid RSA key pair', () => {
|
|
23
|
+
const keyPair = generateRsaKeyPair('test-key');
|
|
24
|
+
expect(keyPair.keyId).toBe('test-key');
|
|
25
|
+
expect(keyPair.privateKeyPem).toContain('-----BEGIN PRIVATE KEY-----');
|
|
26
|
+
expect(keyPair.publicKeyJwk.kty).toBe('RSA');
|
|
27
|
+
expect(keyPair.publicKeyJwk.kid).toBe('test-key');
|
|
28
|
+
expect(keyPair.publicKeyJwk.use).toBe('sig');
|
|
29
|
+
expect(keyPair.publicKeyJwk.alg).toBe('RS256');
|
|
30
|
+
expect(keyPair.createdAt).toBeDefined();
|
|
31
|
+
});
|
|
32
|
+
it('should generate key with auto-generated ID', () => {
|
|
33
|
+
const keyPair = generateRsaKeyPair();
|
|
34
|
+
expect(keyPair.keyId).toMatch(/^dev-key-\d+-[a-zA-Z0-9_-]+$/);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('generateHexSecret', () => {
|
|
38
|
+
it('should generate 32-byte hex secret by default', () => {
|
|
39
|
+
const secret = generateHexSecret();
|
|
40
|
+
expect(secret).toMatch(/^[a-f0-9]{64}$/);
|
|
41
|
+
});
|
|
42
|
+
it('should generate custom size hex secret', () => {
|
|
43
|
+
const secret = generateHexSecret(16);
|
|
44
|
+
expect(secret).toMatch(/^[a-f0-9]{32}$/);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('generateBase64Secret', () => {
|
|
48
|
+
it('should generate base64url secret', () => {
|
|
49
|
+
const secret = generateBase64Secret();
|
|
50
|
+
expect(secret).toMatch(/^[a-zA-Z0-9_-]+$/);
|
|
51
|
+
expect(secret.length).toBeGreaterThan(0);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('generateAllSecrets', () => {
|
|
55
|
+
it('should generate all required secrets', () => {
|
|
56
|
+
const secrets = generateAllSecrets('test-key');
|
|
57
|
+
expect(secrets.keyPair).toBeDefined();
|
|
58
|
+
expect(secrets.keyPair.keyId).toBe('test-key');
|
|
59
|
+
expect(secrets.rpTokenEncryptionKey).toMatch(/^[a-f0-9]{64}$/);
|
|
60
|
+
expect(secrets.adminApiSecret).toBeDefined();
|
|
61
|
+
expect(secrets.keyManagerSecret).toBeDefined();
|
|
62
|
+
expect(secrets.setupToken).toBeDefined();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe('validatePrivateKey', () => {
|
|
66
|
+
it('should validate a valid RSA private key', () => {
|
|
67
|
+
const keyPair = generateRsaKeyPair();
|
|
68
|
+
expect(validatePrivateKey(keyPair.privateKeyPem)).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
it('should reject invalid private key', () => {
|
|
71
|
+
expect(validatePrivateKey('invalid-key')).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe('validatePublicKeyJwk', () => {
|
|
75
|
+
it('should validate a valid JWK', () => {
|
|
76
|
+
const keyPair = generateRsaKeyPair('test-key');
|
|
77
|
+
expect(validatePublicKeyJwk(keyPair.publicKeyJwk)).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
it('should reject JWK without required fields', () => {
|
|
80
|
+
expect(validatePublicKeyJwk({ kty: 'RSA' })).toBe(false);
|
|
81
|
+
expect(validatePublicKeyJwk({ kty: 'RSA', n: 'xxx', e: 'xxx' })).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
it('should reject non-RSA JWK', () => {
|
|
84
|
+
expect(validatePublicKeyJwk({ kty: 'EC', kid: 'test' })).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=keys.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.test.js","sourceRoot":"","sources":["../../src/__tests__/keys.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAEzB,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,KAAK,GAAG,aAAa,EAAE,CAAC;QAE9B,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QAEpC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACxC,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QACrC,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QAErC,MAAM,CAAC,MAAM,CAAC,CAAC,G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AAC,KAAK,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/naming.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Naming Module Tests
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect } from 'vitest';
|
|
5
|
+
import { getWorkerName, getD1DatabaseName, getKVNamespaceName, getDeploymentOrder, getEnabledComponents, CORE_WORKER_COMPONENTS, WORKER_COMPONENTS, } from '../core/naming.js';
|
|
6
|
+
describe('Worker Naming', () => {
|
|
7
|
+
it('should generate correct worker name', () => {
|
|
8
|
+
expect(getWorkerName('prod', 'ar-auth')).toBe('prod-ar-auth');
|
|
9
|
+
expect(getWorkerName('staging', 'ar-token')).toBe('staging-ar-token');
|
|
10
|
+
expect(getWorkerName('dev', 'ar-lib-core')).toBe('dev-ar-lib-core');
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
describe('D1 Database Naming', () => {
|
|
14
|
+
it('should generate correct database name', () => {
|
|
15
|
+
// dbType includes the '-db' suffix as defined in D1_DATABASES
|
|
16
|
+
expect(getD1DatabaseName('prod', 'core-db')).toBe('prod-authrim-core-db');
|
|
17
|
+
expect(getD1DatabaseName('staging', 'pii-db')).toBe('staging-authrim-pii-db');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe('KV Namespace Naming', () => {
|
|
21
|
+
it('should generate correct KV namespace name', () => {
|
|
22
|
+
expect(getKVNamespaceName('prod', 'CLIENTS_CACHE')).toBe('PROD-CLIENTS_CACHE');
|
|
23
|
+
expect(getKVNamespaceName('staging', 'SETTINGS')).toBe('STAGING-SETTINGS');
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
describe('Component Lists', () => {
|
|
27
|
+
it('should have all core components', () => {
|
|
28
|
+
expect(CORE_WORKER_COMPONENTS).toContain('ar-lib-core');
|
|
29
|
+
expect(CORE_WORKER_COMPONENTS).toContain('ar-auth');
|
|
30
|
+
expect(CORE_WORKER_COMPONENTS).toContain('ar-token');
|
|
31
|
+
expect(CORE_WORKER_COMPONENTS).toContain('ar-router');
|
|
32
|
+
});
|
|
33
|
+
it('should have more components in full list', () => {
|
|
34
|
+
expect(WORKER_COMPONENTS.length).toBeGreaterThanOrEqual(CORE_WORKER_COMPONENTS.length);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('getEnabledComponents', () => {
|
|
38
|
+
it('should return core components by default', () => {
|
|
39
|
+
const components = getEnabledComponents({});
|
|
40
|
+
expect(components.has('ar-lib-core')).toBe(true);
|
|
41
|
+
expect(components.has('ar-auth')).toBe(true);
|
|
42
|
+
expect(components.has('ar-token')).toBe(true);
|
|
43
|
+
expect(components.has('ar-router')).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
it('should add optional components when enabled', () => {
|
|
46
|
+
const components = getEnabledComponents({
|
|
47
|
+
saml: true,
|
|
48
|
+
vc: true,
|
|
49
|
+
});
|
|
50
|
+
expect(components.has('ar-saml')).toBe(true);
|
|
51
|
+
expect(components.has('ar-vc')).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
it('should not include optional components when disabled', () => {
|
|
54
|
+
const components = getEnabledComponents({
|
|
55
|
+
saml: false,
|
|
56
|
+
vc: false,
|
|
57
|
+
});
|
|
58
|
+
expect(components.has('ar-saml')).toBe(false);
|
|
59
|
+
expect(components.has('ar-vc')).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe('getDeploymentOrder', () => {
|
|
63
|
+
it('should return deployment levels for core components', () => {
|
|
64
|
+
const components = getEnabledComponents({});
|
|
65
|
+
const levels = getDeploymentOrder(components);
|
|
66
|
+
expect(levels.length).toBeGreaterThan(0);
|
|
67
|
+
// First level should contain ar-lib-core (DO definition source)
|
|
68
|
+
expect(levels[0]).toContain('ar-lib-core');
|
|
69
|
+
// Last level should contain ar-router
|
|
70
|
+
expect(levels[levels.length - 1]).toContain('ar-router');
|
|
71
|
+
});
|
|
72
|
+
it('should include SAML in correct level', () => {
|
|
73
|
+
const components = getEnabledComponents({ saml: true });
|
|
74
|
+
const levels = getDeploymentOrder(components);
|
|
75
|
+
// Flatten levels to check SAML is included
|
|
76
|
+
const allComponents = levels.flat();
|
|
77
|
+
expect(allComponents).toContain('ar-saml');
|
|
78
|
+
// SAML should come before router
|
|
79
|
+
const samlIndex = allComponents.indexOf('ar-saml');
|
|
80
|
+
const routerIndex = allComponents.indexOf('ar-router');
|
|
81
|
+
expect(samlIndex).toBeLessThan(routerIndex);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=naming.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.test.js","sourceRoot":"","sources":["../../src/__tests__/naming.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAE3B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC9D,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACtE,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACtE,CAA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AC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config Command - Manage Authrim configuration
|
|
3
|
+
*
|
|
4
|
+
* Provides options to show, validate, and modify Authrim configuration.
|
|
5
|
+
*/
|
|
6
|
+
export interface ConfigCommandOptions {
|
|
7
|
+
show?: boolean;
|
|
8
|
+
validate?: boolean;
|
|
9
|
+
json?: boolean;
|
|
10
|
+
config?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function configCommand(options: ConfigCommandOptions): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAMD,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAahF"}
|