| 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 cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/ |
| 15 | |
| 16 | import ( |
| 17 | "contextscip-go gomod github.com/golang/go/src go1.20 context/" |
| 18 | "fmtscip-go gomod github.com/golang/go/src go1.20 fmt/" |
| 19 | "ioscip-go gomod github.com/golang/go/src go1.20 io/" |
| 20 | "logscip-go gomod github.com/golang/go/src go1.20 log/" |
| 21 | "osscip-go gomod github.com/golang/go/src go1.20 os/" |
| 22 | "os/execscip-go gomod github.com/golang/go/src go1.20 `os/exec`/" |
| 23 | "reflectscip-go gomod github.com/golang/go/src go1.20 reflect/" |
| 24 | "stringsscip-go gomod github.com/golang/go/src go1.20 strings/" |
| 25 | "testingscip-go gomod github.com/golang/go/src go1.20 testing/" |
| 26 | |
| 27 | "github.com/notaryproject/notation-plugin-framework-go/internal/mockscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/mock`/" |
| 28 | "github.com/notaryproject/notation-plugin-framework-go/pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/" |
| 29 | ) |
| 30 | |
| 31 | var cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/cli., _ = Newscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/New().(mockscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/mock`/.NewPluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/mock`/NewPlugin().(false)) |
| 32 | var errorCliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/errorCli., _ = Newscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/New().(mockscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/mock`/.NewPluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/mock`/NewPlugin().(true)) |
| 33 | |
| 34 | func TestNewWithLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/TestNewWithLogger().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 35 | _, err := NewWithLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/NewWithLogger().(nil, &discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#{}) |
| 36 | if err == nil { |
| 37 | t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("NewWithLogger() expected error but not found") |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | func TestMarshalResponsescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/TestMarshalResponse().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 42 | res := pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.GenerateEnvelopeResponsescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GenerateEnvelopeResponse#{ |
| 43 | SignatureEnvelopescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GenerateEnvelopeResponse#SignatureEnvelope.: []byte("envelope"), |
| 44 | Annotationsscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GenerateEnvelopeResponse#Annotations.: map[string]string{"key": "value"}, |
| 45 | SignatureEnvelopeTypescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GenerateEnvelopeResponse#SignatureEnvelopeType.: "envelopeType", |
| 46 | } |
| 47 | op, err := cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/cli..marshalResponsescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#marshalResponse().(res, nil) |
| 48 | if err != nil { |
| 49 | t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("Error found in marshalResponse: %v", err) |
| 50 | } |
| 51 | |
| 52 | expected := "{\"signatureEnvelope\":\"ZW52ZWxvcGU=\",\"signatureEnvelopeType\":\"envelopeType\",\"annotations\":{\"key\":\"value\"}}" |
| 53 | if !stringsscip-go gomod github.com/golang/go/src go1.20 strings/.EqualFoldscip-go gomod github.com/golang/go/src go1.20 strings/EqualFold().("{\"signatureEnvelope\":\"ZW52ZWxvcGU=\",\"signatureEnvelopeType\":\"envelopeType\",\"annotations\":{\"key\":\"value\"}}", op) { |
| 54 | t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("Not equal: \n expected: %s\n actual : %s", expected, op) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestMarshalResponseErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/TestMarshalResponseError().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 59 | _, err := cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/cli..marshalResponsescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#marshalResponse().(nil, fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.20 fmt/Errorf().("expected error thrown")) |
| 60 | assertErrscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/assertErr().(t, err, pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.ErrorCodeGenericscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeGeneric.) |
| 61 | |
| 62 | _, err = cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/cli..marshalResponsescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#marshalResponse().(nil, pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.NewValidationErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationError().("expected validation error thrown")) |
| 63 | assertErrscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/assertErr().(t, err, pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.ErrorCodeValidationscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeValidation.) |
| 64 | |
| 65 | _, err = cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/cli..marshalResponsescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#marshalResponse().(make(chan int), nil) |
| 66 | assertErrscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/assertErr().(t, err, pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.ErrorCodeGenericscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeGeneric.) |
| 67 | } |
| 68 | |
| 69 | func TestUnmarshalRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/TestUnmarshalRequest().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 70 | content := "{\"contractVersion\":\"1.0\",\"keyId\":\"someKeyId\",\"pluginConfig\":{\"pc1\":\"pk1\"}}" |
| 71 | closer := setupReaderscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/setupReader().(content) |
| 72 | defer closer() |
| 73 | |
| 74 | var request pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.DescribeKeyRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/DescribeKeyRequest# |
| 75 | if err := cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/cli..unmarshalRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#unmarshalRequest().(&request); err != nil { |
| 76 | t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("unmarshalRequest() failed with error: %v", err) |
| 77 | } |
| 78 | |
| 79 | if request.ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/DescribeKeyRequest#ContractVersion. != "1.0" || request.KeyIDscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/DescribeKeyRequest#KeyID. != "someKeyId" || request.PluginConfigscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/DescribeKeyRequest#PluginConfig.["pc1"] != "pk1" { |
| 80 | t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("unmarshalRequest() returned incorrect struct") |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | func TestUnmarshalRequestErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/TestUnmarshalRequestError().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 85 | closer := setupReaderscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/setupReader().("InvalidJson") |
| 86 | defer closer() |
| 87 | |
| 88 | var request pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.DescribeKeyRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/DescribeKeyRequest# |
| 89 | err := cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/cli..unmarshalRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#unmarshalRequest().(&request) |
| 90 | if err == nil { |
| 91 | t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("unmarshalRequest() expected error but not found") |
| 92 | } |
| 93 | |
| 94 | plgErr, ok := err.(*pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#) |
| 95 | if !ok { |
| 96 | t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("unmarshalRequest() expected error of type plugin.Error but found %s", reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.20 reflect/TypeOf().(err)) |
| 97 | } |
| 98 | |
| 99 | expectedErrStr := "{\"errorCode\":\"VALIDATION_ERROR\",\"errorMessage\":\"Input is not a valid JSON\"}" |
| 100 | if plgErr.Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#Error().() != expectedErrStr { |
| 101 | t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("unmarshalRequest() expected error string to be %s but found %s", expectedErrStr, plgErr.Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#Error().()) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | func TestGetMetadataErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/TestGetMetadataError().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 106 | if osscip-go gomod github.com/golang/go/src go1.20 os/.Getenvscip-go gomod github.com/golang/go/src go1.20 os/Getenv().("TEST_OS_EXIT") == "1" { |
| 107 | ctx := contextscip-go gomod github.com/golang/go/src go1.20 context/.Backgroundscip-go gomod github.com/golang/go/src go1.20 context/Background().() |
| 108 | errorCliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/errorCli..Executescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#Execute().(ctx, []string{string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CommandGetMetadatascip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandGetMetadata.)}) |
| 109 | return |
| 110 | } |
| 111 | cmd := execscip-go gomod github.com/golang/go/src go1.20 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.20 `os/exec`/Command().(osscip-go gomod github.com/golang/go/src go1.20 os/.Argsscip-go gomod github.com/golang/go/src go1.20 os/Args.[0], "-test.run=TestGetMetadataError") |
| 112 | cmd.Envscip-go gomod github.com/golang/go/src go1.20 `os/exec`/Cmd#Env. = append(osscip-go gomod github.com/golang/go/src go1.20 os/.Environscip-go gomod github.com/golang/go/src go1.20 os/Environ().(), "TEST_OS_EXIT=1") |
| 113 | err := cmd.Runscip-go gomod github.com/golang/go/src go1.20 `os/exec`/Cmd#Run().() |
| 114 | if e, ok := err.(*execscip-go gomod github.com/golang/go/src go1.20 `os/exec`/.ExitErrorscip-go gomod github.com/golang/go/src go1.20 `os/exec`/ExitError#); ok && !e.Successscip-go gomod github.com/golang/go/src go1.20 os/ProcessState#Success().() { |
| 115 | return |
| 116 | } |
| 117 | t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("process ran with err %v, want exit status 1", err) |
| 118 | } |
| 119 | |
| 120 | func TestExecuteSuccessscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/TestExecuteSuccess().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 121 | sigGenCli, _ := Newscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/New().(mockscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/mock`/.NewSigGeneratorPluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/mock`/NewSigGeneratorPlugin().(false)) |
| 122 | tests := map[string]struct { |
| 123 | c *CLIscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI# |
| 124 | in string |
| 125 | op string |
| 126 | }{ |
| 127 | string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CommandGetMetadatascip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandGetMetadata.): { |
| 128 | c: cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/cli., |
| 129 | in: "{}", |
| 130 | op: "{\"name\":\"Example Plugin\",\"description\":\"This is an description of example plugin. 🍺\",\"version\":\"1.0.0\",\"url\":\"https://example.com/notation/plugin\",\"capabilities\":[\"SIGNATURE_VERIFIER.TRUSTED_IDENTITY\",\"SIGNATURE_VERIFIER.REVOCATION_CHECK\",\"SIGNATURE_GENERATOR.ENVELOPE\"]}", |
| 131 | }, |
| 132 | string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Versionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Version.): { |
| 133 | c: cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/cli., |
| 134 | in: "", |
| 135 | op: "Example Plugin - This is an description of example plugin. 🍺\nVersion: 1.0.0\n", |
| 136 | }, |
| 137 | string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CommandGenerateEnvelopescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandGenerateEnvelope.): { |
| 138 | c: cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/cli., |
| 139 | in: "{\"contractVersion\":\"1.0\",\"keyId\":\"someKeyId\",\"payloadType\":\"somePT\",\"signatureEnvelopeType\":\"someSET\",\"payload\":\"em9w\"}", |
| 140 | op: "{\"signatureEnvelope\":\"\",\"signatureEnvelopeType\":\"someSET\",\"annotations\":{\"manifestAnntnKey1\":\"value1\"}}", |
| 141 | }, |
| 142 | string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CommandVerifySignaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandVerifySignature.): { |
| 143 | c: cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/cli., |
| 144 | in: "{\"contractVersion\":\"1.0\",\"signature\":{\"criticalAttributes\":{\"contentType\":\"someCT\",\"signingScheme\":\"someSigningScheme\"},\"unprocessedAttributes\":null,\"certificateChain\":[\"emFw\",\"em9w\"]},\"trustPolicy\":{\"trustedIdentities\":null,\"signatureVerification\":[\"SIGNATURE_GENERATOR.RAW\"]}}", |
| 145 | op: "{\"verificationResults\":{\"SIGNATURE_VERIFIER.REVOCATION_CHECK\":{\"success\":true,\"reason\":\"Not revoked\"},\"SIGNATURE_VERIFIER.TRUSTED_IDENTITY\":{\"success\":true,\"reason\":\"Valid trusted Identity\"}},\"processedAttributes\":[]}", |
| 146 | }, |
| 147 | string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CommandGenerateSignaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandGenerateSignature.): { |
| 148 | c: sigGenCli, |
| 149 | in: "{\"contractVersion\":\"1.0\",\"keyId\":\"someKeyId\",\"keySpec\":\"EC-384\",\"hashAlgorithm\":\"SHA-384\",\"payload\":\"em9w\"}", |
| 150 | op: "{\"keyId\":\"someKeyId\",\"signature\":\"YWJjZA==\",\"signingAlgorithm\":\"RSASSA-PSS-SHA-256\",\"certificateChain\":[\"YWJjZA==\",\"d3h5eg==\"]}", |
| 151 | }, |
| 152 | string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CommandDescribeKeyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandDescribeKey.): { |
| 153 | c: sigGenCli, |
| 154 | in: "{\"contractVersion\":\"1.0\",\"keyId\":\"someKeyId\"}", |
| 155 | op: "{\"keyId\":\"someKeyId\",\"keySpec\":\"RSA-2048\"}", |
| 156 | }, |
| 157 | } |
| 158 | for name, test := range tests { |
| 159 | t.Runscip-go gomod github.com/golang/go/src go1.20 testing/T#Run().(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#) { |
| 160 | closer := setupReaderscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/setupReader().(test.in) |
| 161 | defer closer() |
| 162 | op := captureStdOutscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/captureStdOut().(func() { |
| 163 | test.c.Executescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#Execute().(contextscip-go gomod github.com/golang/go/src go1.20 context/.Backgroundscip-go gomod github.com/golang/go/src go1.20 context/Background().(), []string{"notation", name}) |
| 164 | }) |
| 165 | if op != test.op { |
| 166 | t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("Execute() with '%s' args, expected '%s' but got '%s'", name, test.op, op) |
| 167 | } |
| 168 | }) |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | func setupReaderscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/setupReader().(content string) func() { |
| 173 | tmpfile, err := osscip-go gomod github.com/golang/go/src go1.20 os/.CreateTempscip-go gomod github.com/golang/go/src go1.20 os/CreateTemp().("", "example") |
| 174 | if err != nil { |
| 175 | logscip-go gomod github.com/golang/go/src go1.20 log/.Fatalscip-go gomod github.com/golang/go/src go1.20 log/Fatal().(err) |
| 176 | } |
| 177 | |
| 178 | if _, err := tmpfile.Writescip-go gomod github.com/golang/go/src go1.20 os/File#Write().([]byte(content)); err != nil { |
| 179 | logscip-go gomod github.com/golang/go/src go1.20 log/.Fatalscip-go gomod github.com/golang/go/src go1.20 log/Fatal().(err) |
| 180 | } |
| 181 | |
| 182 | if _, err := tmpfile.Seekscip-go gomod github.com/golang/go/src go1.20 os/File#Seek().(0, 0); err != nil { |
| 183 | logscip-go gomod github.com/golang/go/src go1.20 log/.Fatalscip-go gomod github.com/golang/go/src go1.20 log/Fatal().(err) |
| 184 | } |
| 185 | |
| 186 | oldStdin := osscip-go gomod github.com/golang/go/src go1.20 os/.Stdinscip-go gomod github.com/golang/go/src go1.20 os/Stdin. |
| 187 | osscip-go gomod github.com/golang/go/src go1.20 os/.Stdinscip-go gomod github.com/golang/go/src go1.20 os/Stdin. = tmpfile |
| 188 | return func() { |
| 189 | osscip-go gomod github.com/golang/go/src go1.20 os/.Removescip-go gomod github.com/golang/go/src go1.20 os/Remove().(tmpfile.Namescip-go gomod github.com/golang/go/src go1.20 os/File#Name().()) |
| 190 | osscip-go gomod github.com/golang/go/src go1.20 os/.Stdinscip-go gomod github.com/golang/go/src go1.20 os/Stdin. = oldStdin // Restore original Stdin |
| 191 | |
| 192 | tmpfile.Closescip-go gomod github.com/golang/go/src go1.20 os/File#Close().() |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | func captureStdOutscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/captureStdOut().(f func()) string { |
| 197 | orig := osscip-go gomod github.com/golang/go/src go1.20 os/.Stdoutscip-go gomod github.com/golang/go/src go1.20 os/Stdout. |
| 198 | r, w, _ := osscip-go gomod github.com/golang/go/src go1.20 os/.Pipescip-go gomod github.com/golang/go/src go1.20 os/Pipe().() |
| 199 | osscip-go gomod github.com/golang/go/src go1.20 os/.Stdoutscip-go gomod github.com/golang/go/src go1.20 os/Stdout. = w |
| 200 | f() |
| 201 | osscip-go gomod github.com/golang/go/src go1.20 os/.Stdoutscip-go gomod github.com/golang/go/src go1.20 os/Stdout. = orig |
| 202 | w.Closescip-go gomod github.com/golang/go/src go1.20 os/File#Close().() |
| 203 | out, _ := ioscip-go gomod github.com/golang/go/src go1.20 io/.ReadAllscip-go gomod github.com/golang/go/src go1.20 io/ReadAll().(r) |
| 204 | return string(out) |
| 205 | } |
| 206 | |
| 207 | func assertErrscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/assertErr().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#, err error, code pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.ErrorCodescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCode#) { |
| 208 | if plgErr, ok := err.(*pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#); ok { |
| 209 | if reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.20 reflect/DeepEqual().(code, plgErr.ErrCodescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#ErrCode.) { |
| 210 | return |
| 211 | } |
| 212 | t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("mismatch in error code: \n expected: %s\n actual : %s", code, plgErr.ErrCodescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#ErrCode.) |
| 213 | } |
| 214 | t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("expected error of type PluginError but found %s", reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.20 reflect/TypeOf().(err)) |
| 215 | } |