package dehub import ( "dehub/sigcred" "testing" "gopkg.in/src-d/go-git.v4/plumbing" ) func TestConfigChange(t *testing.T) { h := newHarness(t) var hashes []plumbing.Hash // commit the initial staged changes, which merely include the config and // public key _, hash := h.changeCommit("commit configuration", h.cfg.Accounts[0].ID, h.sig) hashes = append(hashes, hash) // create a new account and add it to the configuration. That commit should // not be verifiable, though newSig, newPubKeyBody := sigcred.SignifierPGPTmp("toot", h.rand) h.cfg.Accounts = append(h.cfg.Accounts, Account{ ID: "toot", Signifiers: []sigcred.Signifier{{PGPPublicKey: &sigcred.SignifierPGP{ Body: string(newPubKeyBody), }}}, }) h.cfg.AccessControls[0].ChangeAccessControls[0].Condition.Signature.AccountIDs = []string{"root", "toot"} h.cfg.AccessControls[0].ChangeAccessControls[0].Condition.Signature.Count = "1" h.stageCfg() badCommit, err := h.repo.NewCommitChange("add toot user") if err != nil { t.Fatalf("creating CommitChange: %v", err) } h.tryCommit(false, badCommit, h.cfg.Accounts[1].ID, newSig) // now add with the root user, this should work. h.stageCfg() _, hash = h.changeCommit("add toot user", h.cfg.Accounts[0].ID, h.sig) hashes = append(hashes, hash) // _now_ the toot user should be able to do things. h.stage(map[string]string{"foo/bar": "what a cool file"}) _, hash = h.changeCommit("add a cool file", h.cfg.Accounts[1].ID, newSig) hashes = append(hashes, hash) for i, hash := range hashes { if err := h.repo.VerifyCommit(MainRefName, hash); err != nil { t.Fatalf("commit %d (%v) should have been verified but wasn't: %v", i, hash, err) } } }