forked from AmazeeLabs/algm_drutiny
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
117 additions
and
1 deletion.
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,15 @@ | ||
title: "Page Speed Insights policy" | ||
class: \Drutiny\algm\Audit\PageSpeedInsightsScore | ||
name: ALGMPerformance:PSI | ||
description: | | ||
Runs PSI against LAGOON_ROUTE | ||
success: | | ||
Success: All PageSpeed Insights metrics are nominal | ||
Performance {{ report.performance }} | ||
SEO {{ report.seo }} | ||
Accessibility {{ report.accessibility }} | ||
failure: | | ||
Warning: PageSpeed Insights Minimums Not Met | ||
Performance {{ report.performance }} | ||
SEO {{ report.seo }} | ||
Accessibility {{ report.accessibility }} |
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,6 @@ | ||
title: 'ALGM Performance' | ||
description: 'Site Performance Audit for ALGM.' | ||
policies: | ||
'ALGMPerformance:PSI': { } | ||
format: | ||
html: { template: page, content: [{ heading: Purpose, body: "This report is designed to provide some feedback on the overall health of\nthe web application by performing some deep dive analysis. The items\nsurfaced in the report can help improve performance and stability.\n" }, { heading: 'Reporting period', body: "Period | Date time\n------ | ---------\nStart | {{reporting_period_start}}\nEnd | {{reporting_period_end}}\n" }, { heading: Recommendations, body: "<ul>\n{{# remediations }}\n <li>{{{ . }}}</li>\n{{/ remediations }}\n</ul>\n" }, { heading: Findings, body: "{{{ severity_stats }}}\n### Issue Summary\n{{{ summary_table }}}\n\n{{#failures}}\n ### Issues\n {{# output_failure }}\n {{{.}}}\n {{/ output_failure }}\n{{/failures}}\n\n{{#warnings}}\n ### Warnings\n {{# output_warning }}\n {{{.}}}\n {{/ output_warning }}\n{{/warnings}}\n" }, { heading: Appendix, body: "{{#notices}}\n ### Appendix - Analysis\n\n The various appendices provides more detailed data regarding the health of\n the site.\n\n {{# output_notice }}\n {{{.}}}\n {{/ output_notice }}\n{{/notices}}\n\n{{#errors}}\n ### Appendix - Errors\n\n During the production of this report, not all report policies were able to\n be carried out due to errors encounted.\n\n {{#output_error}}\n {{{.}}}\n {{/output_error}}\n{{/errors}}\n\n### Appendix - Summary\nThe below table describes all audit and analysis work completed for the\nproduction of this report and their associated outcomes.\n\n{{{ appendix_table }}}\n\n{{#passes}}\n### Appendix - Successful Assessments\n{{# output_success }}\n {{{.}}}\n{{/ output_success }}\n{{/passes}}\n" }] } |
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
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,61 @@ | ||
<?php | ||
|
||
namespace Drutiny\algm\Audit; | ||
|
||
use Drutiny\Audit; | ||
use Drutiny\Sandbox\Sandbox; | ||
|
||
/** | ||
* | ||
*/ | ||
class PageSpeedInsightsScore extends Audit { | ||
|
||
const THRESHOLD_PERFORMANCE = 0.5; | ||
|
||
const THRESHOLD_ACCESSIBILITY = 0.5; | ||
|
||
const THRESHOLD_SEO = 0.5; | ||
|
||
const PSI_API_ENDPOINT = 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function audit(Sandbox $sandbox) { | ||
|
||
$route = getenv("LAGOON_ROUTE"); | ||
if (empty($route)) { | ||
return AUDIT::ERROR; | ||
} | ||
|
||
$queryParams = [ | ||
'fields' => 'lighthouseResult/categories/*/score', | ||
'strategy' => 'desktop', | ||
'url' => $route, | ||
]; | ||
|
||
$categories = '&category=SEO&category=PERFORMANCE&category=ACCESSIBILITY'; | ||
$params = http_build_query($queryParams) . $categories; | ||
$response = file_get_contents(self::PSI_API_ENDPOINT . '?' . $params); | ||
$responseObj = json_decode($response, TRUE); | ||
|
||
$performanceScore = $responseObj['lighthouseResult']['categories']['performance']['score']; | ||
$accessibilityScore = $responseObj['lighthouseResult']['categories']['accessibility']['score']; | ||
$seoScore = $responseObj['lighthouseResult']['categories']['seo']['score']; | ||
|
||
$sandbox->setParameter('report', [ | ||
'performance' => $performanceScore, | ||
'seo' => $seoScore, | ||
'accessibility' => $accessibilityScore, | ||
]); | ||
|
||
if ($performanceScore < self::THRESHOLD_PERFORMANCE || | ||
$accessibilityScore < self::THRESHOLD_ACCESSIBILITY || | ||
$seoScore < self::THRESHOLD_SEO | ||
) { | ||
return Audit::FAIL; | ||
} | ||
|
||
return Audit::PASS; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace DrutinyTests\Audit; | ||
|
||
use Drutiny\algm\Audit\ClamAVScan; | ||
use Drutiny\Container; | ||
use Drutiny\Policy; | ||
use Drutiny\Sandbox\Sandbox; | ||
use Drutiny\Target\Registry as TargetRegistry; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Log\NullLogger; | ||
|
||
class PageSpeedInsightsScore extends TestCase { | ||
|
||
protected $target; | ||
|
||
public function __construct() | ||
{ | ||
Container::setLogger(new NullLogger()); | ||
$this->target = TargetRegistry::getTarget('none', ''); | ||
parent::__construct(); | ||
} | ||
|
||
/** @test */ | ||
public function it_should_run_a_psi_scan_against_a_site() { | ||
$policy = Policy::load('ALGMPerformance:PSI'); | ||
$sandbox = new Sandbox($this->target, $policy); | ||
|
||
$response = $sandbox->run(); | ||
var_dump($response->isSuccessful()); | ||
var_dump($response->getFailure()); | ||
$this->assertTrue($response->isSuccessful()); | ||
} | ||
|
||
} |