Skip to content

Commit

Permalink
Add a test to verify the TLS config
Browse files Browse the repository at this point in the history
Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com>
  • Loading branch information
chetan-rns committed May 20, 2024
1 parent 7509196 commit 6ee3d77
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/v1beta1/argocd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,9 @@ func (argocd *ArgoCD) IsDeletionFinalizerPresent() bool {
return false
}

// WantsAutoTLS returns true if the user has configured a route with reencrypt or we default to reencrypt.
// WantsAutoTLS returns true if:
// 1. user has configured a route with reencrypt.
// 2. user has not configured TLS and we default to reencrypt.
func (s *ArgoCDServerSpec) WantsAutoTLS() bool {
return s.Route.TLS == nil ||
(s.Route.TLS != nil && s.Route.TLS.Termination == routev1.TLSTerminationReencrypt)
Expand Down
56 changes: 56 additions & 0 deletions controllers/argocd/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,62 @@ func TestReconcileRouteForShorteningHostname(t *testing.T) {
}
}

func TestReconcileRouteTLSConfig(t *testing.T) {
routeAPIFound = true
ctx := context.Background()
logf.SetLogger(ZapLogger(true))

tt := []struct {
name string
want routev1.TLSTerminationType
updateArgoCD func(cr *argoproj.ArgoCD)
}{
{
name: "should set the default termination policy to renencrypt",
want: routev1.TLSTerminationReencrypt,
updateArgoCD: func(cr *argoproj.ArgoCD) {
cr.Spec.Server.Route.Enabled = true
},
},
{
name: "shouldn't overwrite the TLS config if it's already configured",
want: routev1.TLSTerminationEdge,
updateArgoCD: func(cr *argoproj.ArgoCD) {
cr.Spec.Server.Route.Enabled = true
cr.Spec.Server.Route.TLS = &routev1.TLSConfig{
Termination: routev1.TLSTerminationEdge,
}
},
},
}

for _, test := range tt {
t.Run(test.name, func(t *testing.T) {
argoCD := makeArgoCD(test.updateArgoCD)

resObjs := []client.Object{argoCD}
subresObjs := []client.Object{argoCD}
runtimeObjs := []runtime.Object{}
sch := makeTestReconcilerScheme(argoproj.AddToScheme, configv1.Install, routev1.Install)
fakeClient := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs)
reconciler := makeTestReconciler(fakeClient, sch)

req := reconcile.Request{
NamespacedName: testNamespacedName(testArgoCDName),
}

_, err := reconciler.Reconcile(ctx, req)
assert.Nil(t, err)

route := &routev1.Route{}
err = reconciler.Client.Get(ctx, types.NamespacedName{Name: argoCD.Name + "-server", Namespace: argoCD.Namespace}, route)
assert.Nil(t, err)
assert.Equal(t, test.want, route.Spec.TLS.Termination)

})
}
}

func makeReconciler(t *testing.T, acd *argoproj.ArgoCD, objs ...runtime.Object) *ReconcileArgoCD {
t.Helper()
s := scheme.Scheme
Expand Down

0 comments on commit 6ee3d77

Please sign in to comment.