package accessctl import ( "dehub.dev/src/dehub.git/sigcred" "testing" ) func TestFilterSignature(t *testing.T) { mkReq := func(accountIDs ...string) CommitRequest { creds := make([]sigcred.Credential, 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, }, }, }) }