@@ -199,6 +199,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
199199 - Use --venafi-connection for the Venafi Cloud VenafiConnection mode.
200200 - Use --credentials-file alone if you want to use the Jetstack Secure OAuth mode.
201201 - Use --api-token if you want to use the Jetstack Secure API Token mode.
202+ - Use --machine-hub if you want to use the MachineHub mode.
202203 - Use --output-path for Local File mode.` ))
203204 assert .Nil (t , cl )
204205 })
@@ -616,6 +617,38 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
616617 require .NoError (t , err )
617618 assert .Equal (t , VenafiCloudVenafiConnection , got .OutputMode )
618619 })
620+ t .Run ("--machine-hub selects MachineHub mode" , func (t * testing.T ) {
621+ t .Setenv ("POD_NAMESPACE" , "venafi" )
622+ t .Setenv ("KUBECONFIG" , withFile (t , fakeKubeconfig ))
623+ t .Setenv ("ARK_PLATFORM_DOMAIN" , "cyberark.cloud" )
624+ t .Setenv ("ARK_SUBDOMAIN" , "tlspk" )
625+ t .Setenv ("ARK_USERNAME" , "first_last@cyberark.cloud.123456" )
626+ t .Setenv ("ARK_SECRET" , "test-secret" )
627+ got , cl , err := ValidateAndCombineConfig (discardLogs (),
628+ withConfig ("" ),
629+ withCmdLineFlags ("--period" , "1m" , "--machine-hub" ))
630+ require .NoError (t , err )
631+ assert .Equal (t , MachineHub , got .OutputMode )
632+ assert .IsType (t , & client.CyberArkClient {}, cl )
633+ })
634+ t .Run ("--machine-hub without required environment variables" , func (t * testing.T ) {
635+ t .Setenv ("POD_NAMESPACE" , "venafi" )
636+ t .Setenv ("KUBECONFIG" , withFile (t , fakeKubeconfig ))
637+ t .Setenv ("ARK_PLATFORM_DOMAIN" , "" )
638+ t .Setenv ("ARK_SUBDOMAIN" , "" )
639+ t .Setenv ("ARK_USERNAME" , "" )
640+ t .Setenv ("ARK_SECRET" , "" )
641+ got , cl , err := ValidateAndCombineConfig (discardLogs (),
642+ withConfig ("" ),
643+ withCmdLineFlags ("--period" , "1m" , "--machine-hub" ))
644+ assert .Equal (t , CombinedConfig {}, got )
645+ assert .Nil (t , cl )
646+ assert .EqualError (t , err , testutil .Undent (`
647+ validating creds: failed loading config using the MachineHub mode: 1 error occurred:
648+ * missing environment variables: ARK_PLATFORM_DOMAIN, ARK_SUBDOMAIN, ARK_USERNAME, ARK_SECRET
649+
650+ ` ))
651+ })
619652 t .Run ("--output-file selects local file mode" , func (t * testing.T ) {
620653 t .Setenv ("POD_NAMESPACE" , "venafi" )
621654 t .Setenv ("KUBECONFIG" , withFile (t , fakeKubeconfig ))
0 commit comments