@@ -377,6 +377,79 @@ func TestDialToHTTPSServer(t *testing.T) {
377377 }
378378}
379379
380+ func TestGetClientConfig_InsecureSkipTLSVerify (t * testing.T ) {
381+ // Test that insecure-skip-tls-verify setting from kubeconfig is respected
382+ // when logging in without the --insecure-skip-tls-verify flag.
383+
384+ server := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
385+ w .WriteHeader (http .StatusOK )
386+ }))
387+ defer server .Close ()
388+
389+ testCases := map [string ]struct {
390+ insecureFlag bool
391+ insecureKubeconfig bool
392+ expectedInsecureClientConfig bool
393+ }{
394+ "command flag set" : {
395+ insecureFlag : true ,
396+ expectedInsecureClientConfig : true ,
397+ },
398+ "kubeconfig flag set" : {
399+ insecureKubeconfig : true ,
400+ expectedInsecureClientConfig : true ,
401+ },
402+ "no flag set" : {
403+ insecureFlag : false ,
404+ insecureKubeconfig : false ,
405+ expectedInsecureClientConfig : false ,
406+ },
407+ "both command and kubeconfig flag set" : {
408+ insecureFlag : true ,
409+ insecureKubeconfig : true ,
410+ expectedInsecureClientConfig : true ,
411+ },
412+ }
413+
414+ for name , test := range testCases {
415+ t .Run (name , func (t * testing.T ) {
416+ startingConfig := & kclientcmdapi.Config {
417+ Clusters : map [string ]* kclientcmdapi.Cluster {},
418+ }
419+ if test .insecureKubeconfig {
420+ startingConfig .Clusters ["test-cluster" ] = & kclientcmdapi.Cluster {
421+ Server : server .URL ,
422+ InsecureSkipTLSVerify : true ,
423+ }
424+ }
425+
426+ options := & LoginOptions {
427+ Server : server .URL ,
428+ InsecureTLS : test .insecureFlag ,
429+ StartingKubeConfig : startingConfig ,
430+ }
431+
432+ clientConfig , err := options .getClientConfig ()
433+ if err != nil {
434+ if test .expectedInsecureClientConfig {
435+ t .Fatalf ("Expected to succeed with insecure connection, but got error: %v" , err )
436+ } else {
437+ // If we expect secure connection and get a TLS error, that's expected
438+ // since we're using a test server with a self-signed cert.
439+ if err .Error () != certificateAuthorityUnknownMsg {
440+ t .Fatalf ("Expected to fail with insecure connection, but got another error: %v" , err )
441+ }
442+ return
443+ }
444+ }
445+
446+ if clientConfig .Insecure != test .expectedInsecureClientConfig {
447+ t .Errorf ("expected Insecure=%v, got %v" , test .expectedInsecureClientConfig , clientConfig .Insecure )
448+ }
449+ })
450+ }
451+ }
452+
380453func TestPreserveExecProviderOnUsernameLogin (t * testing.T ) {
381454 // Test that when using -u flag with existing OIDC credentials,
382455 // the ExecProvider configuration is preserved
0 commit comments