configre 2.2.0 → 2.2.1

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": "configre",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "🔧 Effortlessly Tailor Your Settings",
5
5
  "type": "module",
6
6
  "engines": {
package/secrets/index.js CHANGED
@@ -173,7 +173,7 @@ function loadSecrets(configPath, configFile, profile) {
173
173
  } catch (registrationError) {
174
174
  registration = registrationError.code === "CONFIGRE_REGISTRATION_FAILED"
175
175
  ? registrationError.message
176
- : "Automatic public-key registration failed; check Git and file permissions, then reload Configre to retry.";
176
+ : `Automatic public-key registration failed: ${registrationError.message}; check Git and file permissions, then reload Configre to retry.`;
177
177
  outcome = { status: "registration-failed", reason: registration };
178
178
  }
179
179
  log.warn("Secrets not authorized; continuing with public settings only.", registration, "Public key:", identity.publicPath);
@@ -49,7 +49,7 @@ function registerRecipient(paths, identity, profile) {
49
49
  throw registrationError("requires a profile containing only letters, digits, dots, underscores or hyphens");
50
50
  }
51
51
  const root = git(paths.parent, ["rev-parse", "--show-toplevel"], "locating the Git repository").trim();
52
- const lock = git(root, ["rev-parse", "--path-format=absolute", "--git-path", "configre-registration"], "locating the Git lock").trim();
52
+ const lock = path.resolve(root, git(root, ["rev-parse", "--git-path", "configre-registration"], "locating the Git lock").trim());
53
53
  return withLock(lock, () => {
54
54
  const branch = git(root, ["symbolic-ref", "--quiet", "HEAD"], "finding the current branch (detached HEAD is unsupported)").trim();
55
55
  const branchName = branch.slice("refs/heads/".length);
package/test/cli.test.js CHANGED
@@ -99,7 +99,7 @@ test("the editing machine reports created, unchanged and updated encrypted files
99
99
  assert.match(updated.stdout, /^Updated secrets\.enc\.json$/m);
100
100
  });
101
101
 
102
- test("a server registers through Git and becomes authorized after the editing machine syncs", t => {
102
+ function publishedFixture(t) {
103
103
  const f = fixture(t);
104
104
  const { admin, server } = f.homes;
105
105
  writeSecrets(f);
@@ -115,6 +115,13 @@ test("a server registers through Git and becomes authorized after the editing ma
115
115
  git(f.app, admin, ["push", "--quiet", "--set-upstream", "origin", "main"]);
116
116
  const checkout = path.join(f.root, "server");
117
117
  git(f.root, server, ["clone", "--quiet", remote, checkout]);
118
+ return { ...f, remote, checkout };
119
+ }
120
+
121
+ test("a server registers through Git and becomes authorized after the editing machine syncs", t => {
122
+ const f = publishedFixture(t);
123
+ const { admin, server } = f.homes;
124
+ const { remote, checkout } = f;
118
125
 
119
126
  const registered = run(checkout, server, ["sync", "config", "--config=web-01"]);
120
127
  assert.equal(registered.status, 0, registered.stderr);
@@ -139,6 +146,36 @@ test("a server registers through Git and becomes authorized after the editing ma
139
146
  assert.match(authorized.stdout, /^Authorized to decrypt config\/secrets\.enc\.json$/m);
140
147
  });
141
148
 
149
+ test("registration works with Git versions that echo unknown rev-parse options", { skip: process.platform === "win32" }, t => {
150
+ const f = publishedFixture(t);
151
+ const realGit = spawnSync("sh", ["-c", "command -v git"], { encoding: "utf8" }).stdout.trim();
152
+ const shim = path.join(f.root, "old-git");
153
+ fs.mkdirSync(shim);
154
+ fs.writeFileSync(path.join(shim, "git"), [
155
+ "#!/bin/sh",
156
+ "for arg; do shift; if [ \"$arg\" = --path-format=absolute ]; then echo \"$arg\"; else set -- \"$@\" \"$arg\"; fi; done",
157
+ `exec ${JSON.stringify(realGit)} "$@"`,
158
+ ""
159
+ ].join("\n"), { mode: 0o755 });
160
+
161
+ const result = spawnSync(process.execPath, [bin, "sync", "config", "--config=web-01"], {
162
+ cwd: f.checkout,
163
+ env: { ...environment(f.homes.server), PATH: `${shim}${path.delimiter}${process.env.PATH}` },
164
+ encoding: "utf8"
165
+ });
166
+ assert.equal(result.status, 0, result.stderr);
167
+ assert.match(result.stdout, /^Registered config\/recipients\/web-01\.pub and pushed it to Git$/m);
168
+ });
169
+
170
+ test("unexpected registration failures report their cause", t => {
171
+ const f = publishedFixture(t);
172
+ fs.mkdirSync(path.join(f.checkout, "config", "recipients", "web-01.pub"), { recursive: true });
173
+
174
+ const result = run(f.checkout, f.homes.server, ["sync", "config", "--config=web-01"]);
175
+ assert.equal(result.status, 1);
176
+ assert.match(result.stderr, /^Automatic public-key registration failed: Configre secrets: expected a regular file at .*recipients\/web-01\.pub; check Git and file permissions, then reload Configre to retry\.$/m);
177
+ });
178
+
142
179
  test("an unauthorized machine that cannot register exits with the failure reason", t => {
143
180
  const f = fixture(t);
144
181
  writeSecrets(f);