Skip to content

Commit

Permalink
Allow passing namespace for MatchPeerCertificatesFromSecret (#557)
Browse files Browse the repository at this point in the history
In Eventing, we need to use the system namespace rather than
the test namespce.

Signed-off-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
pierDipi authored Jul 28, 2023
1 parent 31af513 commit 645a631
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 3 additions & 4 deletions pkg/eventshub/assert/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubeclient "knative.dev/pkg/client/injection/kube/client"

"knative.dev/reconciler-test/pkg/environment"
"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/feature"
)
Expand Down Expand Up @@ -126,10 +125,10 @@ func toFixedContextMatchers(ctx context.Context, matchers []eventshub.EventInfoM
return out
}

func MatchPeerCertificatesFromSecret(name string, key string) eventshub.EventInfoMatcherCtx {
func MatchPeerCertificatesFromSecret(namespace, name string, key string) eventshub.EventInfoMatcherCtx {
return func(ctx context.Context, info eventshub.EventInfo) error {
secret, err := kubeclient.Get(ctx).CoreV1().
Secrets(environment.FromContext(ctx).Namespace()).
Secrets(namespace).
Get(ctx, name, metav1.GetOptions{})

if err != nil {
Expand All @@ -141,7 +140,7 @@ func MatchPeerCertificatesFromSecret(name string, key string) eventshub.EventInf
return fmt.Errorf("failed to get value from secret %s/%s for key %s", secret.Namespace, secret.Name, key)
}

if info.Connection == nil && info.Connection.TLS == nil {
if info.Connection == nil || info.Connection.TLS == nil {
return fmt.Errorf("failed to match peer certificates, connection is not TLS")
}

Expand Down
4 changes: 3 additions & 1 deletion test/e2e/eventshub/receiver_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ func receiverTLS() *feature.Feature {
AtLeast(10),
)
f.Assert("Sender received expected peer certificate", assert.OnStore(sourceName).
MatchPeerCertificatesReceived(assert.MatchPeerCertificatesFromSecret(secretName, "tls.crt")).
MatchPeerCertificatesReceived(func(ctx context.Context, info eventshub.EventInfo) error {
return assert.MatchPeerCertificatesFromSecret(environment.FromContext(ctx).Namespace(), secretName, "tls.crt")(ctx, info)
}).
AtLeast(5),
)

Expand Down

0 comments on commit 645a631

Please sign in to comment.