cf05b3a072
--- type: change message: |- Refactor commit type and logic to account for future commit types This commit introduces a CommitInterface which CommitChange (previously ChangeCommit) now implements. Additionally, now all commit messages will include a type field and a "---" separator. The code is written to still accept all the old commit messages used in this repo. Other than those changes, most of this is just rearranging existing code. change_hash: AHjWAUxCjXgOL0Sb+oQZc6TmuVgVHJn08zpGreYyChwx credentials: - type: pgp_signature pub_key_id: 95C46FA6A41148AC body: iQIzBAABAgAdFiEEJ6tQKp6olvZKJ0lwlcRvpqQRSKwFAl5gOuoACgkQlcRvpqQRSKxapA//bODd2IwX2D7nFBkEEd00ol1l4vaw7pgwCjqyQtyskeCZ5IH6H6PkYOSmU9DIBde+cGo35Oi5ynChmfnSatvUZ1dLRJqm8FfOGDw/IsccyYDd1iptj16Ckr6Bsht1XgFJNN10hufuAg77fRIwbGi003WCQdnrJZ1Xbtgex6a4rUqVFW+sjXAB1msmo5B5nabfm/ta0epptxhlINIY2qP5Vb+ftdb2lRUNQwkIEr5GErfAgN3sxYEfqQvLzr/007tEeVznyhdgww47awWsBaTEd6njycbWpphnNA8PbcgUGKDYsj3qLz/bCR1VQOdWgod8PLEru2O+uC2+72ssfT9NDn8HB/WrBKG4W4oykJIhXJ5um18/B9ZSxPMlTQv2Yr4nF7w+Sx3UynEdUTducbIOUq2K+JnI+Ln3gHe0yRw5UEfrzymR4f2Nfe1I13rJk2W7SVRDmOYidr0MwBlLs8tmnJFMWmWZtd1hpPOpyOyUF1jKgvMuR9ferb5niuc3Lk4trqDiaF+tjy/NmAv/7c+qiVmKKpVJVVqvT60TqBR9DTHjRGktcPFD50sc811Th+Xd9RdhzpIYM+0DT790FTf8E0hY6wm/NKTGplfqwBSNZk87SeIiFTu7sZWVpAaPz1vTmVGduC1oj3/Zlv6TzNrUAp3VwBepROBhZlHCHUr9tKg= account: mediocregopher
62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
package dehub
|
|
|
|
import (
|
|
"dehub/sigcred"
|
|
"testing"
|
|
|
|
"gopkg.in/src-d/go-git.v4"
|
|
"gopkg.in/src-d/go-git.v4/plumbing"
|
|
yaml "gopkg.in/yaml.v2"
|
|
)
|
|
|
|
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(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"
|
|
|
|
cfgBody, err := yaml.Marshal(h.cfg)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
h.stage(map[string]string{ConfigPath: string(cfgBody)})
|
|
_, badHash := h.changeCommit("add toot user", h.cfg.Accounts[1].ID, newSig)
|
|
|
|
if err := h.repo.VerifyCommit(MainRefName, badHash); err == nil {
|
|
t.Fatal("toot user shouldn't be able to add itself to config")
|
|
}
|
|
h.reset(hash, git.HardReset)
|
|
|
|
// now add with the root user, this should work.
|
|
h.stage(map[string]string{ConfigPath: string(cfgBody)})
|
|
_, 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)
|
|
}
|
|
}
|
|
}
|