diff --git a/pkg/token/execCredentialPlugin.go b/pkg/token/execCredentialPlugin.go index 5b59e6e6..ebd452d2 100644 --- a/pkg/token/execCredentialPlugin.go +++ b/pkg/token/execCredentialPlugin.go @@ -3,14 +3,11 @@ package token //go:generate sh -c "mockgen -destination mock_$GOPACKAGE/execCredentialPlugin.go github.com/Azure/kubelogin/pkg/token ExecCredentialPlugin" import ( - "encoding/json" "fmt" "os" - "strings" "time" "github.com/Azure/go-autorest/autorest/adal" - "k8s.io/client-go/pkg/apis/clientauthentication" "k8s.io/klog" ) @@ -32,19 +29,6 @@ type execCredentialPlugin struct { } func New(o *Options) (ExecCredentialPlugin, error) { - env := os.Getenv(execInfoEnv) - if env != "" { - var execCredential clientauthentication.ExecCredential - if err := json.Unmarshal([]byte(env), &execCredential); err != nil { - return nil, fmt.Errorf("cannot convert to ExecCredential: %w", err) - } - klog.V(10).Infof("KUBERNETES_EXEC_INFO is: %s", env) - - if !strings.Contains(env, `"spec":{}`) && !execCredential.Spec.Interactive && o.LoginMethod == DeviceCodeLogin { - return nil, fmt.Errorf("devicelogin is not supported if interactiveMode is 'never'") - } - } - klog.V(10).Info(o) provider, err := newTokenProvider(o) if err != nil { diff --git a/pkg/token/execCredentialPlugin_test.go b/pkg/token/execCredentialPlugin_test.go index b2d0b4d4..a5e4ec66 100644 --- a/pkg/token/execCredentialPlugin_test.go +++ b/pkg/token/execCredentialPlugin_test.go @@ -144,36 +144,7 @@ func setupMocks(t *testing.T) (*gomock.Controller, *mock_token.MockTokenCache, * return ctrl, tokenCache, tokenProvider, pluginWriter } -func TestDeviceloginAndNonInteractive(t *testing.T) { - testData := []struct { - name string - execInfoEnvTest string - options Options - expectedError string - }{ - { - name: "KUBERNETES_EXEC_INFO.spec.interactive: false and login mode is devicelogin", - execInfoEnvTest: `{"kind":"ExecCredential","apiVersion":"client.authentication.k8s.io/v1beta1","spec":{"interactive":false}}`, - options: Options{ - LoginMethod: DeviceCodeLogin, - }, - expectedError: "devicelogin is not supported if interactiveMode is 'never'", - }, - } - - for _, data := range testData { - t.Run(data.name, func(t *testing.T) { - os.Setenv("KUBERNETES_EXEC_INFO", data.execInfoEnvTest) - defer os.Unsetenv("KUBERNETES_EXEC_INFO") - ecp, err := New(&data.options) - if ecp != nil || err == nil || err.Error() != data.expectedError { - t.Fatalf("expected: return defined error, actual: did not return expected error") - } - }) - } -} - -func TestKUBERNETES_EXEC_INFO(t *testing.T) { +func TestKUBERNETES_EXEC_INFOIsEmpty(t *testing.T) { testData := []struct { name string execInfoEnvTest string @@ -189,26 +160,6 @@ func TestKUBERNETES_EXEC_INFO(t *testing.T) { TenantID: "tenantID", }, }, - { - name: "KUBERNETES_EXEC_INFO.spec is empty for apiVersion of v1beta1", - execInfoEnvTest: `{"kind":"ExecCredential","apiVersion":"client.authentication.k8s.io/v1beta1","spec":{}}`, - options: Options{ - LoginMethod: DeviceCodeLogin, - ClientID: "clientID", - ServerID: "serverID", - TenantID: "tenantID", - }, - }, - { - name: "KUBERNETES_EXEC_INFO.spec is empty for apiVersion of v1", - execInfoEnvTest: `{"kind":"ExecCredential","apiVersion":"client.authentication.k8s.io/v1","spec":{}}`, - options: Options{ - LoginMethod: DeviceCodeLogin, - ClientID: "clientID", - ServerID: "serverID", - TenantID: "tenantID", - }, - }, } for _, data := range testData {