Harden API token policy button state
This commit is contained in:
@@ -291,6 +291,63 @@ func TestUIAPITokenDetailPanelHandlesMissingRemoveClickables(t *testing.T) {
|
||||
_ = u.apiTokenDetailPanel(gtx)
|
||||
}
|
||||
|
||||
func TestUIAPITokenDetailPanelResizesPolicyRemoveClickablesAcrossTokenSelection(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := newUIWithSession("desktop", &session.Manager{})
|
||||
u.masterPassword.SetText("correct horse battery staple")
|
||||
if err := u.createVaultAction(); err != nil {
|
||||
t.Fatalf("createVaultAction() error = %v", err)
|
||||
}
|
||||
|
||||
u.showAPITokensSection()
|
||||
u.apiTokenName.SetText("CLI One")
|
||||
u.apiTokenClientName.SetText("grpc-cli-1")
|
||||
if err := u.issueAPITokenAction(); err != nil {
|
||||
t.Fatalf("issueAPITokenAction() error = %v", err)
|
||||
}
|
||||
firstID := u.state.SelectedEntryID
|
||||
u.apiPolicyOperation.SetText(string(apitokens.OperationListEntries))
|
||||
u.apiPolicyPath.SetText("Joe / codex")
|
||||
u.apiPolicyAllow.Value = true
|
||||
u.apiPolicyGroupScopeW.Value = true
|
||||
if err := u.addAPIPolicyRuleAction(); err != nil {
|
||||
t.Fatalf("addAPIPolicyRuleAction() error = %v", err)
|
||||
}
|
||||
|
||||
u.apiTokenName.SetText("CLI Two")
|
||||
u.apiTokenClientName.SetText("grpc-cli-2")
|
||||
if err := u.issueAPITokenAction(); err != nil {
|
||||
t.Fatalf("issueAPITokenAction() error = %v", err)
|
||||
}
|
||||
secondID := u.state.SelectedEntryID
|
||||
|
||||
ops := new(op.Ops)
|
||||
gtx := layout.Context{
|
||||
Ops: ops,
|
||||
Constraints: layout.Exact(image.Pt(800, 600)),
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Fatalf("apiTokenDetailPanel() panicked after token switch: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
u.state.SelectedEntryID = secondID
|
||||
u.loadSelectedAPITokenIntoEditor()
|
||||
if len(u.apiPolicyRemoves) != 0 {
|
||||
t.Fatalf("len(apiPolicyRemoves) after selecting token without policies = %d, want 0", len(u.apiPolicyRemoves))
|
||||
}
|
||||
_ = u.apiTokenDetailPanel(gtx)
|
||||
|
||||
u.state.SelectedEntryID = firstID
|
||||
u.loadSelectedAPITokenIntoEditor()
|
||||
if len(u.apiPolicyRemoves) != 1 {
|
||||
t.Fatalf("len(apiPolicyRemoves) after reselecting token with policy = %d, want 1", len(u.apiPolicyRemoves))
|
||||
}
|
||||
_ = u.apiTokenDetailPanel(gtx)
|
||||
}
|
||||
|
||||
func TestUIAPIAuditSectionShowsRecordedEvents(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user