-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to match lastest standard requirements (patch)
- Loading branch information
Showing
6 changed files
with
772 additions
and
1,233 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
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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
const convert = { | ||
'a+': 100, | ||
'a': 95, | ||
a: 95, | ||
'a-': 90, | ||
'b+': 85, | ||
'b': 80, | ||
b: 80, | ||
'b-': 75, | ||
'c+': 70, | ||
'c': 65, | ||
c: 65, | ||
'c-': 60, | ||
'd+': 55, | ||
'd': 50, | ||
d: 50, | ||
'd-': 45, | ||
'e+': 40, | ||
'e': 35, | ||
e: 35, | ||
'e-': 30, | ||
'f+': 25, | ||
'f': 0 | ||
f: 0 | ||
} | ||
|
||
module.exports = grade => convert[grade.toLowerCase()] |
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 |
---|---|---|
@@ -1,46 +1,49 @@ | ||
/* | ||
This module is not used at the moment. | ||
If is to be included later 'then-sleep' must be included as a dependency | ||
*/ | ||
|
||
const axios = require('axios') | ||
const sleep = require('then-sleep') | ||
const qs = require('querystring') | ||
const apiUrl = 'https://http-observatory.security.mozilla.org/api/v1' | ||
const calculateScore = require('./calculate-observatory-score') | ||
const logger = require('./logger') | ||
|
||
module.exports = site => { | ||
return new Promise(async (resolve, reject) => { | ||
const siteUrl = new URL(site) | ||
const host = siteUrl.host | ||
const observatoryUrl = `${apiUrl}/analyze?host=${host}` | ||
const options = { | ||
hidden: true, | ||
rescan: true | ||
} | ||
logger('info', ['check-observatory', host, 'initialize']) | ||
await axios.post(observatoryUrl, qs.stringify(options)) | ||
logger('info', ['check-observatory', host, 'got data']) | ||
module.exports = async site => { | ||
const siteUrl = new URL(site) | ||
const host = siteUrl.host | ||
const observatoryUrl = `${apiUrl}/analyze?host=${host}` | ||
const options = { | ||
hidden: true, | ||
rescan: true | ||
} | ||
logger('info', ['check-observatory', host, 'initialize']) | ||
await axios.post(observatoryUrl, qs.stringify(options)) | ||
logger('info', ['check-observatory', host, 'got data']) | ||
|
||
const scan = async () => { | ||
await sleep(2500) | ||
const { data } = await axios.get(observatoryUrl) | ||
if (data.state === 'FINISHED') { | ||
logger('info', ['check-observatory', host, 'finished']) | ||
return resolve([ | ||
{ | ||
id: 'observatory', | ||
title: 'Security', | ||
score: calculateScore(data.grade), | ||
grade: data.grade, | ||
description: 'The Mozilla Observatory teaches you how to configure your sites safely and securely. https://observatory.mozilla.org' | ||
} | ||
]) | ||
} else if (data.error === 'site down') { | ||
logger('error', ['check-observatory', host, data.error]) | ||
return reject(new Error(data.error)) | ||
} else { | ||
logger('info', ['check-observatory', host, 'not finished']) | ||
logger('info', ['check-observatory', host, JSON.stringify(data, null, 2)]) | ||
await scan() | ||
} | ||
const scan = async () => { | ||
await sleep(2500) | ||
const { data } = await axios.get(observatoryUrl) | ||
if (data.state === 'FINISHED') { | ||
logger('info', ['check-observatory', host, 'finished']) | ||
return [ | ||
{ | ||
id: 'observatory', | ||
title: 'Security', | ||
score: calculateScore(data.grade), | ||
grade: data.grade, | ||
description: 'The Mozilla Observatory teaches you how to configure your sites safely and securely. https://observatory.mozilla.org' | ||
} | ||
] | ||
} else if (data.error === 'site down') { | ||
logger('error', ['check-observatory', host, data.error]) | ||
throw new Error(data.error) | ||
} else { | ||
logger('info', ['check-observatory', host, 'not finished']) | ||
logger('info', ['check-observatory', host, JSON.stringify(data, null, 2)]) | ||
await scan() | ||
} | ||
await scan() | ||
}) | ||
} | ||
await scan() | ||
} |
Oops, something went wrong.