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

[BREAK] Remove patch info from endpoint /api/info for non-logged in users #16050

Merged
merged 7 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
13 changes: 2 additions & 11 deletions app/api/server/default/info.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { hasRole } from '../../../authorization';
import { Info } from '../../../utils';
import { API } from '../api';
import { getServerInfo } from '../lib/server-info';

API.default.addRoute('info', { authRequired: false }, {
get() {
const user = this.getLoggedInUser();

if (user && hasRole(user._id, 'admin')) {
return API.v1.success({
info: Info,
});
}

return API.v1.success({
version: Info.version,
});
return API.v1.success(Promise.await(getServerInfo({ user })));
},
});

Expand Down
19 changes: 19 additions & 0 deletions app/api/server/lib/server-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import { Info } from '../../../utils';
import { hasRoleAsync } from '../../../authorization/server/functions/hasRole';

const removePatchInfo = (version) => {
const regex = /(\d+)\.(\d+)/;
return version.match(regex)[0];
};

export async function getServerInfo({ user }) {
if (user && await hasRoleAsync(user._id, 'admin')) {
return {
info: Info,
};
}
return {
version: removePatchInfo(Info.version),
};
}
34 changes: 26 additions & 8 deletions tests/end-to-end/api/00-miscellaneous.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,32 @@ describe('miscellaneous', function() {

describe('API default', () => {
// Required by mobile apps
it('/info', (done) => {
request.get('/api/info')
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('version');
})
.end(done);
describe('/info', () => {
let version;
it('should return "version", "build", "commit" and "marketplaceApiVersion" when the user is logged in', (done) => {
request.get('/api/info')
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body.info).to.have.property('version').and.to.be.a('string');
expect(res.body.info).to.have.property('build').and.to.be.an('object');
expect(res.body.info).to.have.property('commit').and.to.be.an('object');
expect(res.body.info).to.have.property('marketplaceApiVersion').and.to.be.a('string');
version = res.body.info.version;
})
.end(done);
});
it('should return only "version" and the version info must be different qhen the user is not logged in', (done) => {
request.get('/api/info')
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('version');
expect(version).to.not.be.equal(res.body.version);
})
.end(done);
});
});
});

Expand Down