github.com/verrazzano/verrazzano@v1.7.0/pkg/certs/acme_utils_test.go (about) 1 // Copyright (c) 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package certs 5 6 import ( 7 "github.com/verrazzano/verrazzano/pkg/constants" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1alpha1" 12 "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1beta1" 13 ) 14 15 // TestIsLetsEncryptProductionEnv tests the IsLetsEncryptProductionEnv functions 16 // GIVEN a call to IsLetsEncryptProductionEnv 17 // WHEN an LetsEncrypt configuration is passed in 18 // THEN the function returns true if the LetsEncrypt environment is for the LE production env 19 func TestIsLetsEncryptProductionEnv(t *testing.T) { 20 assert.True(t, IsLetsEncryptProductionEnv(v1alpha1.LetsEncryptACMEIssuer{Environment: constants.LetsEncryptProduction})) 21 assert.True(t, IsLetsEncryptProductionEnv(v1alpha1.LetsEncryptACMEIssuer{})) 22 assert.False(t, IsLetsEncryptProductionEnv(v1alpha1.LetsEncryptACMEIssuer{Environment: constants.LetsEncryptStaging})) 23 assert.True(t, IsLetsEncryptProductionEnv(v1beta1.LetsEncryptACMEIssuer{Environment: constants.LetsEncryptProduction})) 24 assert.True(t, IsLetsEncryptProductionEnv(v1beta1.LetsEncryptACMEIssuer{})) 25 assert.False(t, IsLetsEncryptProductionEnv(v1beta1.LetsEncryptACMEIssuer{Environment: constants.LetsEncryptStaging})) 26 assert.True(t, IsLetsEncryptProductionEnv(v1alpha1.Acme{Environment: constants.LetsEncryptProduction})) 27 assert.True(t, IsLetsEncryptProductionEnv(v1alpha1.Acme{})) 28 assert.False(t, IsLetsEncryptProductionEnv(v1alpha1.Acme{Environment: constants.LetsEncryptStaging})) 29 assert.True(t, IsLetsEncryptProductionEnv(v1beta1.Acme{Environment: constants.LetsEncryptProduction})) 30 assert.False(t, IsLetsEncryptProductionEnv(v1beta1.Acme{Environment: constants.LetsEncryptStaging})) 31 assert.True(t, IsLetsEncryptProductionEnv(v1beta1.Acme{})) 32 } 33 34 // TestIsLetsEncryptStagingEnv tests the IsLetsEncryptStagingEnv functions 35 // GIVEN a call to IsLetsEncryptStagingEnv 36 // WHEN a Verrazzano configuration is passed in 37 // THEN the function returns true if the LetsEncrypt environment is for the LE staging env 38 func TestIsLetsEncryptStagingEnv(t *testing.T) { 39 assert.True(t, IsLetsEncryptStagingEnv( 40 v1alpha1.LetsEncryptACMEIssuer{ 41 Environment: constants.LetsEncryptStaging, 42 }, 43 )) 44 assert.False(t, IsLetsEncryptStagingEnv( 45 v1alpha1.LetsEncryptACMEIssuer{ 46 Environment: constants.LetsEncryptProduction, 47 }, 48 )) 49 assert.False(t, IsLetsEncryptStagingEnv( 50 v1beta1.LetsEncryptACMEIssuer{ 51 Environment: "foo", 52 }, 53 )) 54 assert.False(t, IsLetsEncryptStagingEnv( 55 v1beta1.LetsEncryptACMEIssuer{ 56 Environment: "", 57 }, 58 )) 59 assert.True(t, IsLetsEncryptStagingEnv( 60 v1alpha1.Acme{ 61 Environment: constants.LetsEncryptStaging, 62 }, 63 )) 64 assert.False(t, IsLetsEncryptStagingEnv( 65 v1alpha1.Acme{ 66 Environment: constants.LetsEncryptProduction, 67 }, 68 )) 69 assert.False(t, IsLetsEncryptStagingEnv( 70 v1beta1.Acme{ 71 Environment: "foo", 72 }, 73 )) 74 assert.False(t, IsLetsEncryptStagingEnv( 75 v1beta1.Acme{ 76 Environment: "", 77 }, 78 )) 79 80 assert.False(t, IsLetsEncryptStagingEnv(v1alpha1.LetsEncryptACMEIssuer{})) 81 assert.False(t, IsLetsEncryptStagingEnv(v1beta1.LetsEncryptACMEIssuer{})) 82 assert.False(t, IsLetsEncryptStagingEnv(v1alpha1.Acme{})) 83 assert.False(t, IsLetsEncryptStagingEnv(v1beta1.Acme{})) 84 } 85 86 // TestIsLetsEncryptProvider tests the IsLetsEncryptProvider functions 87 // GIVEN a call to IsLetsEncryptProvider 88 // WHEN a various valid/invalid LetsEncrypt provider names are passed in 89 // THEN the function returns true if the provider type matches the LetsEncrypt type (case-insensitive), false otherwise 90 func TestIsLetsEncryptProvider(t *testing.T) { 91 assert.True(t, IsLetsEncryptProvider(v1alpha1.Acme{Provider: v1alpha1.LetsEncrypt})) 92 assert.True(t, IsLetsEncryptProvider(v1alpha1.Acme{Provider: "LETSencRYPt"})) 93 assert.False(t, IsLetsEncryptProvider(v1alpha1.Acme{Provider: "foo"})) 94 assert.True(t, IsLetsEncryptProvider(v1beta1.Acme{Provider: v1beta1.LetsEncrypt})) 95 assert.True(t, IsLetsEncryptProvider(v1beta1.Acme{Provider: "LETSencRYPt"})) 96 assert.False(t, IsLetsEncryptProvider(v1beta1.Acme{Provider: "foo"})) 97 }