Server explosion: Badge.validateBody needs sanity checking. #178

Closed
brianloveswords opened this Issue Jun 4, 2012 · 1 comment

Comments

Projects
None yet
1 participant
Contributor

brianloveswords commented Jun 4, 2012

Need to examine this:

/srv/openbadges/models/badge.js:146
      current = current[f];
                       ^
TypeError: Cannot read property 'recipient' of undefined
    at /srv/openbadges/models/badge.js:146:24
    at Array.forEach (native)
    at /srv/openbadges/models/badge.js:144:12
    at Object.missing (/srv/openbadges/models/badge.js:153:19)
    at Function.validateBody (/srv/openbadges/models/badge.js:173:8)
    at /srv/openbadges/controllers/baker.js:72:17
    at /srv/openbadges/lib/remote.js:74:12
    at Request._callback (/srv/openbadges/lib/remote.js:120:16)
    at Request.callback (/srv/openbadges/node_modules/request/main.js:119:22)
    at Request.<anonymous> (native)

@brianloveswords brianloveswords added a commit that referenced this issue Jun 4, 2012

@brianloveswords brianloveswords Add test for #178. fb49851
Contributor

brianloveswords commented Jun 4, 2012

This was happening because Badge.validateBody was assuming a somewhat valid body as it was originally called from an instance validator. The instance validation would only hit Badge.validateBody once it did basic sanity checks.

We started using Badge.validateBody outside of just instances, and in places before doing the basic sanity check – in this case, from the baker controller. The responsibility of sanity checking belongs in the validator, so I added those checks into Badge.validateBody.

(cc @cmcavoy, @stenington)

@brianloveswords brianloveswords added a commit that referenced this issue Jun 4, 2012

@brianloveswords brianloveswords More testing for #178.
We should also be testing for the right type of object (namely, an object).
d5b689e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment