From 716c61e093148cd44dfdf11f67d327e5b5e4727a Mon Sep 17 00:00:00 2001 From: Massimiliano Giovagnoli Date: Wed, 19 Jul 2023 20:57:26 +0200 Subject: [PATCH] test(pkg/distribution): add initial index entry signature unit test Signed-off-by: Massimiliano Giovagnoli --- build/registry/go.mod | 3 +- build/registry/go.sum | 1 - .../pkg/distribution/index_internal_test.go | 56 +++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 build/registry/pkg/distribution/index_internal_test.go diff --git a/build/registry/go.mod b/build/registry/go.mod index bc433058..e99b063d 100644 --- a/build/registry/go.mod +++ b/build/registry/go.mod @@ -13,7 +13,6 @@ require ( github.com/onsi/gomega v1.27.8 github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.7.0 - golang.org/x/tools v0.9.3 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 k8s.io/klog/v2 v2.100.1 @@ -74,13 +73,13 @@ require ( github.com/xeipuuv/gojsonschema v1.2.0 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect - golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.11.0 // indirect golang.org/x/oauth2 v0.9.0 // indirect golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.9.0 // indirect golang.org/x/term v0.9.0 // indirect golang.org/x/text v0.10.0 // indirect + golang.org/x/tools v0.9.3 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/build/registry/go.sum b/build/registry/go.sum index 975f8991..59fa6fcb 100644 --- a/build/registry/go.sum +++ b/build/registry/go.sum @@ -410,7 +410,6 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= -golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/build/registry/pkg/distribution/index_internal_test.go b/build/registry/pkg/distribution/index_internal_test.go new file mode 100644 index 00000000..46ad8379 --- /dev/null +++ b/build/registry/pkg/distribution/index_internal_test.go @@ -0,0 +1,56 @@ +/* +Copyright (C) 2022 The Falco Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package distribution + +import ( + "reflect" + "testing" + + "github.com/falcosecurity/falcoctl/pkg/index" + + "github.com/falcosecurity/plugins/build/registry/pkg/registry" +) + +func TestPluginToIndexEntrySignature(t *testing.T) { + signature := &index.Signature{ + Cosign: &index.CosignSignature{}, + } + + expected := signature + + p := registry.Plugin{Signature: signature} + + entry := pluginToIndexEntry(p, "", "") + if !reflect.DeepEqual(entry.Signature, expected) { + t.Fatalf("Index entry signature: expected %#v, got %v", expected, entry.Signature) + } +} + +func TestPluginRulesToIndexEntrySignature(t *testing.T) { + signature := &index.Signature{ + Cosign: &index.CosignSignature{}, + } + + expected := signature + + p := registry.Plugin{Signature: signature} + + entry := pluginRulesToIndexEntry(p, "", "") + if !reflect.DeepEqual(entry.Signature, expected) { + t.Fatalf("Index entry signature: expected %#v, got %v", expected, entry.Signature) + } +}