Skip to content

Commit 6092694

Browse files
authored
fix sonar sso (#39)
* fix sonar sso * update
1 parent 09e00b8 commit 6092694

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

testing/steps/sso.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,24 @@ func loginACP(ctx context.Context, page playwright.Page, params ssoParams) error
132132
}
133133

134134
log.Info("等待登录表单出现...")
135+
// 检查是否在第三方登录页面
136+
buttonLocator := page.Locator(".connectors")
137+
isVisible, err := buttonLocator.IsVisible()
138+
if err != nil {
139+
return fmt.Errorf("检查第三方登录页面失败: %v", err)
140+
}
141+
142+
if isVisible {
143+
log.Info("当前在第三方登录页面,切换到本地登录...")
144+
if err := page.GetByRole("button", playwright.PageGetByRoleOptions{
145+
Name: "切换本地用户登录",
146+
}).Click(); err != nil {
147+
return fmt.Errorf("点击切换本地用户登录按钮失败: %v", err)
148+
}
149+
} else {
150+
log.Info("已是本地用户登录页")
151+
}
152+
135153
if _, err := page.WaitForSelector(".login-form", playwright.PageWaitForSelectorOptions{
136154
State: playwright.WaitForSelectorStateVisible,
137155
Timeout: playwright.Float(60000),
@@ -149,8 +167,18 @@ func loginACP(ctx context.Context, page playwright.Page, params ssoParams) error
149167
}
150168

151169
// 点击登录按钮
152-
if err := page.GetByRole("button", playwright.PageGetByRoleOptions{}).Click(); err != nil {
153-
return fmt.Errorf("点击登录按钮失败: %v", err)
170+
if err := page.GetByRole("button", playwright.PageGetByRoleOptions{
171+
Name: "登录",
172+
Exact: playwright.Bool(true),
173+
}).Click(); err != nil {
174+
log.Info("点击 登录 按钮失败,错误信息: %v", zap.Error(err))
175+
log.Info("尝试点击 Login 按钮...")
176+
if err := page.GetByRole("button", playwright.PageGetByRoleOptions{
177+
Name: "Login",
178+
Exact: playwright.Bool(true),
179+
}).Click(); err != nil {
180+
return fmt.Errorf("点击Login按钮失败: %v", err)
181+
}
154182
}
155183

156184
// 等待 Devops 文本出现

testing/testdata/sonar-oidc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
sonar.auth.oidc.issuerUri: <config.{{.acp.baseUrl}}>/dex
1515
sonar.auth.oidc.clientId.secured: test-dex
1616
sonar.auth.oidc.clientSecret.secured: Z2l0bGFiLW9mZmljaWFsLTAK
17-
sonar.auth.oidc.loginStrategy: Email
17+
sonar.auth.oidc.loginStrategy: Preferred username
1818
sonar.auth.oidc.providerConfiguration: '{"issuer":"<config.{{.acp.baseUrl}}>/dex","authorization_endpoint":"<config.{{.acp.baseUrl}}>/dex/auth","token_endpoint":"<config.{{.acp.baseUrl}}>/dex/token","jwks_uri":"<config.{{.acp.baseUrl}}>/dex/keys","response_types_supported":["code","id_token","token"],"subject_types_supported":["public"],"id_token_signing_alg_values_supported":["RS256"],"scopes_supported":["openid","email","groups","profile","offline_access"],"token_endpoint_auth_methods_supported":["client_secret_basic"],"claims_supported":["aud","email","email_verified","exp","iat","iss","locale","name","sub"]}'
1919
postgresql:
2020
enabled: false

0 commit comments

Comments
 (0)