b01fe1524a
--- type: change description: |- Completely refactor naming of everything, in light of new SPEC Writing the SPEC shed some light on just how weakly a lot of concepts, like "commit", had been defined, and prompted the delineation of a lot of things along specific lines (commit vs payload, repo vs project). This commit makes the code reflect the SPEC much better in quite a few ways: * Repo is now Project * Commit is now Payload * GitCommit is now just Commit * Hash is now Fingerprint * A lot of minor fields got renamed * All the XXXInterface types are now just XXX, and their old XXX type is now XXXUnion. More than likely there's still some comments and variable names that have slipped passed, but overall I feel like I got most of the changes. fingerprint: AKkDC5BKhKbfXzZQ/F4KquHeMgVvcNxgLmkZFz/nP/tY credentials: - type: pgp_signature pub_key_id: 95C46FA6A41148AC body: iQIzBAABAgAdFiEEJ6tQKp6olvZKJ0lwlcRvpqQRSKwFAl6l7aYACgkQlcRvpqQRSKxFrA//VQ+f8B6pwGS3ORB4VVBnHvvJTGZvAYTvB0fHuHJx2EreR4FwjhaNakk5ClkwbO7WFMq++2OV4xIkvzwswLdbXZF0IHx3wScQM59v4vIkR4V9Lj5p1aGGhQna52uIKugF2gTqKdU4tqYzmBjDND/c2XDwCN5CwTwwnAHXUSSsHxviiPUYPWV5wzFP7uyRW0ZeK8Isv7QECKRXlsDjcSJa+g+jc091FG/jG9Dkai8fbDbW8YXj7W3ALaXgXWEBJMrgQxZcJJRjgCvLY72FIIrUBquu3FepiyzMtZ0yaIvi4NmGCsYqIv00NcMvMtD7iwhOCZn10Sku4wvaKJ8YBMRduhqC99fnr/ZDW0/HvTNcL7GKx11GjwtmzkJgwsHFPy3zX+kMdF4m3WgtoeI0GwEsBXXZE2C49yAk3Mb/3puegl3a1PPMvOabTzo7Xm6xpWkI6gISChI7My71H3EuKZWhkb+IubPmMvJJXIdVxHnsHPz2dl/BZXLgpfVdEgQa2qWeXtYI4NNm37pLl3gv92V4kka+Kr4gfdoq8mJ7aqvc9was35baJbHg4+fEVJG2Wj+2AQU+ncx3nAFzgYyMxwo9K8VuC4QdfRF4ImyxTnWkuokEn9H6JRrbkBDKIELj6vzdPmsjOUEQ4nsYX66/zSibFD7UvhQmdXFs8Gp8/Qq6g4M= account: mediocregopher
146 lines
2.9 KiB
Go
146 lines
2.9 KiB
Go
package accessctl
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"dehub.dev/src/dehub.git/sigcred"
|
|
)
|
|
|
|
func TestAssertCanCommit(t *testing.T) {
|
|
tests := []struct {
|
|
descr string
|
|
acl []AccessControl
|
|
req CommitRequest
|
|
allowed bool
|
|
}{
|
|
{
|
|
descr: "first allows",
|
|
acl: []AccessControl{
|
|
{
|
|
Action: ActionAllow,
|
|
Filters: []FilterUnion{{
|
|
PayloadType: &FilterPayloadType{Type: "foo"},
|
|
}},
|
|
},
|
|
{
|
|
Action: ActionDeny,
|
|
Filters: []FilterUnion{{
|
|
PayloadType: &FilterPayloadType{Type: "foo"},
|
|
}},
|
|
},
|
|
},
|
|
req: CommitRequest{Type: "foo"},
|
|
allowed: true,
|
|
},
|
|
{
|
|
descr: "first denies",
|
|
acl: []AccessControl{
|
|
{
|
|
Action: ActionDeny,
|
|
Filters: []FilterUnion{{
|
|
PayloadType: &FilterPayloadType{Type: "foo"},
|
|
}},
|
|
},
|
|
{
|
|
Action: ActionAllow,
|
|
Filters: []FilterUnion{{
|
|
PayloadType: &FilterPayloadType{Type: "foo"},
|
|
}},
|
|
},
|
|
},
|
|
req: CommitRequest{Type: "foo"},
|
|
allowed: false,
|
|
},
|
|
{
|
|
descr: "second allows",
|
|
acl: []AccessControl{
|
|
{
|
|
Action: ActionDeny,
|
|
Filters: []FilterUnion{{
|
|
PayloadType: &FilterPayloadType{Type: "bar"},
|
|
}},
|
|
},
|
|
{
|
|
Action: ActionAllow,
|
|
Filters: []FilterUnion{{
|
|
PayloadType: &FilterPayloadType{Type: "foo"},
|
|
}},
|
|
},
|
|
},
|
|
req: CommitRequest{Type: "foo"},
|
|
allowed: true,
|
|
},
|
|
{
|
|
descr: "second denies",
|
|
acl: []AccessControl{
|
|
{
|
|
Action: ActionDeny,
|
|
Filters: []FilterUnion{{
|
|
PayloadType: &FilterPayloadType{Type: "bar"},
|
|
}},
|
|
},
|
|
{
|
|
Action: ActionDeny,
|
|
Filters: []FilterUnion{{
|
|
PayloadType: &FilterPayloadType{Type: "foo"},
|
|
}},
|
|
},
|
|
},
|
|
req: CommitRequest{Type: "foo"},
|
|
allowed: false,
|
|
},
|
|
{
|
|
descr: "default allows",
|
|
acl: []AccessControl{
|
|
{
|
|
Action: ActionDeny,
|
|
Filters: []FilterUnion{{
|
|
PayloadType: &FilterPayloadType{Type: "bar"},
|
|
}},
|
|
},
|
|
},
|
|
req: CommitRequest{
|
|
Branch: "not_main",
|
|
Type: "foo",
|
|
Credentials: []sigcred.CredentialUnion{{
|
|
PGPSignature: new(sigcred.CredentialPGPSignature),
|
|
AccountID: "a",
|
|
}},
|
|
},
|
|
allowed: true,
|
|
},
|
|
{
|
|
descr: "default denies",
|
|
acl: []AccessControl{
|
|
{
|
|
Action: ActionDeny,
|
|
Filters: []FilterUnion{{
|
|
PayloadType: &FilterPayloadType{Type: "bar"},
|
|
}},
|
|
},
|
|
},
|
|
req: CommitRequest{
|
|
Branch: "main",
|
|
Type: "foo",
|
|
Credentials: []sigcred.CredentialUnion{{
|
|
PGPSignature: new(sigcred.CredentialPGPSignature),
|
|
AccountID: "a",
|
|
}},
|
|
},
|
|
allowed: false,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.descr, func(t *testing.T) {
|
|
err := AssertCanCommit(test.acl, test.req)
|
|
if test.allowed && err != nil {
|
|
t.Fatalf("expected to be allowed but got: %v", err)
|
|
} else if !test.allowed && !errors.As(err, new(ErrCommitRequestDenied)) {
|
|
t.Fatalf("expected to be denied but got: %v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|