-
-
Notifications
You must be signed in to change notification settings - Fork 792
authhelper: support single-input TOTP fields and improve field interaction #7259
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
Open
sarathivengadesh
wants to merge
4
commits into
zaproxy:main
Choose a base branch
from
sarathivengadesh:fix/totp-single-input-auth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e076dbf
fix(authhelper): support single-input TOTP fields and improve field i…
sarathivengadesh d7dd821
fix(authhelper): address PR review - revert MsLoginAuthenticator and …
sarathivengadesh 08da194
fix(authhelper): address PR review - lazy TOTP via context, auto-dete…
sarathivengadesh 629b7b9
fix(authhelper): skip redundant TOTP_FIELD steps via per-attempt spli…
sarathivengadesh 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
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
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
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 |
|---|---|---|
|
|
@@ -27,11 +27,15 @@ | |
| import static org.hamcrest.Matchers.hasSize; | ||
| import static org.hamcrest.Matchers.notNullValue; | ||
| import static org.hamcrest.Matchers.nullValue; | ||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.anyString; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.BDDMockito.given; | ||
| import static org.mockito.Mockito.doAnswer; | ||
| import static org.mockito.Mockito.inOrder; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.verifyNoInteractions; | ||
|
|
@@ -65,6 +69,7 @@ | |
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.TestTemplate; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
@@ -75,6 +80,7 @@ | |
| import org.junit.jupiter.params.provider.ValueSource; | ||
| import org.openqa.selenium.By; | ||
| import org.openqa.selenium.Dimension; | ||
| import org.openqa.selenium.JavascriptExecutor; | ||
| import org.openqa.selenium.OutputType; | ||
| import org.openqa.selenium.Point; | ||
| import org.openqa.selenium.Rectangle; | ||
|
|
@@ -1541,6 +1547,71 @@ void shouldConfigureContext() throws Exception { | |
| } | ||
| } | ||
|
|
||
| @Nested | ||
| class FillFieldWithEventsTest { | ||
|
Member
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. These tests are not testing anything (you can change the script and the tests still pass). Please, add proper tests in |
||
|
|
||
| private interface JsWebDriver extends WebDriver, JavascriptExecutor {} | ||
|
|
||
| @Test | ||
| void shouldFillFieldWithValue() { | ||
| // Given | ||
| WebElement field = mock(WebElement.class); | ||
| given(field.getAttribute("value")).willReturn(null); | ||
| WebDriver driver = mock(WebDriver.class); | ||
|
|
||
| // When | ||
| AuthUtils.fillFieldWithEvents(field, "testValue", driver); | ||
|
|
||
| // Then | ||
| verify(field).sendKeys("testValue"); | ||
| verify(field, never()).clear(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldClearExistingValueBeforeFilling() { | ||
| // Given | ||
| WebElement field = mock(WebElement.class); | ||
| given(field.getAttribute("value")).willReturn("existing"); | ||
| WebDriver driver = mock(WebDriver.class); | ||
|
|
||
| // When | ||
| AuthUtils.fillFieldWithEvents(field, "newValue", driver); | ||
|
|
||
| // Then | ||
| var ordered = inOrder(field); | ||
| ordered.verify(field).clear(); | ||
| ordered.verify(field).sendKeys("newValue"); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldFireJsEventsWhenDriverIsJavascriptExecutor() { | ||
| // Given | ||
| WebElement field = mock(WebElement.class); | ||
| given(field.getAttribute("value")).willReturn(null); | ||
| JsWebDriver driver = mock(JsWebDriver.class); | ||
|
|
||
| // When | ||
| AuthUtils.fillFieldWithEvents(field, "testValue", driver); | ||
|
|
||
| // Then | ||
| verify(field).sendKeys("testValue"); | ||
| verify(driver).executeScript(anyString(), eq(field)); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotFailWhenDriverIsNotJavascriptExecutor() { | ||
| // Given | ||
| WebElement field = mock(WebElement.class); | ||
| given(field.getAttribute("value")).willReturn(null); | ||
| WebDriver driver = mock(WebDriver.class); | ||
|
|
||
| // When / Then | ||
| assertDoesNotThrow(() -> AuthUtils.fillFieldWithEvents(field, "testValue", driver)); | ||
| verify(field).sendKeys("testValue"); | ||
| verifyNoInteractions(driver); | ||
| } | ||
| } | ||
|
|
||
| class TestWebElement implements WebElement { | ||
|
|
||
| private String tag; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
This should be generated when needed not beforehand, the code will be outdated if the steps before the TOTP_FIELD step take more time than the defined period. This also fails to validate the required number of digits.
The change itself is also out of place, this breaks the step implementation isolation, better to provide a state object for the steps than add ad-hoc step specific logic here.
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.
Addressed. Added AuthenticationContext — a state object created once per authentication attempt and passed to every step. The TOTP code is now generated lazily at the moment the first TOTP_FIELD step executes (not before all steps run), so it stays fresh even if preceding steps take time. All TOTP logic remains inside AuthenticationStep; DefaultAuthenticator has no step-specific knowledge.