mirror of https://github.com/docker/docs.git
Adding unit test for official repo detection
This commit is contained in:
parent
0875ecd4b3
commit
1fa8127145
|
@ -11,6 +11,7 @@ var metrics = require('./Metrics');
|
|||
var router = require('./Router');
|
||||
var template = require('./MenuTemplate');
|
||||
var webUtil = require('./WebUtil');
|
||||
var util = require ('./Util');
|
||||
|
||||
webUtil.addWindowSizeSaving();
|
||||
webUtil.addLiveReload();
|
||||
|
@ -34,7 +35,6 @@ ipc.on('application:quitting', opts => {
|
|||
});
|
||||
|
||||
ipc.on('application:open-url', opts => {
|
||||
var repoRegexp = /[a-z0-9]+(?:[._-][a-z0-9]+)*/;
|
||||
var parser = document.createElement('a');
|
||||
parser.href = opts.url;
|
||||
|
||||
|
@ -49,7 +49,7 @@ ipc.on('application:open-url', opts => {
|
|||
var repo = tokens.slice(2).join('/');
|
||||
|
||||
// Only accept official repos for now
|
||||
if (repo.indexOf('/') !== -1 || !repoRegexp.test(repo)) {
|
||||
if (repo.indexOf('/') !== -1 || !util.isOfficialRepo(repo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
jest.dontMock('./Util');
|
||||
var util = require('./Util');
|
||||
|
||||
describe('Util', function () {
|
||||
it('accepts official repo', () => {
|
||||
expect(util.isOfficialRepo('redis')).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects falsy value as official repo', () => {
|
||||
expect(util.isOfficialRepo(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects empty repo name', () => {
|
||||
expect(util.isOfficialRepo('')).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects repo with non official namespace', () => {
|
||||
expect(util.isOfficialRepo('kitematic/html')).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects repo with a different registry address', () => {
|
||||
expect(util.isOfficialRepo('www.myregistry.com/kitematic/html')).toBe(false);
|
||||
});
|
||||
});
|
|
@ -44,5 +44,12 @@ module.exports = {
|
|||
} catch (err) {}
|
||||
return settingsjson;
|
||||
},
|
||||
isOfficialRepo: function (name) {
|
||||
if (!name || !name.length) {
|
||||
return false;
|
||||
}
|
||||
var repoRegexp = /^[a-z0-9]+(?:[._-][a-z0-9]+)*$/;
|
||||
return repoRegexp.test(name);
|
||||
},
|
||||
webPorts: ['80', '8000', '8080', '3000', '5000', '2368', '9200', '8983']
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue