Skip to content

Commit 56520d1

Browse files
authored
Merge pull request #6666 from thc202/authhelper/add-word-login
authhelper: add word for login label
2 parents 9659353 + 0f846be commit 56520d1

File tree

5 files changed

+165
-3
lines changed

5 files changed

+165
-3
lines changed

addOns/authhelper/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ All notable changes to this add-on will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## Unreleased
7+
### Added
8+
- Add login word variant for Spanish.
79

10+
## Changed
11+
- Search also for login elements with ARIA role button.
812

913
## [0.28.0] - 2025-09-02
1014
### Added

addOns/authhelper/src/main/java/org/zaproxy/addon/authhelper/AuthUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public class AuthUtils {
137137
"sign in",
138138
"sign-in",
139139
"iniciar sesión", // Spanish: login
140+
"ingresar", // Ditto.
140141
"acceder", // Spanish: sign in
141142
"connexion", // French: login
142143
"se connecter", // French: sign in

addOns/authhelper/src/main/java/org/zaproxy/addon/authhelper/LoginLinkDetector.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,22 @@ public static List<WebElement> getLoginLinks(WebDriver wd, List<String> loginLab
3737
return loginLinks;
3838
}
3939
// If no links found, try buttons
40-
return findElementsByTagAndLabels(wd, "button", loginLabels);
40+
List<WebElement> loginButtons = findElementsByTagAndLabels(wd, "button", loginLabels);
41+
if (!loginButtons.isEmpty()) {
42+
return loginButtons;
43+
}
44+
// If no links nor buttons found try search for ARIA role button
45+
return findElementsByAndLabels(wd, By.xpath("//*[@role=\"button\"]"), loginLabels);
4146
}
4247

4348
private static List<WebElement> findElementsByTagAndLabels(
4449
WebDriver wd, String tag, List<String> labels) {
45-
return wd.findElements(By.tagName(tag)).stream()
50+
return findElementsByAndLabels(wd, By.tagName(tag), labels);
51+
}
52+
53+
private static List<WebElement> findElementsByAndLabels(
54+
WebDriver wd, By by, List<String> labels) {
55+
return wd.findElements(by).stream()
4656
.filter(element -> elementContainsText(element, labels))
4757
.toList();
4858
}
@@ -59,7 +69,16 @@ public static List<Element> getLoginLinks(Source src, List<String> loginLabels)
5969
return loginLinks;
6070
}
6171
// If no links found, try buttons
62-
return findElementsByTagAndLabels(src, HTMLElementName.BUTTON, loginLabels);
72+
List<Element> loginButtons =
73+
findElementsByTagAndLabels(src, HTMLElementName.BUTTON, loginLabels);
74+
if (!loginButtons.isEmpty()) {
75+
return loginButtons;
76+
}
77+
// If no links nor buttons found try search for ARIA role button
78+
return src.getAllElements().stream()
79+
.filter(element -> "button".equals(element.getAttributeValue("role")))
80+
.filter(element -> elementContainsText(element, loginLabels))
81+
.toList();
6382
}
6483

