Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mangesh Hambarde <1411192+mangeshhambarde@users.noreply.github.com>
  • Loading branch information
mangeshhambarde committed Mar 13, 2024
1 parent efe2e06 commit 717269e
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions pkg/controller/certificate-shim/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,107 @@ func TestSync(t *testing.T) {
},
},
},
{
Name: "return a single HTTP01 Certificate for an ingress with a single valid TLS entry and valid secret template annotation",
Issuer: acmeClusterIssuer,
IngressLike: &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "ingress-name",
Namespace: gen.DefaultTestNamespace,
Annotations: map[string]string{
cmapi.IngressClusterIssuerNameAnnotationKey: "issuer-name",
cmapi.IngressSecretTemplateAnnotations: "secret-reflector.com.*",
"secret-replicator.com/ignored-annotation": "ignored-value",
"www.secret-reflector.com/ignored-annotation": "ignored-value",
"secret-reflector.com/reflection-enabled": "true",
"secret-reflector.com/reflection-enabled-namespaces": "example-namespace",
},
UID: types.UID("ingress-name"),
},
Spec: networkingv1.IngressSpec{
TLS: []networkingv1.IngressTLS{
{
Hosts: []string{"example.com", "www.example.com"},
SecretName: "example-com-tls",
},
},
},
},
ClusterIssuerLister: []runtime.Object{acmeClusterIssuer},
ExpectedEvents: []string{`Normal CreateCertificate Successfully created Certificate "example-com-tls"`},
ExpectedCreate: []*cmapi.Certificate{
{
ObjectMeta: metav1.ObjectMeta{
Name: "example-com-tls",
Namespace: gen.DefaultTestNamespace,
OwnerReferences: buildIngressOwnerReferences("ingress-name", gen.DefaultTestNamespace),
},
Spec: cmapi.CertificateSpec{
DNSNames: []string{"example.com", "www.example.com"},
SecretName: "example-com-tls",
SecretTemplate: &cmapi.CertificateSecretTemplate{
Annotations: map[string]string{
"secret-reflector.com/reflection-enabled": "true",
"secret-reflector.com/reflection-enabled-namespaces": "example-namespace",
},
},
IssuerRef: cmmeta.ObjectReference{
Name: "issuer-name",
Kind: "ClusterIssuer",
},
Usages: cmapi.DefaultKeyUsages(),
},
},
},
},
{
Name: "secret template annotation should not match cert-manager.io/ annotations",
Issuer: acmeClusterIssuer,
IngressLike: &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "ingress-name",
Namespace: gen.DefaultTestNamespace,
Annotations: map[string]string{
cmapi.IngressClusterIssuerNameAnnotationKey: "issuer-name",
cmapi.IngressSecretTemplateAnnotations: ".*cert-manager.io/.*",
},
UID: types.UID("ingress-name"),
},
Spec: networkingv1.IngressSpec{
TLS: []networkingv1.IngressTLS{
{
Hosts: []string{"example.com", "www.example.com"},
SecretName: "example-com-tls",
},
},
},
},
Err: true,
},
{
Name: "secret template annotation should have valid regex",
Issuer: acmeClusterIssuer,
IngressLike: &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "ingress-name",
Namespace: gen.DefaultTestNamespace,
Annotations: map[string]string{
cmapi.IngressClusterIssuerNameAnnotationKey: "issuer-name",
cmapi.IngressSecretTemplateAnnotations: ")invalid] [regex(",
},
UID: types.UID("ingress-name"),
},
Spec: networkingv1.IngressSpec{
TLS: []networkingv1.IngressTLS{
{
Hosts: []string{"example.com", "www.example.com"},
SecretName: "example-com-tls",
},
},
},
},
Err: true,
},
{
Name: "edit-in-place set to false should not trigger editing the ingress in-place",
Issuer: acmeClusterIssuer,
Expand Down

0 comments on commit 717269e

Please sign in to comment.