Refuse to freshen a signed manifest without --sign-key (closes #191)
check / check (push) Waiting to run
check / check (push) Waiting to run
freshen built the new manifest from its flags alone, so a signed manifest freshened without --sign-key came out unsigned while the log said its signature verified. freshen now stops after loading such a manifest, before scanning, with an error naming the signer's fingerprint and --sign-key, and leaves the manifest as it was. With --sign-key it rewrites and signs as before. The library gains Signer() on the loaded manifest: the signing key's fingerprint, or nil when the manifest is unsigned, as Checker.Signer gives it. Model: opus-5-5
This commit is contained in:
@@ -73,6 +73,56 @@ func TestGenAndFreshenSignWithKeyFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestFreshenSignedManifestNeedsSignKey runs freshen on a signed manifest
|
||||
// after a file is added. Without --sign-key it must fail, naming the
|
||||
// signer and --sign-key, and leave the manifest as it was; with --sign-key
|
||||
// it must rewrite the manifest, signed.
|
||||
func TestFreshenSignedManifestNeedsSignKey(t *testing.T) {
|
||||
t.Setenv(envSignKeyPassphrase, "")
|
||||
|
||||
secretKey, fingerprint := testSecretKey(t, nil, nil)
|
||||
|
||||
fs := afero.NewOsFs()
|
||||
keyFile := filepath.Join(t.TempDir(), "key.asc")
|
||||
root := t.TempDir()
|
||||
manifestPath := filepath.Join(root, defaultManifestName)
|
||||
|
||||
require.NoError(t, afero.WriteFile(fs, keyFile, secretKey, 0o600))
|
||||
writeTestFile(t, fs, filepath.Join(root, testFileTxt), "hello")
|
||||
|
||||
opts := testOpts([]string{
|
||||
testApp, cmdGenerate, "-q", testFlagSignKey, keyFile,
|
||||
"-o", manifestPath, root,
|
||||
}, fs)
|
||||
require.Equal(t, 0, runCLI(opts), testStderr(t, opts))
|
||||
|
||||
before, err := afero.ReadFile(fs, manifestPath)
|
||||
require.NoError(t, err)
|
||||
|
||||
writeTestFile(t, fs, filepath.Join(root, "added.txt"), "added")
|
||||
|
||||
opts = testOpts([]string{testApp, cmdFreshen, "-q", manifestPath}, fs)
|
||||
assert.Equal(t, 1, runCLI(opts))
|
||||
assert.Contains(t, testStderr(t, opts), fingerprint)
|
||||
assert.Contains(t, testStderr(t, opts), testFlagSignKey)
|
||||
|
||||
after, err := afero.ReadFile(fs, manifestPath)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, before, after)
|
||||
|
||||
opts = testOpts([]string{
|
||||
testApp, cmdFreshen, "-q", testFlagSignKey, keyFile, manifestPath,
|
||||
}, fs)
|
||||
require.Equal(t, 0, runCLI(opts), testStderr(t, opts))
|
||||
|
||||
opts = testOpts([]string{
|
||||
testApp, cmdCheck, "-q",
|
||||
"--" + flagRequireSignature, fingerprint, manifestPath,
|
||||
}, fs)
|
||||
require.Equal(t, 0, runCLI(opts), testStderr(t, opts))
|
||||
assert.Len(t, manifestFiles(t, fs, manifestPath), 2)
|
||||
}
|
||||
|
||||
// TestSignWithProtectedKeyNeedsPassphrase runs gen with a protected key,
|
||||
// with MFER_SIGN_KEY_PASSPHRASE empty and no terminal to ask on. gen must
|
||||
// fail, naming the variable, and write no manifest.
|
||||
|
||||
Reference in New Issue
Block a user