Skip to content

Commit

Permalink
Resolved controller test failure - Improved how the check for req.par…
Browse files Browse the repository at this point in the history
…ams qualifies
  • Loading branch information
maxxcrawford committed Aug 17, 2020
1 parent 0016158 commit 8b3cd29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
15 changes: 7 additions & 8 deletions controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ function _getFeaturedBreach(allBreaches, breachQueryValue) {
return HIBP.getBreachByName(allBreaches, lowercaseBreachValue);
}

function _getBreachRequest(query = false, param = false) {
if (query) { return query; }
if (param) { return param; }
}

async function home(req, res) {
const formTokens = {
pageToken: AppConstants.PAGE_TOKEN_TIMER > 0 ? generatePageToken(req) : "",
Expand All @@ -44,11 +39,13 @@ async function home(req, res) {
});
}

if (req.query.breach || req.params.breach) {
if (req.params && req.params.breach) {
req.query.breach = req.params.breach;
}

const requestedBreach = _getBreachRequest(req.query.breach, req.params.breach);
if (req.query.breach) {

featuredBreach = _getFeaturedBreach(req.app.locals.breaches, requestedBreach);
featuredBreach = _getFeaturedBreach(req.app.locals.breaches, req.query.breach);

if (!featuredBreach) {
return notFound(req, res);
Expand All @@ -71,6 +68,8 @@ async function home(req, res) {
});
}



res.render("monitor", {
title: req.fluentFormat("home-title"),
featuredBreach: featuredBreach,
Expand Down
1 change: 1 addition & 0 deletions routes/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const router = express.Router();
const csrfProtection = csrf();

router.get("/", csrfProtection, home);
router.get("/share/", csrfProtection, home);
router.get("/share/purple", csrfProtection, home);
router.get("/share/red", csrfProtection, home);
router.get("/share/blue", csrfProtection, home);
Expand Down

0 comments on commit 8b3cd29

Please sign in to comment.