Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add unit tests for KMP and CertStore controllers #1439

Merged
merged 36 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ede25b9
feat: add Stores interface to wrap operations on namespaced stores
binbin-li Apr 3, 2024
d76e2a9
feat: add Policies interface to wrap operations on namespaced policies
binbin-li Apr 2, 2024
0eb8df5
feat: add KMPManager interface to wrap operations on namespaced kmp
binbin-li Apr 12, 2024
c0b5769
feat: revert extra namespace mapping
binbin-li Apr 19, 2024
05e34fa
Merge branch 'dev' into multi-tenancy-pr-6
binbin-li Apr 20, 2024
6e69159
Merge remote-tracking branch 'upstream/dev' into multi-tenancy-pr-6
binbin-li Apr 25, 2024
5dc63d0
feat: add context to GetKeys
binbin-li Apr 25, 2024
7d93b96
feat: add ClusterPolicy CRD
binbin-li Apr 17, 2024
cf7c563
chore: address comments
binbin-li Apr 24, 2024
7521fb2
feat: add NamespacedStore CRD
binbin-li Apr 23, 2024
db364e6
Merge remote-tracking branch 'upstream/dev' into multi-tenancy-pr-8
binbin-li Apr 26, 2024
80a229e
Merge branch 'dev' into multi-tenancy-pr-8
binbin-li Apr 28, 2024
d59067a
Merge remote-tracking branch 'upstream/dev' into multi-tenancy-pr-8
binbin-li Apr 29, 2024
13131f7
chore: remove deprecated tests
binbin-li Apr 29, 2024
d06b1a0
feat: add NamespacedKMP and switch KMP scope to cluster
binbin-li Apr 29, 2024
e856f53
Merge remote-tracking branch 'upstream/dev' into multi-tenancy-pr-9
binbin-li Apr 29, 2024
96f8ad3
Merge branch 'dev' into multi-tenancy-pr-9
binbin-li Apr 30, 2024
4d68169
Merge remote-tracking branch 'upstream/dev' into multi-tenancy-pr-9
binbin-li Apr 30, 2024
7321d5c
Merge branch 'dev' into multi-tenancy-pr-9
binbin-li May 1, 2024
a95d858
feat: refactor certStore to support multi-tenancy
binbin-li Apr 29, 2024
f573a21
Merge remote-tracking branch 'upstream/dev' into multi-tenancy-pr-10
binbin-li May 2, 2024
bc16d4c
feat: remove default namespace setting
binbin-li May 2, 2024
f236803
feat: return errors when failing to access kmp/certStore
binbin-li May 3, 2024
2474502
Merge remote-tracking branch 'upstream/dev' into multi-tenancy-pr-10
binbin-li May 3, 2024
8a9d586
feat: add NamespacedVerifier CRD
binbin-li Apr 30, 2024
758e479
chore: remove comment
binbin-li May 2, 2024
f605071
Merge remote-tracking branch 'upstream/dev' into multi-tenancy-pr-11
binbin-li May 4, 2024
f0df760
test: add e2e tests for multi-tenancy
binbin-li Apr 30, 2024
a0c0ef5
Merge remote-tracking branch 'upstream/dev' into multi-tenancy-pr-12
binbin-li May 4, 2024
4726003
Merge branch 'dev' into multi-tenancy-pr-12
binbin-li May 4, 2024
63fe951
test: add unit tests
binbin-li May 3, 2024
681ce70
Merge remote-tracking branch 'upstream/dev' into multi-tenancy-pr-13
binbin-li May 7, 2024
2bafa4e
chore: add description to each test
binbin-li May 7, 2024
a27406d
Merge remote-tracking branch 'upstream/dev' into multi-tenancy-pr-13
binbin-li May 7, 2024
0f6d2f6
Merge branch 'dev' into multi-tenancy-pr-13
binbin-li May 7, 2024
40df15d
Merge branch 'dev' into multi-tenancy-pr-13
binbin-li May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ import (
"testing"

configv1beta1 "github.com/deislabs/ratify/api/v1beta1"
"github.com/deislabs/ratify/internal/constants"
"github.com/deislabs/ratify/pkg/keymanagementprovider"
"github.com/sirupsen/logrus"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

test "github.com/deislabs/ratify/pkg/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
)

const (
kmpName = "kmpName"
)

// TestUpdateErrorStatus tests the updateErrorStatus method
Expand Down Expand Up @@ -176,3 +184,100 @@ func TestWriteKMProviderStatus(t *testing.T) {
})
}
}

