Skip to content

Commit

Permalink
Report form index
Browse files Browse the repository at this point in the history
Include the index of the form to allow to identify them in ZAP.

Signed-off-by: thc202 <[email protected]>
  • Loading branch information
thc202 committed Dec 17, 2024
1 parent f20c6a4 commit 7ef16f8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ All notable changes to this add-on will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

### Changed
- Report index of the forms.

## 0.0.9 - 2024-11-28

### Added
Expand Down
2 changes: 2 additions & 0 deletions source/types/ReportedModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class ReportedElement extends ReportedObject {
// This gets the full URL rather than a relative one
const a: HTMLAnchorElement = element as HTMLAnchorElement;
this.href = a.toString();
} else if (element.tagName === 'FORM') {
this.formId = Array.prototype.slice.call(document.forms).indexOf(element);
} else if (element.tagName === 'INPUT') {
// Capture extra useful info for input elements
const input: HTMLInputElement = element as HTMLInputElement;
Expand Down
6 changes: 3 additions & 3 deletions test/ContentScript/unitTests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ test('Report page forms', () => {
// Then
expect(mockFn.mock.calls.length).toBe(2);
expect(mockFn.mock.calls[0][0].toNonTimestampString()).toBe(
'{"type":"nodeAdded","tagName":"FORM","id":"form1","nodeName":"FORM","url":"http://localhost/","text":"Content1"}'
'{"type":"nodeAdded","tagName":"FORM","id":"form1","nodeName":"FORM","url":"http://localhost/","text":"Content1","formId":-1}'
);
expect(mockFn.mock.calls[1][0].toNonTimestampString()).toBe(
'{"type":"nodeAdded","tagName":"FORM","id":"form2","nodeName":"FORM","url":"http://localhost/","text":"Content2"}'
'{"type":"nodeAdded","tagName":"FORM","id":"form2","nodeName":"FORM","url":"http://localhost/","text":"Content2","formId":-1}'
);
});

Expand Down Expand Up @@ -263,7 +263,7 @@ test('Reported page loaded', () => {
'{"type":"nodeAdded","tagName":"AREA","id":"","nodeName":"AREA","url":"http://localhost/","href":"https://www.example.com/1","text":""}'
);
expect(mockFn.mock.calls[2][0].toNonTimestampString()).toBe(
'{"type":"nodeAdded","tagName":"FORM","id":"form1","nodeName":"FORM","url":"http://localhost/","text":"FormContent"}'
'{"type":"nodeAdded","tagName":"FORM","id":"form1","nodeName":"FORM","url":"http://localhost/","text":"FormContent","formId":-1}'
);
expect(mockFn.mock.calls[3][0].toNonTimestampString()).toBe(
'{"type":"nodeAdded","tagName":"INPUT","id":"input1","nodeName":"INPUT","url":"http://localhost/","text":"default","tagType":"text"}'
Expand Down

0 comments on commit 7ef16f8

Please sign in to comment.