Skip to content

Commit 7a0a2d2

Browse files
fix: resolve TOCTOU race condition in daily forecaster chart control click (#2127) (#2128)
(cherry picked from commit 31219c6) Signed-off-by: shreyah963 <shreyab963@gmail.com> Signed-off-by: opensearch-ci-bot <opensearch-infra@amazon.com> Co-authored-by: Shreya Bhatta <shreyab963@gmail.com>
1 parent 46edba2 commit 7a0a2d2

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

cypress/integration/plugins/anomaly-detection-dashboards-plugin/daily_forecaster_spec.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ const clickControlAndVerifyChartUpdate = (buttonAriaLabel) => {
3636
cy.get('.echChartStatus')
3737
.invoke('attr', 'data-ech-render-count')
3838
.then((initialRenderCount) => {
39-
cy.get(`button[aria-label="${buttonAriaLabel}"]`).click();
40-
41-
// Cypress's .should() will automatically retry until the assertion passes or times out,
42-
// which handles the async nature of the re-render.
43-
cy.get('.echChartStatus')
44-
.invoke('attr', 'data-ech-render-count')
45-
.should('not.eq', initialRenderCount);
39+
// Re-check disabled state right before clicking to avoid TOCTOU race
40+
cy.get(`button[aria-label="${buttonAriaLabel}"]`).then(($btn) => {
41+
if (!$btn.is(':disabled')) {
42+
cy.wrap($btn).click();
43+
44+
cy.get('.echChartStatus')
45+
.invoke('attr', 'data-ech-render-count')
46+
.should('not.eq', initialRenderCount);
47+
}
48+
});
4649
});
4750
}
4851
});

0 commit comments

Comments
 (0)