Skip to content

Commit

Permalink
Merge 3a7f697 into 2aff7b4
Browse files Browse the repository at this point in the history
  • Loading branch information
Pchelolo committed Feb 21, 2018
2 parents 2aff7b4 + 3a7f697 commit 83785bb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 12 deletions.
28 changes: 16 additions & 12 deletions lib/revision_table_access_check_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ function redirect(content, location, options) {

module.exports = (hyper, req, next, options, specInfo) => {
const rp = req.params;
const continueRequest = () => next(hyper, req)
.then((res) => {
if (res.status === 302
&& (req.query.redirect === false || mwUtil.isNoCacheRequest(req))) {
res.status = 200;
delete res.headers.location;
}
return res;
});

if (mwUtil.isNoCacheRequest(req)) {
return continueRequest();
}

const titleParamName = options.title ? options.title : 'title';
const checkURIParts = [rp.domain, 'sys', 'page_revisions', 'page', rp[titleParamName]];
if (rp.revision) {
Expand All @@ -32,9 +46,7 @@ module.exports = (hyper, req, next, options, specInfo) => {
.then((res) => {
const revision = res.body.items[0];

if (revision.redirect
&& req.query.redirect !== false
&& !mwUtil.isNoCacheRequest(req)) {
if (revision.redirect && req.query.redirect !== false) {
const htmlPath = [rp.domain, 'sys', 'parsoid', 'html', rp[titleParamName]];
if (rp.revision) {
htmlPath.push(`${rp.revision}`);
Expand Down Expand Up @@ -79,14 +91,6 @@ module.exports = (hyper, req, next, options, specInfo) => {
}
});
}
return next(hyper, req)
.then((res) => {
if (res.status === 302
&& (req.query.redirect === false || mwUtil.isNoCacheRequest(req))) {
res.status = 200;
delete res.headers.location;
}
return res;
});
return continueRequest();
});
};
43 changes: 43 additions & 0 deletions test/features/pagecontent/access_checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,49 @@ describe('Access checks', () => {
assert.deepEqual(res.status, 200);
});
});

it('should understand the page was deleted again', () => {
const api = nock(server.config.apiURL)
// Other requests return nothing as if the page is deleted.
.post('').reply(200, emptyResponse);
// Fetch the page
return preq.get({
uri: `${server.config.bucketURL}/title/${encodeURIComponent(deletedPageTitle)}`,
headers: {
'cache-control': 'no-cache'
}
})
.then(() => {
throw new Error('404 should have been returned for a deleted page');
}, (e) => {
assert.deepEqual(e.status, 404);
assert.contentType(e, 'application/problem+json');
})
.then(() => {
api.done();
})
.finally(() => {
nock.cleanAll();
});
});

it('Should understand that the page was undeleted base on html request', () => {
return preq.get({
uri: `${server.config.bucketURL}/html/${encodeURIComponent(deletedPageTitle)}`,
headers: {
'cache-control': 'no-cache'
}
})
.then((res) => {
assert.deepEqual(res.status, 200);
return preq.get({
uri: `${server.config.bucketURL}/html/${encodeURIComponent(deletedPageTitle)}/${deletedPageOlderRevision}`,
});
})
.then((res) => {
assert.deepEqual(res.status, 200);
});
});
});

describe('Restricting', () => {
Expand Down

0 comments on commit 83785bb

Please sign in to comment.