func TestKMPReconcile(t *testing.T) {
tests := []struct {
name string
description string
provider *configv1beta1.KeyManagementProvider
req *reconcile.Request
expectedErr bool
expectedKMPCount int
}{
{
name: "nonexistent KMP",
description: "Reconciling a non-existent KMP CR, it should be deleted from maps",
req: &reconcile.Request{
NamespacedName: types.NamespacedName{Name: "nonexistent"},
},
provider: &configv1beta1.KeyManagementProvider{
ObjectMeta: metav1.ObjectMeta{
Namespace: constants.EmptyNamespace,
Name: kmpName,
},
Spec: configv1beta1.KeyManagementProviderSpec{
Type: "inline",
},
},
expectedErr: false,
expectedKMPCount: 0,
},
{
name: "invalid params",
description: "Received invalid parameters of the KMP Spec, it should fail the reconcile and return an error",
provider: &configv1beta1.KeyManagementProvider{
ObjectMeta: metav1.ObjectMeta{
Namespace: constants.EmptyNamespace,
Name: kmpName,
},
Spec: configv1beta1.KeyManagementProviderSpec{
Type: "inline",
},
},
expectedErr: true,
expectedKMPCount: 0,
},
{
name: "valid params",
description: "Received a valid KMP manifest, it should be added to the cert map",
provider: &configv1beta1.KeyManagementProvider{
ObjectMeta: metav1.ObjectMeta{
Namespace: constants.EmptyNamespace,
Name: kmpName,
},
Spec: configv1beta1.KeyManagementProviderSpec{
Type: "inline",
Parameters: runtime.RawExtension{
Raw: []byte(`{"type": "inline", "contentType": "certificate", "value": "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIQXy2VqtlhSkiZKAGhsnkjbDANBgkqhkiG9w0BAQsFADBvMRswGQYDVQQD\nExJyYXRpZnkuZXhhbXBsZS5jb20xDzANB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93oc1+OLFjPI7gNuPXYOP1N46oKgEmAEmNkP1etFrEjFRgsdIFHksrmlOlD\nIed9RcQ087VLjmuymLgqMTFX34Q3j7XgN2ENwBSnkHotE9CcuGRW+NuiOeJalL8DBmFXXWwHTKLQ\nPp5g6m1yZXylLJaFLKz7tdMmO355\n-----END CERTIFICATE-----\n"}`),
},
},
},
expectedErr: false,
expectedKMPCount: 1,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resetKMP()
scheme, _ := test.CreateScheme()
client := fake.NewClientBuilder().WithScheme(scheme)
client.WithObjects(tt.provider)
r := &KeyManagementProviderReconciler{
Scheme: scheme,
Client: client.Build(),
}
var req reconcile.Request
if tt.req != nil {
req = *tt.req
} else {
req = reconcile.Request{
NamespacedName: test.KeyFor(tt.provider),
}
}

_, err := r.Reconcile(context.Background(), req)
if tt.expectedErr != (err != nil) {
t.Fatalf("Reconcile() expected error %v, actual %v", tt.expectedErr, err)
}
certs, _ := keymanagementprovider.GetCertificatesFromMap(context.Background(), kmpName)
if len(certs) != tt.expectedKMPCount {
t.Fatalf("Cert map expected size %v, actual %v", tt.expectedKMPCount, len(certs))
}
})
}
}

