Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backwards Compatibility for Dual 1.0.3 and 2.0.0 Conformance #270

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
44 changes: 3 additions & 41 deletions batteries.js
Original file line number Diff line number Diff line change
Expand Up @@ -6676,7 +6676,7 @@ module.exports = {
}
},
"2.0.0": {
"conformanceTestCount": 1442,
"conformanceTestCount": 1435,
"tests": {
"text": "",
"children": [
Expand Down Expand Up @@ -13576,46 +13576,8 @@ module.exports = {
"text": "Alternate Request Syntax Requirements",
"children": [
{
"text": "The LRS does NOT allow Alternate Request Syntax in xAPI 2.0",
"children": [
{
"text": "An LRS rejects POST requests containing method query parameters",
"children": []
},
{
"text": "An LRS rejects an alternate request syntax not issued as a POST",
"children": []
},
{
"text": "An LRS rejects an alternate request syntax PUT issued as a POST",
"children": []
},
{
"text": "During an alternate request syntax the LRS treats the listed form parameters, 'Authorization', 'X-Experience-API-Version', 'Content-Type', 'Content-Length', 'If-Match' and 'If-None-Match', as header parameters",
"children": []
},
{
"text": "An LRS will reject an alternate request syntax which contains any extra information with error code 400 Bad Request",
"children": []
},
{
"text": "An LRS will reject an alternate request syntax sending content which does not have a form parameter with the name of \"content\"",
"children": [
{
"text": "will reject PUT with content body which is url encoded",
"children": []
},
{
"text": "will reject PUT with no content body",
"children": []
},
{
"text": "will reject PUT with content body which is not url encoded",
"children": []
}
]
}
]
"text": "The LRS Spec does not mandate any properties regarding Alternate Request Syntax in xAPI 2.0",
"children": []
}
]
},
Expand Down
1 change: 1 addition & 0 deletions bin/update-batteries.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function createMockApp() {
let mockApp = expresss();

mockApp.all("/xapi/*", (req, res, next) => {

res.set('Content-Type', 'text/plain');
res.set('x-experience-api-consistent-through', (new Date(Date.now() +100)).toISOString());
res.set('x-experience-api-version', "1.0.3");
Expand Down
38 changes: 38 additions & 0 deletions local/super-request/lib/cookieJar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict'

var tough = require('tough-cookie');

var Cookie = tough.Cookie
var CookieJar = tough.CookieJar

exports.parse = function (str) {
if (str && str.uri) {
str = str.uri
}
if (typeof str !== 'string') {
throw new Error('The cookie function only accepts STRING as param')
}
return Cookie.parse(str, {loose: true})
}

// Adapt the sometimes-Async api of tough.CookieJar to our requirements
function RequestJar (store) {
var self = this
self._jar = new CookieJar(store, {looseMode: true})
}
RequestJar.prototype.setCookie = function (cookieOrStr, uri, options) {
var self = this
return self._jar.setCookieSync(cookieOrStr, uri, options || {})
}
RequestJar.prototype.getCookieString = function (uri) {
var self = this
return self._jar.getCookieStringSync(uri)
}
RequestJar.prototype.getCookies = function (uri) {
var self = this
return self._jar.getCookiesSync(uri)
}

exports.createCookieJar = function (store) {
return new RequestJar(store)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adl-lrs-conformance-tests",
"version": "2.0.0-0",
"version": "2.0.0-1",
"description": "lrs-conformance-tests",
"main": "./bin/console_runner.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion test/v1_0_3/E.Data2.4.10-VersionProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
(function (module, fs, extend, moment, request, requestPromise, chai, liburl, Joi, helper, multipartParser, redirect, templatingSelection) {
// "use strict";

const REG_ALLOWED_VERSIONS = /^2\.0\.0$|^1\.0(\.[1-3])$/;

var expect = chai.expect;
if(global.OAUTH)
request = helper.OAuthRequest(request);
Expand Down Expand Up @@ -60,7 +62,7 @@ describe('Version Property Requirements (Data 2.4.10)', () => {
}
else{
var results = helper.parse(res.body);
expect(results.version).to.equal(version);
expect(results.version).to.match(REG_ALLOWED_VERSIONS);
done();
}
});
Expand Down
11 changes: 7 additions & 4 deletions test/v1_0_3/H.Communication3.3-Versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
(function (module, fs, extend, moment, request, requestPromise, chai, liburl, Joi, helper, multipartParser, redirect) {
// "use strict";


const REG_ALLOWED_VERSIONS = /^2\.0\.0$|^1\.0(\.[1-3])$/;

var expect = chai.expect;
if(global.OAUTH)
request = helper.OAuthRequest(request);
Expand Down Expand Up @@ -55,7 +58,7 @@ describe('Versioning Requirements (Communication 3.3)', () => {
}
else{
expect(res.headers).to.have.property('x-experience-api-version');
expect(res.headers['x-experience-api-version']).to.equal(helper.getXapiVersion());
expect(res.headers['x-experience-api-version']).to.match(REG_ALLOWED_VERSIONS);
done();
}
});
Expand Down Expand Up @@ -140,7 +143,7 @@ describe('Versioning Requirements (Communication 3.3)', () => {
if (err) {
done(err);
} else if (res.statusCode === 400) {
expect(res.headers['x-experience-api-version']).to.match(/^1\.0\.3$|^0\.95?$/)
expect(res.headers['x-experience-api-version']).to.match(REG_ALLOWED_VERSIONS)
done();
} else if (res.statusCode === 404) {
expect(res.headers['x-experience-api-version']).to.match(/^0\.95?$/);
Expand All @@ -167,7 +170,7 @@ describe('Versioning Requirements (Communication 3.3)', () => {
if (err) {
done(err);
} else if (res.statusCode === 400) {
expect(res.headers['x-experience-api-version']).to.match(/^1\.0\.3$|^0\.95?$/);
expect(res.headers['x-experience-api-version']).to.match(REG_ALLOWED_VERSIONS);
done();
} else if (res.statusCode === 404) {
expect(res.headers['x-experience-api-version']).to.match(/^0\.95?$/);
Expand All @@ -194,7 +197,7 @@ describe('Versioning Requirements (Communication 3.3)', () => {
if (err) {
done(err);
} else if (res.statusCode === 400) {
expect(res.headers['x-experience-api-version']).to.match(/^1\.0\.3$|^0\.95?$/);
expect(res.headers['x-experience-api-version']).to.match(REG_ALLOWED_VERSIONS);
done();
} else if (res.statusCode === 404) {
expect(res.headers['x-experience-api-version']).to.match(/^0\.95?$/);
Expand Down
138 changes: 4 additions & 134 deletions test/v2_0/H.Communication1.3-AlternateRequestSyntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,139 +11,9 @@ const { expect } = require('chai');
if(global.OAUTH)
superRequest = oldHelpers.OAuthRequest(superRequest);

describe('Alternate Request Syntax Requirements (Communication 1.3)', function () {
describe('Alternate Request Syntax Requirements', function () {

/**
* Alternate request syntax was removed from the IEEE specification.
*
* This area is a bit vague, but for now we are assuming that this is simply not allowed
* and will expect that the LRS
*/
describe('The LRS does NOT allow Alternate Request Syntax in xAPI 2.0', function () {

it('An LRS rejects POST requests containing method query parameters', async function () {
let alternateParams = {
method: "GET"
};

let res = await requests.postToStatements(null, alternateParams, null);
expect(res.status).to.be.within(400, 499);
});

it('An LRS rejects an alternate request syntax not issued as a POST', async function () {
let alternateParams = {
method: "POST"
};

let res = await requests.putToStatements(null, alternateParams, null);
expect(res.status).to.be.within(400, 499);
});

it('An LRS rejects an alternate request syntax PUT issued as a POST', async function () {
let alternateParams = {
method: "PUT"
};

let res = await requests.postToStatements(null, alternateParams, null);
expect(res.status).to.be.within(400, 499);
});

/**
* From here on, these tests are pretty pointless now.
*
* These will be removed in an upcoming version of the 2.0 test suite, but as this is a general cleanup,
* updating the test quantity would warrant a version increment.
*/
it('During an alternate request syntax the LRS treats the listed form parameters, \'Authorization\', \'X-Experience-API-Version\', \'Content-Type\', \'Content-Length\', \'If-Match\' and \'If-None-Match\', as header parameters (Communictation 1.3.s3.b7)', async function () {
var alternateParams = {
method: 'PUT'
};
var sID = oldHelpers.generateUUID();
var formBody = {
statementId: sID,
'X-Experience-API-Version': '0.8',
content: oldHelpers.buildStatement()
}

let res = await requests.postToStatements(formBody, alternateParams, null);
expect(res.status).to.be.within(400, 499);
});

it('An LRS will reject an alternate request syntax which contains any extra information with error code 400 Bad Request (Communication 1.3.s3.b4)', async function () {
var alternateParams = {
method: 'PUT',
statementId: sID
};
var templates = [
{statement: '{{statements.default}}'}
];
var data = oldHelpers.createFromTemplate(templates);
var statement = data.statement;
var sID = oldHelpers.generateUUID();

var formBody = {
statementId: sID,
content: statement,
};

let res = await requests.postToStatements(formBody, alternateParams, null);
expect(res.status).to.be.within(400, 499);
});

describe('An LRS will reject an alternate request syntax sending content which does not have a form parameter with the name of "content" (Communication 1.3.s3.b4)', function () {
it('will reject PUT with content body which is url encoded', async function () {
let defaultHeaders = oldHelpers.addAllHeaders({});
let auth = defaultHeaders['Authorization'];
let alternateParams = {
method: 'PUT'
};

let templates = [
{statement: '{{statements.default}}'}
];
let statement = oldHelpers.createFromTemplate(templates).statement;
let payload = {
statementId: oldHelpers.generateUUID(),
content: JSON.stringify(statement),
'X-Experience-API-Version': '2.0.0',
Authorization: auth
};
let headers = {
'content-type': 'application/x-www-form-urlencoded'
};

let res = await requests.postToStatements(payload, alternateParams, headers);
expect(res.status).to.be.within(400, 499);
});

it('will reject PUT with no content body', async function () {
let alternateParams = {
method: "PUT"
};

let res = await requests.postToStatements(null, alternateParams, null);
expect(res.status).to.be.within(400, 499);
});

it('will reject PUT with content body which is not url encoded', async function () {
var headers = oldHelpers.addAllHeaders({});
var alternateParams = oldHelpers.getUrlEncoding({method: 'PUT'});
var templates = [
{statement: '{{statements.default}}'}
];
var statement = oldHelpers.createFromTemplate(templates).statement;
headers['content-type'] = 'application/x-www-form-urlencoded';

var payload = {
statementId: oldHelpers.generateUUID(),
content: JSON.stringify(statement),
'X-Experience-API-Version': '2.0.0'
}

let res = await requests.postToStatements(payload, alternateParams, null);
expect(res.status).to.be.within(400, 499);
});
});
it('The LRS Spec does not mandate any properties regarding Alternate Request Syntax in xAPI 2.0', async function () {
expect(true).to.eql(true);
});

});
});
12 changes: 7 additions & 5 deletions test/v2_0/H.Communication3.3-Versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
(function (module, fs, extend, moment, request, requestPromise, chai, liburl, Joi, helper, multipartParser, redirect) {
// "use strict";

const REG_ALLOWED_VERSIONS = /^2\.0\.0$|^1\.0(\.[1-3])$/;

var expect = chai.expect;
if(global.OAUTH)
request = helper.OAuthRequest(request);
Expand Down Expand Up @@ -55,7 +57,7 @@ describe('Versioning Requirements (Communication 3.3)', () => {
}
else{
expect(res.headers).to.have.property('x-experience-api-version');
expect(res.headers['x-experience-api-version']).to.equal(helper.getXapiVersion());
expect(res.headers['x-experience-api-version']).to.match(REG_ALLOWED_VERSIONS);
done();
}
});
Expand Down Expand Up @@ -141,7 +143,7 @@ describe('Versioning Requirements (Communication 3.3)', () => {
if (err) {
done(err);
} else if (res.statusCode === 400) {
expect(res.headers['x-experience-api-version']).to.match(/^2\.0\.0$|^0\.95?$/)
expect(res.headers['x-experience-api-version']).to.match(REG_ALLOWED_VERSIONS);
done();
} else if (res.statusCode === 404) {
expect(res.headers['x-experience-api-version']).to.match(/^0\.95?$/);
Expand All @@ -168,7 +170,7 @@ describe('Versioning Requirements (Communication 3.3)', () => {
if (err) {
done(err);
} else if (res.statusCode === 400) {
expect(res.headers['x-experience-api-version']).to.match(/^2\.0\.0$|^0\.95?$/);
expect(res.headers['x-experience-api-version']).to.match(REG_ALLOWED_VERSIONS);
done();
} else if (res.statusCode === 404) {
expect(res.headers['x-experience-api-version']).to.match(/^0\.95?$/);
Expand All @@ -195,13 +197,13 @@ describe('Versioning Requirements (Communication 3.3)', () => {
if (err) {
done(err);
} else if (res.statusCode === 400) {
expect(res.headers['x-experience-api-version']).to.match(/^2\.0\.0$|^0\.95?$/);
expect(res.headers['x-experience-api-version']).to.match(REG_ALLOWED_VERSIONS);
done();
} else if (res.statusCode === 404) {
expect(res.headers['x-experience-api-version']).to.match(/^0\.95?$/);
done();
} else {
throw new Error(`Version header (${res.headers['x-experience-api-version']}) and Status Code (${res.statusCode}) do not match specification. Expected version header 2.0.0 with status code 400 or version header 0.9 or 0.95 with status code either 400 or 404.`);
throw new Error(`Version header (${res.headers['x-experience-api-version']}) and Status Code (${res.statusCode}) do not match specification. Expected version header 2.0.0 or 1.0.X with status code 400, or version header 0.9 or 0.95 with status code either 400 or 404.`);
done();
}
});
Expand Down
2 changes: 1 addition & 1 deletion version.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
"versionNumber": "2.0.0.0",
"versionNumber": "2.0.0.1",
"versionNumberLegacy": "1.0.3.18"
}