-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
098bb72
commit de202e5
Showing
7 changed files
with
140 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Result } from '../result'; | ||
|
||
export type Checker = ( | ||
url: string, | ||
parsers: { name: string; result: any }[], | ||
{ urls, page }?: { urls: Set<string>; page: Page } | ||
) => Promise<Result | undefined>; |
This file contains 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
46 changes: 46 additions & 0 deletions
46
audit/apps/audit/src/checkers/async/rules/hasBasicLayoutElement.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Checker } from '../checker'; | ||
import { Page } from 'puppeteer'; | ||
|
||
export const hasBasicLayoutElement: Checker = async ( | ||
_url: string, | ||
parsers: { name: string; result: any }[], | ||
{ page }: { page: Page } | ||
): Promise<{ name: string; result: any; message: string } | undefined> => { | ||
const header = await page.evaluate(() => { | ||
return document.querySelector('header'); | ||
}); | ||
|
||
if (header === null) { | ||
return Promise.resolve({ | ||
name: 'hasBasicLayoutElement', | ||
result: undefined, | ||
message: 'Its looks like yo do not have any header', | ||
}); | ||
} | ||
|
||
const body = await page.evaluate(() => { | ||
return document.querySelector('body'); | ||
}); | ||
|
||
if (body === null) { | ||
return Promise.resolve({ | ||
name: 'hasBasicLayoutElement', | ||
result: undefined, | ||
message: 'Its looks like yo do not have any body', | ||
}); | ||
} | ||
|
||
const footer = await page.evaluate(() => { | ||
return document.querySelector('header'); | ||
}); | ||
|
||
if (footer === null) { | ||
return Promise.resolve({ | ||
name: 'hasBasicLayoutElement', | ||
result: undefined, | ||
message: 'Its looks like yo do not have any footer', | ||
}); | ||
} | ||
|
||
return Promise.resolve(undefined); | ||
}; |
41 changes: 41 additions & 0 deletions
41
audit/apps/audit/src/checkers/async/rules/hasValidDoctype.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Checker } from "../checker"; | ||
import { Page } from 'puppeteer'; | ||
|
||
export const hasValidDoctype: Checker = async ( | ||
_url: string, | ||
parsers: { name: string; result: any }[], | ||
{ page }: { page: Page } | ||
): Promise<{ name: string; result: any; message: string } | undefined> => { | ||
const doctype = await page.evaluate(() => { | ||
const node = document.doctype; | ||
if (node) { | ||
return { | ||
name: node.name, | ||
publicId: node.publicId, | ||
systemId: node.systemId, | ||
}; | ||
} | ||
return null; // Si pas de doctype | ||
}); | ||
|
||
if (!doctype) { | ||
return Promise.resolve({ | ||
name: 'hasValidDoctype', | ||
result: undefined, | ||
message: 'You do not have a doctype', | ||
}); | ||
} | ||
|
||
if ( | ||
doctype.name !== 'html' || | ||
doctype.publicId !== '' || | ||
doctype.systemId !== '' | ||
) { | ||
return Promise.resolve({ | ||
name: 'hasValidDoctype', | ||
result: doctype, | ||
message: 'You do not have a valide doctype', | ||
}); | ||
} | ||
return Promise.resolve(undefined); | ||
}; |
27 changes: 27 additions & 0 deletions
27
audit/apps/audit/src/checkers/async/rules/hasValidElementInsideHead.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Checker } from '../checker'; | ||
import { Page } from 'puppeteer'; | ||
|
||
export const hasValidElementInsideHead: Checker = async ( | ||
_url: string, | ||
parsers: { name: string; result: any }[], | ||
{ page }: { page: Page } | ||
): Promise<{ name: string; result: any; message: string } | undefined> => { | ||
const elements = await page.evaluate(() => { | ||
return Array.from(document.querySelectorAll('head > *')).filter( | ||
(node) => | ||
!['script', 'style', 'link', 'meta', 'title'].includes( | ||
node.tagName.toLowerCase() | ||
) | ||
); | ||
}); | ||
|
||
if (elements.length > 0) { | ||
return Promise.resolve({ | ||
name: 'hasValidElementInsideHead', | ||
result: elements, | ||
message: 'You have invalid elements inside head', | ||
}); | ||
} | ||
|
||
return Promise.resolve(undefined); | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export type Result = { name: string; result: any; message?: string }; |
This file contains 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