func resetKMP() {
keymanagementprovider.DeleteCertificatesFromMap(storeName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ limitations under the License.
package namespaceresource

import (
"context"
"fmt"
"testing"

configv1beta1 "github.com/deislabs/ratify/api/v1beta1"
"github.com/deislabs/ratify/internal/constants"
"github.com/deislabs/ratify/pkg/certificateprovider"
"github.com/deislabs/ratify/pkg/certificateprovider/inline"
"github.com/deislabs/ratify/pkg/controllers"
test "github.com/deislabs/ratify/pkg/utils"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

ctxUtils "github.com/deislabs/ratify/internal/context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
)

func TestGetCertStoreConfig_ValidConfig(t *testing.T) {
Expand Down Expand Up @@ -183,3 +191,96 @@ func TestGetCertificateProvider(t *testing.T) {
t.Fatalf("Getting unregistered provider should returns an error")
}
}

func TestCertStoreReconcile(t *testing.T) {
tests := []struct {
name string
description string
provider *configv1beta1.CertificateStore
req *reconcile.Request
expectedErr bool
expectedCertCount int
}{
{
name: "nonexistent store",
description: "Reconciling a non-existent certStore CR, it should be deleted from map",
req: &reconcile.Request{
NamespacedName: types.NamespacedName{Name: "nonexistent"},
},
provider: &configv1beta1.CertificateStore{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: storeName,
},
Spec: configv1beta1.CertificateStoreSpec{
Provider: "inline",
},
},
expectedErr: false,
expectedCertCount: 0,
},
{
name: "invalid params",
description: "Received invalid parameters of the certStore Spec, it should fail the reconcile and return an error",
provider: &configv1beta1.CertificateStore{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: storeName,
},
Spec: configv1beta1.CertificateStoreSpec{
Provider: "inline",
},
},
expectedErr: true,
expectedCertCount: 0,
},
{
name: "valid params",
description: "Received invalid parameters of the certStore Spec, it should fail the reconcile and return an error",
provider: &configv1beta1.CertificateStore{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: storeName,
},
Spec: configv1beta1.CertificateStoreSpec{
Provider: "inline",
Parameters: runtime.RawExtension{
Raw: []byte(`{"value": "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIQXy2VqtlhSkiZKAGhsnkjbDANBgkqhkiG9w0BAQsFADBvMRswGQYDVQQD\nExJyYXRpZnkuZXhhbXBsZS5jb20xDzANBgNVBAsTBk15IE9yZzETMBEGA1UEChMKTXkgQ29tcGFu\neTEQMA4GA1UEBxMHUmVkbW9uZDELMAkGA1UECBMCV0ExCzAJBgNVBAYTAlVTMB4XDTIzMDIwMTIy\nND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XXWwHTKLQ\nPp5g6m1yZXylLJaFLKz7tdMmO355\n-----END CERTIFICATE-----\n"}`),
},
},
},
expectedErr: false,
expectedCertCount: 1,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
scheme, _ := test.CreateScheme()
client := fake.NewClientBuilder().WithScheme(scheme)
client.WithObjects(tt.provider)
r := &CertificateStoreReconciler{
Scheme: scheme,
Client: client.Build(),
}
var req reconcile.Request
if tt.req != nil {
req = *tt.req
} else {
req = reconcile.Request{
NamespacedName: test.KeyFor(tt.provider),
}
}

_, err := r.Reconcile(context.Background(), req)
if tt.expectedErr != (err != nil) {
t.Fatalf("Reconcile() expected error %v, actual %v", tt.expectedErr, err)
}
ctx := ctxUtils.SetContextWithNamespace(context.Background(), testNamespace)
certs, _ := controllers.NamespacedCertStores.GetCertsFromStore(ctx, testNamespace+constants.NamespaceSeperator+storeName)
if len(certs) != tt.expectedCertCount {
t.Fatalf("Store map expected size %v, actual %v", tt.expectedCertCount, len(certs))
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@ import (
"github.com/deislabs/ratify/pkg/keymanagementprovider"
"github.com/sirupsen/logrus"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/deislabs/ratify/internal/constants"
ctxUtils "github.com/deislabs/ratify/internal/context"
test "github.com/deislabs/ratify/pkg/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
)

const (
kmpName = "kmpName"
)

// TestUpdateErrorStatus tests the updateErrorStatus method
Expand Down Expand Up @@ -176,3 +185,96 @@ func TestWriteKMProviderStatus(t *testing.T) {
})
}
}

