-
Notifications
You must be signed in to change notification settings - Fork 421
OCPBUGS-64619: oc login: Respect insecure flag from kubeconfig #2134
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -377,6 +377,79 @@ func TestDialToHTTPSServer(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestGetClientConfig_InsecureSkipTLSVerify(t *testing.T) { | ||
| // Test that insecure-skip-tls-verify setting from kubeconfig is respected | ||
| // when logging in without the --insecure-skip-tls-verify flag. | ||
|
|
||
| server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| w.WriteHeader(http.StatusOK) | ||
| })) | ||
| defer server.Close() | ||
|
|
||
| testCases := map[string]struct { | ||
| insecureFlag bool | ||
| insecureKubeconfig bool | ||
| expectedInsecureClientConfig bool | ||
| }{ | ||
| "command flag set": { | ||
| insecureFlag: true, | ||
| expectedInsecureClientConfig: true, | ||
| }, | ||
| "kubeconfig flag set": { | ||
| insecureKubeconfig: true, | ||
| expectedInsecureClientConfig: true, | ||
| }, | ||
| "no flag set": { | ||
| insecureFlag: false, | ||
| insecureKubeconfig: false, | ||
| expectedInsecureClientConfig: false, | ||
| }, | ||
| "both command and kubeconfig flag set": { | ||
| insecureFlag: true, | ||
| insecureKubeconfig: true, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd expect insecureFlag and insecureKubeconfig values differ and we explicitly state which one we should choose. Flags are higher priority than implicit assignments (kubeconfig)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the logic is that there is no priority, but setting insecure anywhere just makes the whole thing accept insecure connection. In other words, insecure=false flag does not overwrite kubeconfig with insecure=true. Otherwise we would need to explicitly check whether the CLI flag was actually set and use that value in any case, in other words, treat default flag value and explicitly set flag value to false differently.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My suggestion basically is to assure whatever the expected outcome if they differ. So that in the future if that test fails, we will be notified something has changed.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if assigning one of them is true makes the outcome as true, let's reflect it to the test
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is reflected in the test 🙂
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the ones you pointed out is line:394 and line:398. They exercise, for example, I'm totally aware that they are identical. But we need to test this case too, because from user point of view
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the other hand, test does not have notion of explicit, implicit flag. So we can leave the tests as is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I appreciate adding unit tests every time. Thank you
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the way :mandalorian:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is not so great is that the tests are passing even when I roll back the change 😅 |
||
| expectedInsecureClientConfig: true, | ||
| }, | ||
| } | ||
|
|
||
| for name, test := range testCases { | ||
| t.Run(name, func(t *testing.T) { | ||
| startingConfig := &kclientcmdapi.Config{ | ||
| Clusters: map[string]*kclientcmdapi.Cluster{}, | ||
| } | ||
| if test.insecureKubeconfig { | ||
| startingConfig.Clusters["test-cluster"] = &kclientcmdapi.Cluster{ | ||
| Server: server.URL, | ||
| InsecureSkipTLSVerify: true, | ||
| } | ||
| } | ||
|
|
||
| options := &LoginOptions{ | ||
| Server: server.URL, | ||
| InsecureTLS: test.insecureFlag, | ||
| StartingKubeConfig: startingConfig, | ||
| } | ||
|
|
||
| clientConfig, err := options.getClientConfig() | ||
| if err != nil { | ||
| if test.expectedInsecureClientConfig { | ||
| t.Fatalf("Expected to succeed with insecure connection, but got error: %v", err) | ||
| } else { | ||
| // If we expect secure connection and get a TLS error, that's expected | ||
| // since we're using a test server with a self-signed cert. | ||
| if err.Error() != certificateAuthorityUnknownMsg { | ||
| t.Fatalf("Expected to fail with insecure connection, but got another error: %v", err) | ||
| } | ||
| return | ||
| } | ||
| } | ||
|
|
||
| if clientConfig.Insecure != test.expectedInsecureClientConfig { | ||
| t.Errorf("expected Insecure=%v, got %v", test.expectedInsecureClientConfig, clientConfig.Insecure) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestPreserveExecProviderOnUsernameLogin(t *testing.T) { | ||
| // Test that when using -u flag with existing OIDC credentials, | ||
| // the ExecProvider configuration is preserved | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the leftover line that caused an issue in previous version. I'm wondering why did I miss it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one right below was removed: