Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: pradeepmurugesan/openbadges
...
head fork: pradeepmurugesan/openbadges
  • 6 commits
  • 5 files changed
  • 0 commit comments
  • 2 contributors
5 controllers/issuer.js
View
@@ -179,6 +179,11 @@ exports.issuerBadgeAddFromAssertion = function(req, res, next) {
// grabbing the remote badge image
var imageUrl = qualifyUrl(assertion.badge.image, assertion.badge.issuer.origin);
remote.badgeImage(imageUrl, function(err, imagedata) {
+ if (err){
+ var error_msg = "trying to grab image at url " + imageUrl + " got error " + err;
+ logger.error(error_msg);
+ return res.json({ message: error_msg }, 502);
+ }
// awarding the badge, only done if this is a POST
if (req.method=='POST') {
var opts = {
16 lib/baker.js
View
@@ -28,10 +28,18 @@ exports.prepare = function(pnginput, data) {
*/
exports.getDataFromImage = function(pnginput) {
- var badgedata = metapng.read(pnginput, KEYWORD)
- , err = new Error('More than one `openbadges` keyword in PNG, aborting.');
+ var badgedata;
+ var err = new Error();
+ err.name = 'ParseError';
+ try {
+ badgedata = metapng.read(pnginput, KEYWORD);
+ }
+ catch (ex) {
+ err.message = 'Unable to read data from PNG: ' + ex;
+ throw err;
+ }
if (badgedata.length > 1) {
- err.name = 'ParseError';
+ err.message = 'More than one `openbadges` keyword in PNG, aborting.';
throw err;
}
return badgedata.toString('utf-8');
@@ -69,4 +77,4 @@ exports.urlFromUpload = function (file, callback) {
return callback(null, url, imagedata);
})
-};
+};
18 static/test/assertions/bad_img.json
View
@@ -0,0 +1,18 @@
+{
+ "recipient": "sha256$4817f7f2b03fb83c669a56ed1212047a8d9ca294aaf7a01c569de070dfb3fe8b",
+ "salt": "ballertime",
+ "evidence": "/badges/html5-basic/example",
+ "badge": {
+ "version": "0.5.0",
+ "name": "HTML5 Fundamental",
+ "image": "https://github.com/mozilla/openbadges/raw/development/static/images/CANT_BE_REACHED.png",
+ "description": "Knows the difference between a <section> and an <article>",
+ "criteria": "/badges/html5-basic",
+ "issuer": {
+ "origin": "http://p2pu.org",
+ "name": "P2PU",
+ "org": "School of Webcraft",
+ "contact": "admin@p2pu.org"
+ }
+ }
+}
2  static/test/assertions/example.json
View
@@ -5,7 +5,7 @@
"badge": {
"version": "0.5.0",
"name": "HTML5 Fundamental",
- "image": "/_demo/cc.large.png",
+ "image": "https://github.com/mozilla/openbadges/raw/development/static/images/demo-badge.png",
"description": "Knows the difference between a <section> and an <article>",
"criteria": "/badges/html5-basic",
"issuer": {
11 test/issuer-test.js
View
@@ -14,7 +14,7 @@ const EXAMPLE_BADGE = {
"badge": {
"version": "0.5.0",
"name": "HTML5 Fundamental",
- "image": "http://p2pu.org/_demo/cc.large.png",
+ "image": "https://github.com/mozilla/openbadges/raw/development/static/images/demo-badge.png",
"description": "Knows the difference between a <section> and an <article>",
"criteria": "/badges/html5-basic",
"issuer": {
@@ -27,6 +27,7 @@ const EXAMPLE_BADGE = {
};
const EXAMPLE_BADGE_URL = suite.url('/test/assertions/example.json');
+const BAD_IMG_BADGE_URL = suite.url('/test/assertions/bad_img.json');
validator.check = (function acceptLocalURLs() {
var oldCheck = validator.check;
@@ -73,6 +74,14 @@ suite
.postFormData({url: suite.url('/does/not/exist')}).expect(502)
.undiscuss()
.discuss('and providing a valid url')
+ .discuss('with an unreachable image')
+ .get("?url=" + BAD_IMG_BADGE_URL)
+ .expect(502)
+ .expect("provides an appropriate error message", function(err, res) {
+ var message = JSON.parse(res.body).message;
+ assert.ok(message.match(/image.*unreachable/i));
+ })
+ .undiscuss()
.discuss('that the user does not have in their backpack')
.get("?url=" + EXAMPLE_BADGE_URL)
.expect(200, {

No commit comments for this range

Something went wrong with that request. Please try again.