Debian Codegraph @

plugin/verify_test.go

raw symbols SCIP
1 // Copyright The Notary Project Authors.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/
15
16 import (
17 "fmtscip-go gomod github.com/golang/go/src go1.20 fmt/"
18 "testingscip-go gomod github.com/golang/go/src go1.20 testing/"
19 )
20
21 var mockCertChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/mockCertChain. = [][]byte{[]byte("zap"), []byte("zop")}
22
23 func TestVerifySignatureRequest_Validatescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TestVerifySignatureRequest_Validate().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) {
24 reqs := []VerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#{
25 getVerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/getVerifySignatureRequest().(ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ContractVersion., "someCT", "someSigningScheme", mockCertChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/mockCertChain., []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#{CapabilitySignatureGeneratorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilitySignatureGenerator.}),
26 {
27 ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#ContractVersion.: "2.0",
28 Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Signature.: Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#{
29 CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#CriticalAttributes.: CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#{
30 ContentTypescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#ContentType.: "someCT",
31 SigningSchemescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#SigningScheme.: "someSigningScheme",
32 Expiryscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#Expiry.: nil,
33 AuthenticSigningTimescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#AuthenticSigningTime.: nil,
34 ExtendedAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#ExtendedAttributes.: nil,
35 },
36 UnprocessedAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#UnprocessedAttributes.: []string{"upa1", "upa2"},
37 CertificateChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#CertificateChain.: mockCertChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/mockCertChain.,
38 },
39 TrustPolicyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#TrustPolicy.: TrustPolicyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TrustPolicy#{
40 TrustedIdentitiesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TrustPolicy#TrustedIdentities.: []string{"trustedIdentity1", "trustedIdentity2"},
41 SignatureVerificationscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TrustPolicy#SignatureVerification.: []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#{CapabilitySignatureGeneratorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilitySignatureGenerator., CapabilityRevocationCheckVerifierscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilityRevocationCheckVerifier.},
42 },
43 PluginConfigscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#PluginConfig.: map[string]string{"someKey": "someValue"},
44 },
45 }
46
47 for _, req := range reqs {
48 if err := req.Validatescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Validate().(); err != nil {
49 t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("VerifySignatureRequest#Validate failed with error: %+v", err)
50 }
51 }
52 }
53
54 func TestVerifySignatureRequest_Validate_Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TestVerifySignatureRequest_Validate_Error().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) {
55 reqWithoutSignature := getVerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/getVerifySignatureRequest().("1.0", "someCT", "someSigningScheme", mockCertChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/mockCertChain., []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#{CapabilitySignatureGeneratorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilitySignatureGenerator.})
56 reqWithoutSignature.Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Signature. = Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#{}
57
58 reqWithoutCriticalAttr := getVerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/getVerifySignatureRequest().("1.0", "someCT", "someSigningScheme", mockCertChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/mockCertChain., []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#{CapabilitySignatureGeneratorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilitySignatureGenerator.})
59 reqWithoutCriticalAttr.Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Signature..CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#CriticalAttributes. = CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#{}
60
61 testCases := []struct {
62 name string
63 req VerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#
64 }{
65 {name: "contractVersion", req: getVerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/getVerifySignatureRequest().("", "someCT", "someSigningScheme", mockCertChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/mockCertChain., []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#{CapabilitySignatureGeneratorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilitySignatureGenerator.})},
66 {name: "signature's criticalAttributes's contentType", req: getVerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/getVerifySignatureRequest().(ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ContractVersion., "", "someSigningScheme", mockCertChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/mockCertChain., []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#{CapabilitySignatureGeneratorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilitySignatureGenerator.})},
67 {name: "signature's criticalAttributes's signingScheme", req: getVerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/getVerifySignatureRequest().(ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ContractVersion., "someCT", "", mockCertChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/mockCertChain., []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#{CapabilitySignatureGeneratorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilitySignatureGenerator.})},
68 {name: "signature's criticalAttributes's certificateChain", req: getVerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/getVerifySignatureRequest().(ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ContractVersion., "someCT", "someSigningScheme", [][]byte{}, []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#{CapabilitySignatureGeneratorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilitySignatureGenerator.})},
69 {name: "signature's criticalAttributes's certificateChain", req: getVerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/getVerifySignatureRequest().(ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ContractVersion., "someCT", "someSigningScheme", nil, []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#{CapabilitySignatureGeneratorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilitySignatureGenerator.})},
70 {name: "signature's trustPolicy", req: getVerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/getVerifySignatureRequest().(ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ContractVersion., "someCT", "someSigningScheme", mockCertChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/mockCertChain., nil)},
71 {name: "signature's trustPolicy's signatureVerification", req: getVerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/getVerifySignatureRequest().(ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ContractVersion., "someCT", "someSigningScheme", mockCertChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/mockCertChain., []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#{})},
72 {name: "signature", req: reqWithoutSignature},
73 {name: "signature's criticalAttributes", req: reqWithoutCriticalAttr},
74 }
75
76 for _, testcase := range testCases {
77 t.Runscip-go gomod github.com/golang/go/src go1.20 testing/T#Run().(testcase.name, func(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) {
78 if err := testcase.req.Validatescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Validate().(); err != nil {
79 expMsg := fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.20 fmt/Sprintf().("{\"errorCode\":\"VALIDATION_ERROR\",\"errorMessage\":\"%s cannot be empty\"}", testcase.name)
80 if err.Error() != expMsg {
81 t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("expected error message '%s' but got '%s'", expMsg, err.Error())
82 }
83 } else {
84 t.Errorscip-go gomod github.com/golang/go/src go1.20 testing/common#Error().("VerifySignatureRequest#Validate didn't returned error")
85 }
86 })
87 }
88 }
89
90 func TestVerifySignatureRequest_Commandscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TestVerifySignatureRequest_Command().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) {
91 req := getVerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/getVerifySignatureRequest().(ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ContractVersion., "someCT", "someSigningScheme", mockCertChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/mockCertChain., []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#{CapabilitySignatureGeneratorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilitySignatureGenerator.})
92 if cmd := req.Commandscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Command().(); cmd != CommandVerifySignaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandVerifySignature. {
93 t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("DescribeKeyRequest#Command, expected %s but returned %s", CommandVerifySignaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandVerifySignature., cmd)
94 }
95 }
96
97 func getVerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/getVerifySignatureRequest().(cv, ct, ss string, cc [][]byte, sv []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#) VerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest# {
98 return VerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#{
99 ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#ContractVersion.: cv,
100 Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Signature.: Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#{
101 CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#CriticalAttributes.: CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#{
102 ContentTypescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#ContentType.: ct,
103 SigningSchemescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#SigningScheme.: ss,
104 },
105 CertificateChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#CertificateChain.: cc,
106 },
107 TrustPolicyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#TrustPolicy.: TrustPolicyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TrustPolicy#{
108 SignatureVerificationscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TrustPolicy#SignatureVerification.: sv,
109 },
110 }
111 }