Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ TinCan client library
Agent.prototype.log("fromJSON");
var _agent = JSON.parse(agentJSON);

if (_agent.hasOwnProperty("objectType") && _agent.objectType !== Agent.prototype.objectType) {
throw "Unexpected object type for agent: " + _agent.objectType;
}

return new Agent(_agent);
};
}());
4 changes: 4 additions & 0 deletions src/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ TinCan client library
Group.prototype.log("fromJSON");
var _group = JSON.parse(groupJSON);

if (_group.hasOwnProperty("objectType") && _group.objectType !== Group.prototype.objectType) {
throw "Unexpected object type for group: " + _group.objectType;
}

return new Group(_group);
};
}());
8 changes: 7 additions & 1 deletion src/TinCan.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,13 @@ var TinCan;
delete qsParams.actor;
}
catch (ex) {
this.log("_initFromQueryString - failed to set actor: " + ex);
try {
this.actor = TinCan.Group.fromJSON(qsParams.actor);
delete qsParams.actor;
}
catch (ex2) {
this.log("_initFromQueryString - failed to set actor: " + ", ".join([ex, ex2]));
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion test/js/unit/Agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@
;

result = TinCan.Agent.fromJSON(JSON.stringify(raw));
ok(result instanceof TinCan.Agent, "returns TinCan.Agent");
ok(result instanceof TinCan.Agent, "returns TinCan.Agent (objectType omitted)");

raw.objectType = 'Agent';
result = TinCan.Agent.fromJSON(JSON.stringify(raw));
ok(result instanceof TinCan.Agent, "returns TinCan.Agent (objectType set explicitly)");

raw.objectType = 'invalid';
throws(
function () {
TinCan.Agent.fromJSON(JSON.stringify(raw));
},
"exception on invalid objectType"
);
}
);

Expand Down
12 changes: 12 additions & 0 deletions test/js/unit/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@

result = TinCan.Group.fromJSON(JSON.stringify(raw));
ok(result instanceof TinCan.Group, "returns TinCan.Group");

raw.objectType = 'Group';
result = TinCan.Group.fromJSON(JSON.stringify(raw));
ok(result instanceof TinCan.Group, "returns TinCan.Group (objectType set explicitly)");

raw.objectType = 'invalid';
throws(
function () {
TinCan.Group.fromJSON(JSON.stringify(raw));
},
"exception on invalid objectType"
);
}
);

Expand Down