github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/integration/v7/selfcontained/logout_command_test.go (about)

     1  package selfcontained_test
     2  
     3  import (
     4  	"net/http"
     5  	"path/filepath"
     6  
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	"github.com/onsi/gomega/gexec"
    10  	apiv1 "k8s.io/client-go/tools/clientcmd/api/v1"
    11  
    12  	"github.com/LukasHeimann/cloudfoundrycli/v8/integration/helpers"
    13  	"github.com/LukasHeimann/cloudfoundrycli/v8/integration/v7/selfcontained/fake"
    14  	"github.com/LukasHeimann/cloudfoundrycli/v8/util/configv3"
    15  )
    16  
    17  var _ = Describe("cf logout", func() {
    18  	BeforeEach(func() {
    19  		helpers.SetConfig(func(config *configv3.Config) {
    20  			config.ConfigFile.CFOnK8s.Enabled = true
    21  			config.ConfigFile.CFOnK8s.AuthInfo = "my-user"
    22  		})
    23  
    24  		apiServer.SetConfiguration(fake.CFAPIConfig{Routes: map[string]fake.Response{
    25  			"GET /whoami": {
    26  				Code: http.StatusOK, Body: map[string]interface{}{
    27  					"name": "my-user",
    28  					"kind": "User",
    29  				},
    30  			},
    31  		}})
    32  
    33  		kubeConfig := apiv1.Config{
    34  			Kind:       "Config",
    35  			APIVersion: "v1",
    36  			AuthInfos: []apiv1.NamedAuthInfo{
    37  				{
    38  					Name: "my-user",
    39  					AuthInfo: apiv1.AuthInfo{
    40  						AuthProvider: &apiv1.AuthProviderConfig{
    41  							Name: "oidc",
    42  							Config: map[string]string{
    43  								"id-token":       string(token),
    44  								"idp-issuer-url": "-",
    45  								"client-id":      "-",
    46  							},
    47  						},
    48  					},
    49  				},
    50  			},
    51  			Clusters: []apiv1.NamedCluster{
    52  				{
    53  					Name: "my-cluster",
    54  					Cluster: apiv1.Cluster{
    55  						Server: "https://example.org",
    56  					},
    57  				},
    58  			},
    59  			Contexts: []apiv1.NamedContext{
    60  				{
    61  					Name: "my-context",
    62  					Context: apiv1.Context{
    63  						Cluster:   "my-cluster",
    64  						AuthInfo:  "my-auth-info",
    65  						Namespace: "my-namespace",
    66  					},
    67  				},
    68  			},
    69  			CurrentContext: "my-context",
    70  		}
    71  
    72  		kubeConfigPath := filepath.Join(homeDir, ".kube", "config")
    73  		storeKubeConfig(kubeConfig, kubeConfigPath)
    74  
    75  		env = helpers.CFEnv{
    76  			EnvVars: map[string]string{
    77  				"KUBECONFIG": kubeConfigPath,
    78  			},
    79  		}
    80  	})
    81  
    82  	JustBeforeEach(func() {
    83  		Eventually(helpers.CustomCF(env, "logout")).Should(gexec.Exit(0))
    84  	})
    85  
    86  	It("clears the auth-info", func() {
    87  		Expect(loadConfig().CFOnK8s).To(Equal(configv3.CFOnK8s{
    88  			Enabled:  true,
    89  			AuthInfo: "",
    90  		}))
    91  	})
    92  })