-
Notifications
You must be signed in to change notification settings - Fork 92
Require explicit authentication for the admin control plane #507
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 1 commit
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 |
|---|---|---|
|
|
@@ -35,6 +35,33 @@ func TestMain(m *testing.M) { | |
| os.Exit(m.Run()) | ||
| } | ||
|
|
||
| func TestInitializeAdminAuthBootstrapsOnlyWhenStoreIsEmpty(t *testing.T) { | ||
| st, err := store.Open(filepath.Join(t.TempDir(), "octobus.db")) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| defer st.Close() | ||
|
|
||
| t.Setenv("OCTOBUS_BOOTSTRAP_ADMIN_TOKEN", "bootstrap-secret") | ||
| if err := initializeAdminAuth(context.Background(), st); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| requires, err := st.AdminRequiresToken(context.Background()) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if !requires { | ||
| t.Fatal("bootstrap token was not persisted") | ||
| } | ||
| ok, err := st.VerifyAdminToken(context.Background(), "bootstrap-secret") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if !ok { | ||
| t.Fatal("bootstrap token was not usable") | ||
| } | ||
| } | ||
|
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. bootstrap 测试仅覆盖快乐路径,缺少对『已要求 token』与『未设置环境变量』负分支的覆盖新增测试 TestInitializeAdminAuthBootstrapsOnlyWhenStoreIsEmpty 的命名声明了『仅当 store 为空时自举』,但实际只覆盖了『store 为空 + 环境变量已设置』的快乐路径,没有覆盖两个关键负分支:a) store 已要求 token(已有 token)时设置环境变量应被忽略且不应报错/重复创建同名 token;b) store 为空但环境变量未设置时应 no-op(而这一路径正是导致 admin API 被静默锁死的主因)。鉴于该逻辑的回归风险较高(错误的自举可能导致重复 token、启动失败或控制面锁死),建议补充这两个分支的用例以锁定预期行为。 Problem code: Recommendation: |
||
|
|
||
| func TestRootAddrFlagOverridesAdminCommands(t *testing.T) { | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if r.Method != http.MethodGet || r.URL.Path != "/admin/v1/status" { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.