From 4458978d3871909c047319aba1102f32e6b51349 Mon Sep 17 00:00:00 2001 From: Eric Mill Date: Fri, 13 Jul 2018 12:55:07 -0400 Subject: [PATCH] start measuring uswds presence --- scanners/uswds.js | 15 ++++++++++++++- scanners/uswds.py | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/scanners/uswds.js b/scanners/uswds.js index 45d52fde..1703eead 100644 --- a/scanners/uswds.js +++ b/scanners/uswds.js @@ -36,14 +36,27 @@ module.exports = { else throw exc; } + // Do a quick text match on the HTML to find out of date USWDS + // banner text. const html = await page.content(); - data.banner_bad_text = hasBadText(html); + // Search DOM for evidence of USWDS being present at all. + data.present = await uswdsPresent(page); + return data; } } +// Simple text match on some old text. var hasBadText = (html) => { return (html.search("Federal government websites always use a .gov or .mil domain.") >= 0) }; + + +// Checks for any element with a class with "usa-" in it. +// TODO: Should "usa-" at least be at the start of the string? +var uswdsPresent = async (page) => { + var match = await page.$('[class*=usa-]'); + return (match != null); +}; diff --git a/scanners/uswds.py b/scanners/uswds.py index ee848175..f553558b 100644 --- a/scanners/uswds.py +++ b/scanners/uswds.py @@ -51,13 +51,13 @@ def to_rows(data): return [[ data['url'], - data.get('banner_present'), + data.get('present'), data.get('banner_bad_text'), ]] headers = [ 'Scanned URL', - 'USWDS Banner Present', + 'USWDS Present', 'USWDS Bad Banner Text' ]