-
Notifications
You must be signed in to change notification settings - Fork 567
fix(oauth): use kubeAPIServerDNSName for LoginURL when configured #8854
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
Closed
chdeshpa-hue
wants to merge
1
commit into
openshift:main
from
chdeshpa-hue:fix/OCPBUGS-86260-oauth-login-url-dns
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
control-plane-operator/controllers/hostedcontrolplane/v2/oauth/config_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package oauth | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
|
|
||
| hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1" | ||
| "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/infra" | ||
| component "github.com/openshift/hypershift/support/controlplane-component" | ||
|
|
||
| osinv1 "github.com/openshift/api/osin/v1" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
| ) | ||
|
|
||
| func TestAdaptOAuthConfig_LoginURL(t *testing.T) { | ||
| const ( | ||
| lbHost = "10.71.22.118" | ||
| dnsName = "api.ocp4.example.com" | ||
| oauthHost = "oauth.example.com" | ||
| ) | ||
| var lbPort int32 = 6443 | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| kubeAPIServerDNS string | ||
| loginURLAnnotation string | ||
| expectedLoginURL string | ||
| }{ | ||
| { | ||
| name: "no kubeAPIServerDNSName — uses controlPlaneEndpoint host", | ||
| kubeAPIServerDNS: "", | ||
| expectedLoginURL: fmt.Sprintf("https://%s:%d", lbHost, lbPort), | ||
| }, | ||
| { | ||
| name: "kubeAPIServerDNSName set — uses DNS name", | ||
| kubeAPIServerDNS: dnsName, | ||
| expectedLoginURL: fmt.Sprintf("https://%s:%d", dnsName, lbPort), | ||
| }, | ||
| { | ||
| name: "kubeAPIServerDNSName set but annotation override present — annotation wins", | ||
| kubeAPIServerDNS: dnsName, | ||
| loginURLAnnotation: "https://iam.custom.ibm.com/login", | ||
| expectedLoginURL: "https://iam.custom.ibm.com/login", | ||
| }, | ||
| { | ||
| name: "only annotation override, no DNS name — annotation used", | ||
| kubeAPIServerDNS: "", | ||
| loginURLAnnotation: "https://iam.custom.ibm.com/login", | ||
| expectedLoginURL: "https://iam.custom.ibm.com/login", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
|
||
| hcp := &hyperv1.HostedControlPlane{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "test-hcp", | ||
| Namespace: "test-ns", | ||
| }, | ||
| Spec: hyperv1.HostedControlPlaneSpec{ | ||
| KubeAPIServerDNSName: tt.kubeAPIServerDNS, | ||
| }, | ||
| Status: hyperv1.HostedControlPlaneStatus{ | ||
| ControlPlaneEndpoint: hyperv1.APIEndpoint{ | ||
| Host: lbHost, | ||
| Port: lbPort, | ||
| }, | ||
| }, | ||
| } | ||
| if tt.loginURLAnnotation != "" { | ||
| hcp.Annotations = map[string]string{ | ||
| hyperv1.OauthLoginURLOverrideAnnotation: tt.loginURLAnnotation, | ||
| } | ||
| } | ||
|
|
||
| cpContext := component.WorkloadContext{ | ||
| HCP: hcp, | ||
| InfraStatus: infra.InfrastructureStatus{ | ||
| OAuthHost: oauthHost, | ||
| OAuthPort: 443, | ||
| APIPort: lbPort, | ||
| }, | ||
| Client: fake.NewClientBuilder().Build(), | ||
| } | ||
|
|
||
| cfg := &osinv1.OsinServerConfig{ | ||
| OAuthConfig: osinv1.OAuthConfig{}, | ||
| } | ||
|
|
||
| adaptOAuthConfig(cpContext, cfg) | ||
|
|
||
| g.Expect(cfg.OAuthConfig.LoginURL).To(Equal(tt.expectedLoginURL)) | ||
| g.Expect(cfg.OAuthConfig.MasterURL).To(Equal(fmt.Sprintf("https://%s:%d", oauthHost, 443))) | ||
| g.Expect(cfg.OAuthConfig.MasterPublicURL).To(Equal(fmt.Sprintf("https://%s:%d", oauthHost, 443))) | ||
| }) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add a case for the new IPv6 bracketing path.
The production change now routes
LoginURLthroughpki.AddBracketsIfIPv6(...), but this table only exercises IPv4, DNS, and annotation inputs. A regression back to an unbracketed IPv6 URL would still pass here. As per coding guidelines,Unit test any code changes and additions.Also applies to: 71-74, 99-99
🤖 Prompt for AI Agents
Source: Coding guidelines