package dehub import ( "testing" "gopkg.in/src-d/go-git.v4/plumbing" ) func TestConfigChange(t *testing.T) { h := newHarness(t) rootSig := h.stageNewAccount("root", false) var gitCommits []GitCommit // commit the initial staged changes, which merely include the config and // public key gitCommit := h.assertCommitChange(true, "commit configuration", rootSig) gitCommits = append(gitCommits, gitCommit) // create a new account and add it to the configuration. That commit should // not be verifiable, though tootSig := h.stageNewAccount("toot", false) h.stageCfg() h.assertCommitChange(false, "add toot user", tootSig) // now add with the root user, this should work. h.stageCfg() gitCommit = h.assertCommitChange(true, "add toot user", rootSig) gitCommits = append(gitCommits, gitCommit) // _now_ the toot user should be able to do things. h.stage(map[string]string{"foo/bar": "what a cool file"}) gitCommit = h.assertCommitChange(true, "add a cool file", tootSig) gitCommits = append(gitCommits, gitCommit) if err := h.repo.VerifyCommits(MainRefName, gitCommits); err != nil { t.Fatal(err) } } func TestMainAncestryRequirement(t *testing.T) { otherBranch := plumbing.NewBranchReferenceName("other") t.Run("empty repo", func(t *testing.T) { h := newHarness(t) rootSig := h.stageNewAccount("root", false) h.checkout(otherBranch) // stage and try to add to the "other" branch, it shouldn't work though h.stageCfg() h.assertCommitChange(false, "starting new branch at other", rootSig) }) t.Run("new branch, single commit", func(t *testing.T) { h := newHarness(t) rootSig := h.stageNewAccount("root", false) h.stageCfg() h.assertCommitChange(true, "add cfg", rootSig) // set HEAD to this other branch which doesn't really exist ref := plumbing.NewSymbolicReference(plumbing.HEAD, otherBranch) if err := h.repo.GitRepo.Storer.SetReference(ref); err != nil { h.t.Fatal(err) } h.stageCfg() h.assertCommitChange(false, "starting new branch at other", rootSig) }) } func TestAnonymousCommits(t *testing.T) { h := newHarness(t) anonSig := h.stageNewAccount("anon", true) h.stageAccessControls(` - action: allow filters: - type: signature any: true `) h.assertCommitChange(true, "this will work", anonSig) }