Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert following commits as the original assumption where devicelogin… #155

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions pkg/token/execCredentialPlugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand Down
51 changes: 1 addition & 50 deletions pkg/token/execCredentialPlugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down