-
Notifications
You must be signed in to change notification settings - Fork 314
Add support for signing checkpoint commits #960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a719b0e
Sign checkpoint commits using the ObjectSigner plugin
pjbgf 41ed93f
Sign all commit types using ObjectSigner plugin
pjbgf 5e46670
Add SSH agent and gate signer warning on commit.gpgSign
pjbgf ae01a9c
Make SignCommitBestEffort truly best-effort and add sign_checkpoint_c…
pjbgf a2945a4
Add checkpoint commit signing documentation
pjbgf d3b8352
Refactor object signer registration
pjbgf 1748686
Reduce mergeJSON cyclomatic complexity by extracting typed helpers
pjbgf e147555
Merge branch 'main' into pjbgf/sign-commits
gtrrz-victor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| package checkpoint | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "io" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/entireio/cli/cmd/entire/cli/paths" | ||
|
|
||
| "github.com/go-git/go-git/v6/plumbing" | ||
| "github.com/go-git/go-git/v6/plumbing/object" | ||
| "github.com/go-git/go-git/v6/x/plugin" | ||
| ) | ||
|
|
||
| type stubSigner struct { | ||
| sig []byte | ||
| err error | ||
| } | ||
|
|
||
| func (s *stubSigner) Sign(_ io.Reader) ([]byte, error) { | ||
| return s.sig, s.err | ||
| } | ||
|
|
||
| func setupSigningEnv(t *testing.T, disableSigning bool) { | ||
| t.Helper() | ||
|
|
||
| dir := t.TempDir() | ||
|
|
||
| // Minimal git repo so paths.WorktreeRoot resolves. | ||
| if err := os.MkdirAll(filepath.Join(dir, ".git"), 0o755); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| entireDir := filepath.Join(dir, ".entire") | ||
| if err := os.MkdirAll(entireDir, 0o755); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if disableSigning { | ||
| content := `{"sign_checkpoint_commits": false}` | ||
| if err := os.WriteFile(filepath.Join(entireDir, "settings.json"), []byte(content), 0o644); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
|
|
||
| paths.ClearWorktreeRootCache() | ||
| t.Chdir(dir) | ||
| t.Cleanup(func() { | ||
| resetPluginEntry("object-signer") | ||
| paths.ClearWorktreeRootCache() | ||
| }) | ||
| } | ||
|
|
||
| func newTestCommit() *object.Commit { | ||
| sig := object.Signature{ | ||
| Name: "Test", | ||
| Email: "test@test.com", | ||
| When: time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC), | ||
| } | ||
| return &object.Commit{ | ||
| TreeHash: plumbing.ZeroHash, | ||
| Author: sig, | ||
| Committer: sig, | ||
| Message: "test commit", | ||
| } | ||
| } | ||
|
|
||
| func TestSignCommitBestEffort_Signs(t *testing.T) { //nolint:paralleltest // t.Chdir requires non-parallel | ||
| setupSigningEnv(t, false) | ||
|
|
||
| err := plugin.Register(plugin.ObjectSigner(), func() plugin.Signer { | ||
| return &stubSigner{sig: []byte("FAKESIG")} | ||
| }) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| commit := newTestCommit() | ||
| SignCommitBestEffort(context.Background(), commit) | ||
|
|
||
| if commit.Signature != "FAKESIG" { | ||
| t.Errorf("expected signature %q, got %q", "FAKESIG", commit.Signature) | ||
| } | ||
| } | ||
|
|
||
| func TestSignCommitBestEffort_SkipsWhenDisabled(t *testing.T) { //nolint:paralleltest // t.Chdir requires non-parallel | ||
| setupSigningEnv(t, true) | ||
|
|
||
| err := plugin.Register(plugin.ObjectSigner(), func() plugin.Signer { | ||
| t.Fatal("signer should not be called when signing is disabled") | ||
| return nil | ||
| }) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| commit := newTestCommit() | ||
| SignCommitBestEffort(context.Background(), commit) | ||
|
|
||
| if commit.Signature != "" { | ||
| t.Errorf("expected empty signature, got %q", commit.Signature) | ||
| } | ||
| } | ||
|
|
||
| func TestSignCommitBestEffort_ErrorIsBestEffort(t *testing.T) { //nolint:paralleltest // t.Chdir requires non-parallel | ||
| setupSigningEnv(t, false) | ||
|
|
||
| err := plugin.Register(plugin.ObjectSigner(), func() plugin.Signer { | ||
| return &stubSigner{err: errors.New("signing failed")} | ||
| }) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| commit := newTestCommit() | ||
| SignCommitBestEffort(context.Background(), commit) | ||
|
|
||
| if commit.Signature != "" { | ||
| t.Errorf("expected empty signature after error, got %q", commit.Signature) | ||
| } | ||
| } | ||
|
|
||
| func TestSignCommitBestEffort_NoSignerRegistered(t *testing.T) { //nolint:paralleltest // t.Chdir requires non-parallel | ||
| setupSigningEnv(t, false) | ||
|
|
||
| commit := newTestCommit() | ||
| SignCommitBestEffort(context.Background(), commit) | ||
|
|
||
| if commit.Signature != "" { | ||
| t.Errorf("expected empty signature without signer, got %q", commit.Signature) | ||
| } | ||
| } | ||
|
|
||
| func TestSignCommitBestEffort_NilSigner(t *testing.T) { //nolint:paralleltest // t.Chdir requires non-parallel | ||
| setupSigningEnv(t, false) | ||
|
|
||
| err := plugin.Register(plugin.ObjectSigner(), func() plugin.Signer { | ||
| return nil | ||
| }) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| commit := newTestCommit() | ||
| SignCommitBestEffort(context.Background(), commit) | ||
|
|
||
| if commit.Signature != "" { | ||
| t.Errorf("expected empty signature with nil signer, got %q", commit.Signature) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.