You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
2.6 KiB
124 lines
2.6 KiB
package accessctl
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"dehub.dev/src/dehub.git/sigcred"
|
|
)
|
|
|
|
func TestFilterSignature(t *testing.T) {
|
|
mkReq := func(accountIDs ...string) CommitRequest {
|
|
creds := make([]sigcred.CredentialUnion, len(accountIDs))
|
|
for i := range accountIDs {
|
|
creds[i].PGPSignature = new(sigcred.CredentialPGPSignature)
|
|
creds[i].AccountID = accountIDs[i]
|
|
}
|
|
return CommitRequest{Credentials: creds}
|
|
}
|
|
|
|
runCommitMatchTests(t, []filterCommitMatchTest{
|
|
{
|
|
descr: "no cred accounts",
|
|
filter: FilterSignature{
|
|
AnyAccount: true,
|
|
Count: "1",
|
|
},
|
|
matchErr: ErrFilterSignatureUnsatisfied{
|
|
TargetNumAccounts: 1,
|
|
NumAccounts: 0,
|
|
},
|
|
},
|
|
{
|
|
descr: "one cred account",
|
|
filter: FilterSignature{
|
|
AnyAccount: true,
|
|
Count: "1",
|
|
},
|
|
req: mkReq("foo"),
|
|
match: true,
|
|
},
|
|
{
|
|
descr: "one matching cred account",
|
|
filter: FilterSignature{
|
|
AccountIDs: []string{"foo", "bar"},
|
|
Count: "1",
|
|
},
|
|
req: mkReq("foo"),
|
|
match: true,
|
|
},
|
|
{
|
|
descr: "no matching cred account",
|
|
filter: FilterSignature{
|
|
AccountIDs: []string{"foo", "bar"},
|
|
Count: "1",
|
|
},
|
|
req: mkReq("baz"),
|
|
matchErr: ErrFilterSignatureUnsatisfied{
|
|
TargetNumAccounts: 1,
|
|
NumAccounts: 0,
|
|
},
|
|
},
|
|
{
|
|
descr: "two matching cred accounts",
|
|
filter: FilterSignature{
|
|
AccountIDs: []string{"foo", "bar"},
|
|
Count: "2",
|
|
},
|
|
req: mkReq("foo", "bar"),
|
|
match: true,
|
|
},
|
|
{
|
|
descr: "one matching cred account, missing one",
|
|
filter: FilterSignature{
|
|
AccountIDs: []string{"foo", "bar"},
|
|
Count: "2",
|
|
},
|
|
req: mkReq("foo", "baz"),
|
|
matchErr: ErrFilterSignatureUnsatisfied{
|
|
TargetNumAccounts: 2,
|
|
NumAccounts: 1,
|
|
},
|
|
},
|
|
{
|
|
descr: "50 percent matching cred accounts",
|
|
filter: FilterSignature{
|
|
AccountIDs: []string{"foo", "bar", "baz"},
|
|
Count: "50%",
|
|
},
|
|
req: mkReq("foo", "bar"),
|
|
match: true,
|
|
},
|
|
{
|
|
descr: "not 50 percent matching cred accounts",
|
|
filter: FilterSignature{
|
|
AccountIDs: []string{"foo", "bar", "baz"},
|
|
Count: "50%",
|
|
},
|
|
req: mkReq("foo"),
|
|
matchErr: ErrFilterSignatureUnsatisfied{
|
|
TargetNumAccounts: 2,
|
|
NumAccounts: 1,
|
|
},
|
|
},
|
|
{
|
|
descr: "any sig at all",
|
|
filter: FilterSignature{
|
|
Any: true,
|
|
},
|
|
req: CommitRequest{
|
|
Credentials: []sigcred.CredentialUnion{
|
|
{PGPSignature: new(sigcred.CredentialPGPSignature)},
|
|
},
|
|
},
|
|
match: true,
|
|
},
|
|
{
|
|
descr: "not any sig at all",
|
|
filter: FilterSignature{Any: true},
|
|
req: CommitRequest{},
|
|
matchErr: ErrFilterSignatureUnsatisfied{
|
|
TargetNumAccounts: 1,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|