6584
private static List<Element> findElementsByTagAndLabels(

addOns/authhelper/src/main/resources/db/migration/V6__Auth_report_data.sql

Whitespace-only changes.

addOns/authhelper/src/test/java/org/zaproxy/addon/authhelper/LoginLinkDetectorUnitTest.java

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,142 @@ void shouldReturnButtonWithDeeperSrcText() {
403403
assertThat(loginLinks.size(), is(equalTo(1)));
404404
assertThat(loginLinks.get(0).getAttributeValue("custom"), is(equalTo("test")));
405405
}
406+
407+
@TestTemplate
408+
void shouldReturnSimpleWdRoleButton(WebDriver wd) {
409+
// Given
410+
pageContent =
411+
() ->
412+
"""
413+
<h1>Heading</h1>
414+
<a href="#link1">Link 1</a>
415+
<a href="#link2">Link 2</a>
416+
<a href="#link3">Link 3</a>
417+
<div role="button" custom="test">Sign in</div>
418+
<div/>
419+
""";
420+
wd.get(url);
421+
// When
422+
List<WebElement> loginLinks =
423+
LoginLinkDetector.getLoginLinks(wd, AuthUtils.LOGIN_LABELS_P1);
424+
425+
// Then
426+
assertThat(loginLinks.size(), is(equalTo(1)));
427+
assertThat(loginLinks.get(0).getDomAttribute("custom"), is(equalTo("test")));
428+
}
429+
430+
@Test
431+
void shouldReturnSimpleWdRoleButton() {
432+
// Given
433+
String html =
434+
"""
435+
<h1>Heading</h1>
436+
<a href="#link1">Link 1</a>
437+
<a href="#link2">Link 2</a>
438+
<a href="#link3">Link 3</a>
439+
<div role="button" custom="test">Sign in</div>
440+
<div/>
441+
""";
442+
// When
443+
List<Element> loginLinks =
444+
LoginLinkDetector.getLoginLinks(new Source(html), AuthUtils.LOGIN_LABELS_P1);
445+
446+
// Then
447+
assertThat(loginLinks.size(), is(equalTo(1)));
448+
assertThat(loginLinks.get(0).getAttributeValue("custom"), is(equalTo("test")));
449+
}
450+
451+
@TestTemplate
452+
void shouldReturnMultipleSimpleWdRoleButtons(WebDriver wd) {
453+
// Given
454+
pageContent =
455+
() ->
456+
"""
457+
<h1>Heading</h1>
458+
<a href="#link1">Link 1</a>
459+
<div role="button" custom="test1">Sign in</div>
460+
<a href="#link2">Link 2</a>
461+
<div role="button" custom="test2">Log In</div>
462+
<a href="#link3">Link 3</a>
463+
<div role="button" custom="test3">Log Out</div>
464+
<div/>
465+
""";
466+
wd.get(url);
467+
// When
468+
List<WebElement> loginLinks =
469+
LoginLinkDetector.getLoginLinks(wd, AuthUtils.LOGIN_LABELS_P1);
470+
471+
// Then
472+
assertThat(loginLinks.size(), is(equalTo(2)));
473+
assertThat(loginLinks.get(0).getDomAttribute("custom"), is(equalTo("test1")));
474+
assertThat(loginLinks.get(1).getDomAttribute("custom"), is(equalTo("test2")));
475+
}
476+
477+
@Test
478+
void shouldReturnMultipleSimpleSrcRoleButtons() {
479+
// Given
480+
String html =
481+
"""
482+
<h1>Heading</h1>
483+
<a href="#link1">Link 1</a>
484+
<div role="button" custom="test1">Sign in</div>
485+
<a href="#link2">Link 2</a>
486+
<div role="button" custom="test2">Log In</div>
487+
<a href="#link3">Link 3</a>
488+
<div role="button" custom="test3">Log Out</div>
489+
<div/>
490+
""";
491+
// When
492+
List<Element> loginLinks =
493+
LoginLinkDetector.getLoginLinks(new Source(html), AuthUtils.LOGIN_LABELS_P1);
494+
495+
// Then
496+
assertThat(loginLinks.size(), is(equalTo(2)));
497+
assertThat(loginLinks.get(0).getAttributeValue("custom"), is(equalTo("test1")));
498+
assertThat(loginLinks.get(1).getAttributeValue("custom"), is(equalTo("test2")));
499+
}
500+
501+
@TestTemplate
502+
void shouldReturnRoleButtonWithDeeperWdText(WebDriver wd) {
503+
// Given
504+
pageContent =
505+
() ->
506+
"""
507+
<h1>Heading</h1>
508+
<a href="#link1">Link 1</a>
509+
<a href="#link2">Link 2</a>
510+
<div role="button" custom="test"><div><div></div><div><div>Log in</div></div></div>
511+
<a href="#link3">Link 3</a>
512+
<div/>
513+
""";
514+
wd.get(url);
515+
// When
516+
List<WebElement> loginLinks =
517+
LoginLinkDetector.getLoginLinks(wd, AuthUtils.LOGIN_LABELS_P1);
518+
519+
// Then
520+
assertThat(loginLinks.size(), is(equalTo(1)));
521+
assertThat(loginLinks.get(0).getDomAttribute("custom"), is(equalTo("test")));
522+
}
523+
524+
@Test
525+
void shouldReturnRoleButtonWithDeeperSrcText() {
526+
// Given
527+
String html =
528+
"""
529+
<h1>Heading</h1>
530+
<a href="#link1">Link 1</a>
531+
<a href="#link2">Link 2</a>
532+
<div role="button" custom="test"><div><div></div><div><div>Log in</div></div></div></div>
533+
<a href="#link3">Link 3</a>
534+
<div/>
535+
""";
536+
// When
537+
List<Element> loginLinks =
538+
LoginLinkDetector.getLoginLinks(new Source(html), AuthUtils.LOGIN_LABELS_P1);
539+
540+
// Then
541+
assertThat(loginLinks.size(), is(equalTo(1)));
542+
assertThat(loginLinks.get(0).getAttributeValue("custom"), is(equalTo("test")));
543+
}
406544
}

0 commit comments

Comments
 (0)