poad 2.10.1 → 2.10.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poad",
3
- "version": "2.10.1",
3
+ "version": "2.10.2",
4
4
  "engine": "0.7.0",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
package/utils/keycloak.js CHANGED
@@ -30,6 +30,15 @@ const containerName = (config) => `${config.project_uuid}-keycloak`;
30
30
  const dataDir = (root) => path.join(path.dirname(root), 'data', 'keycloak');
31
31
  const random = (n) => crypto.randomBytes(n).toString('base64url');
32
32
 
33
+ /**
34
+ * Mot de passe à recopier : lettres et chiffres seulement. Un « - » ou un
35
+ * « _ » coupe la sélection au double-clic dans un terminal, et le mot de
36
+ * passe collé est alors tronqué.
37
+ */
38
+ const ALNUM = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789';
39
+ const typeable = (n) => Array.from({ length: n }, () => ALNUM[crypto.randomInt(ALNUM.length)]).join('');
40
+ const isTypeable = (p) => typeof p === 'string' && /^[A-Za-z0-9]+$/.test(p);
41
+
33
42
  /** Le drapeau désigne-t-il Keycloak ? ({ kc: true }, { keycloak: true }) */
34
43
  const wanted = (args = {}) => NAMES.some((n) => args[n]);
35
44
 
@@ -69,19 +78,33 @@ const loadSecrets = (dir) => {
69
78
  const file = path.join(dir, 'users.json');
70
79
  if (fs.existsSync(file)) {
71
80
  const secrets = JSON.parse(fs.readFileSync(file, 'utf-8'));
81
+ let changed = false;
72
82
  if (!secrets.signing_key) {
73
83
  secrets.signing_key = rsaKey();
74
- fs.writeFileSync(file, JSON.stringify(secrets, null, 2) + '\n', { mode: 0o600 });
84
+ changed = true;
85
+ }
86
+ // Anciens mots de passe (base64url, avec « - » ou « _ ») : remplacés. Sans
87
+ // risque ici : Keycloak est recréé et son realm réimporté juste après.
88
+ if (!isTypeable(secrets.admin_password)) {
89
+ secrets.admin_password = typeable(16);
90
+ changed = true;
91
+ }
92
+ for (const u of secrets.users || []) {
93
+ if (!isTypeable(u.password)) {
94
+ u.password = typeable(12);
95
+ changed = true;
96
+ }
75
97
  }
98
+ if (changed) fs.writeFileSync(file, JSON.stringify(secrets, null, 2) + '\n', { mode: 0o600 });
76
99
  return { file, secrets };
77
100
  }
78
101
  const secrets = {
79
102
  signing_key: rsaKey(),
80
103
  client_secret: random(24),
81
- admin_password: random(18),
104
+ admin_password: typeable(16),
82
105
  users: [
83
- { username: 'alice', email: 'alice@poad.test', password: random(9), emailVerified: true },
84
- { username: 'bob', email: 'bob@poad.test', password: random(9), emailVerified: false },
106
+ { username: 'alice', email: 'alice@poad.test', password: typeable(12), emailVerified: true },
107
+ { username: 'bob', email: 'bob@poad.test', password: typeable(12), emailVerified: false },
85
108
  ],
86
109
  };
87
110
  fs.mkdirSync(dir, { recursive: true });
package/utils/services.js CHANGED
@@ -46,8 +46,13 @@ const SERVICES = [
46
46
  // Comptes de test du realm (poad/data/keycloak/users.json) : locaux, faits pour être affichés
47
47
  const users = readKeycloakUsers(root);
48
48
  if (users) {
49
- out['Admin console'] = `http://localhost:${config.keycloak.port}/admin (admin / ${users.admin_password})`;
50
- out['Test users'] = users.users.map((u) => `${u.username} / ${u.password} ${u.email}${u.emailVerified ? '' : ' (email not verified)'}`);
49
+ const base = `http://localhost:${config.keycloak.port}`;
50
+ // Deux realms, deux usages : ne pas essayer alice sur la console d'admin
51
+ out['Admin console'] = [`${base}/admin`, `admin ${users.admin_password}`];
52
+ out['Test users'] = [
53
+ `realm "${kc.REALM}" : "Continuer avec Keycloak" in the app, or ${base}/realms/${kc.REALM}/account`,
54
+ ...users.users.map((u) => `${u.username.padEnd(6)} ${u.password} ${u.email}${u.emailVerified ? '' : ' (email not verified)'}`),
55
+ ];
51
56
  }
52
57
  return out;
53
58
  },