func TestKMPReconcile(t *testing.T) {
tests := []struct {
name string
description string
provider *configv1beta1.NamespacedKeyManagementProvider
req *reconcile.Request
expectedErr bool
expectedKMPCount int
}{
{
name: "nonexistent KMP",
description: "Reconciling a non-existent KMP CR, it should be deleted from maps",
req: &reconcile.Request{
NamespacedName: types.NamespacedName{Name: "nonexistent"},
},
provider: &configv1beta1.NamespacedKeyManagementProvider{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: kmpName,
},
Spec: configv1beta1.NamespacedKeyManagementProviderSpec{
Type: "inline",
},
},
expectedErr: false,
expectedKMPCount: 0,
},
{
name: "invalid params",
description: "Received invalid parameters of the KMP Spec, it should fail the reconcile and return an error",
provider: &configv1beta1.NamespacedKeyManagementProvider{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: kmpName,
},
Spec: configv1beta1.NamespacedKeyManagementProviderSpec{
Type: "inline",
},
},
expectedErr: true,
expectedKMPCount: 0,
},
{
name: "valid params",
description: "Received a valid KMP manifest, it should be added to the cert map",
provider: &configv1beta1.NamespacedKeyManagementProvider{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: kmpName,
},
Spec: configv1beta1.NamespacedKeyManagementProviderSpec{
Type: "inline",
Parameters: runtime.RawExtension{
Raw: []byte(`{"type": "inline", "contentType": "certificate", "value": "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIQXy2VqtlhSkiZKAGhsnkjbDANBgkqhkiG9w0BAQsFADBvMRswGQYDVQQD\nExJyYXRpZnkuZXhhbXBsZS5jb20xDzANBgNVBAsTBk15IE9yZzETMBEGA1UEChMKTXkgQ29tcGFu\neTEQMA4GA1UEBxMHUmVkbW9uZDELMAkGA1UECBMCV0ExCzAJBgNVBAYTAlVTMB4XDTIzMDIwMTIy\nNDUwMFoXDTI0MDIwMTIyNTUwMFowbzEbMBkGA1UEAxMScmF0aWZ5LmV4YW1wbGUuY29tMQ8wDQYD\nVQQLEwZNeSBPcmcxEzARBgNVBAoTCk15IENvbXBhbnkxEDAOBgNVBAcTB1JlZG1vbmQxCzAJBgNV\nBAgTAldBMQswCQYDVQQGEwJVUzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL10bM81\npPAyuraORABsOGS8M76Bi7Guwa3JlM1g2D8CuzSfSTaaT6apy9GsccxUvXd5cmiP1ffna5z+EFmc\nizFQh2aq9kWKWXDvKFXzpQuhyqD1HeVlRlF+V0AfZPvGt3VwUUjNycoUU44ctCWmcUQP/KShZev3\n6SOsJ9q7KLjxxQLsUc4mg55eZUThu8mGB8jugtjsnLUYvIWfHhyjVpGrGVrdkDMoMn+u33scOmrt\nsBljvq9WVo4T/VrTDuiOYlAJFMUae2Ptvo0go8XTN3OjLblKeiK4C+jMn9Dk33oGIT9pmX0vrDJV\nX56w/2SejC1AxCPchHaMuhlwMpftBGkCAwEAAaNyMHAwDgYDVR0PAQH/BAQDAgeAMAkGA1UdEwQC\nMAAwEwYDVR0lBAwwCgYIKwYBBQUHAwMwHwYDVR0jBBgwFoAU0eaKkZj+MS9jCp9Dg1zdv3v/aKww\nHQYDVR0OBBYEFNHmipGY/jEvYwqfQ4Nc3b97/2isMA0GCSqGSIb3DQEBCwUAA4IBAQBNDcmSBizF\nmpJlD8EgNcUCy5tz7W3+AAhEbA3vsHP4D/UyV3UgcESx+L+Nye5uDYtTVm3lQejs3erN2BjW+ds+\nXFnpU/pVimd0aYv6mJfOieRILBF4XFomjhrJOLI55oVwLN/AgX6kuC3CJY2NMyJKlTao9oZgpHhs\nLlxB/r0n9JnUoN0Gq93oc1+OLFjPI7gNuPXYOP1N46oKgEmAEmNkP1etFrEjFRgsdIFHksrmlOlD\nIed9RcQ087VLjmuymLgqMTFX34Q3j7XgN2ENwBSnkHotE9CcuGRW+NuiOeJalL8DBmFXXWwHTKLQ\nPp5g6m1yZXylLJaFLKz7tdMmO355\n-----END CERTIFICATE-----\n"}`),
},
},
},
expectedErr: false,
expectedKMPCount: 1,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
scheme, _ := test.CreateScheme()
client := fake.NewClientBuilder().WithScheme(scheme)
client.WithObjects(tt.provider)
r := &KeyManagementProviderReconciler{
Scheme: scheme,
Client: client.Build(),
}
var req reconcile.Request
if tt.req != nil {
req = *tt.req
} else {
req = reconcile.Request{
NamespacedName: test.KeyFor(tt.provider),
}
}

_, err := r.Reconcile(context.Background(), req)
if tt.expectedErr != (err != nil) {
t.Fatalf("Reconcile() expected error %v, actual %v", tt.expectedErr, err)
}
ctx := ctxUtils.SetContextWithNamespace(context.Background(), testNamespace)
certs, _ := keymanagementprovider.GetCertificatesFromMap(ctx, testNamespace+constants.NamespaceSeperator+kmpName)
if len(certs) != tt.expectedKMPCount {
t.Fatalf("Cert map expected size %v, actual %v", tt.expectedKMPCount, len(certs))
}
})
}
}
Loading
Loading