mirror of https://github.com/docker/docs.git
Integration tests
This commit is contained in:
parent
e55a8f0add
commit
903a36904a
|
|
@ -0,0 +1,3 @@
|
||||||
|
test:
|
||||||
|
override:
|
||||||
|
- npm run integration
|
||||||
|
|
@ -9,6 +9,9 @@ npm-debug.log
|
||||||
# Signing Identity
|
# Signing Identity
|
||||||
identity*
|
identity*
|
||||||
|
|
||||||
|
# Integration test environment
|
||||||
|
integration
|
||||||
|
|
||||||
# Resources
|
# Resources
|
||||||
resources/docker-*
|
resources/docker-*
|
||||||
resources/boot2docker-*
|
resources/boot2docker-*
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,32 @@
|
||||||
jest.autoMockOff();
|
jest.autoMockOff();
|
||||||
|
|
||||||
|
let hubUtil = require('../src/utils/HubUtil');
|
||||||
|
let Promise = require('bluebird');
|
||||||
|
|
||||||
|
jasmine.getEnv().DEFAULT_TIMEOUT_INTERVAL = 60000;
|
||||||
|
|
||||||
describe('HubUtil Integration Tests', () => {
|
describe('HubUtil Integration Tests', () => {
|
||||||
describe('token refresh', () => {
|
describe('auth', () => {
|
||||||
it('re-auths if the token has expired', () => {
|
pit('successfully authenticates', () => {
|
||||||
expect(true).toBe(true);
|
return new Promise((resolve) => {
|
||||||
|
hubUtil.auth(process.env.INTEGRATION_USER, process.env.INTEGRATION_PASSWORD, (error, response, body) => {
|
||||||
|
expect(response.statusCode).toBe(200);
|
||||||
|
expect(error).toBe(null);
|
||||||
|
|
||||||
|
let data = JSON.parse(body);
|
||||||
|
expect(data.token).toBeTruthy();
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('signup', () => {
|
|
||||||
it('returns a 204 and sets localstorage data', () => {
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('login', () => {
|
|
||||||
it('Returns a 401 with account not active string if not active', () => {
|
|
||||||
|
|
||||||
});
|
|
||||||
it('Returns a 401 if the password is wrong', () => {
|
|
||||||
|
|
||||||
|
pit('provides a 401 if credentials are incorrect', () => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
hubUtil.auth(process.env.INTEGRATION_USER, 'incorrectpassword', (error, response) => {
|
||||||
|
expect(response.statusCode).toBe(401);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,61 @@
|
||||||
jest.autoMockOff();
|
jest.autoMockOff();
|
||||||
|
|
||||||
describe('RegHubUtil Integration Tests', () => {
|
// One minute timeout for integration tests
|
||||||
describe('repos', () => {
|
jasmine.getEnv().DEFAULT_TIMEOUT_INTERVAL = 60000;
|
||||||
it('returns set of repos', () => {
|
|
||||||
|
|
||||||
|
let _ = require('underscore');
|
||||||
|
let regHubUtil = require('../src/utils/RegHubUtil');
|
||||||
|
let hubUtil = require('../src/utils/hubUtil');
|
||||||
|
let Promise = require('bluebird');
|
||||||
|
|
||||||
|
describe('RegHubUtil Integration Tests', () => {
|
||||||
|
describe('with login', () => {
|
||||||
|
pit('lists private repos', () => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
hubUtil.login(process.env.INTEGRATION_USER, process.env.INTEGRATION_PASSWORD, () => {
|
||||||
|
regHubUtil.repos((error, repos) => {
|
||||||
|
expect(_.findWhere(repos, {name: 'test_private', is_private: true})).toBeTruthy();
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
pit('lists tags for a private repo', () => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
hubUtil.login(process.env.INTEGRATION_USER, process.env.INTEGRATION_PASSWORD, () => {
|
||||||
|
regHubUtil.tags(`${process.env.INTEGRATION_USER}/test_private`, (error, tags) => {
|
||||||
|
expect(error).toBeFalsy();
|
||||||
|
expect(tags).toEqual(['latest']);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('public repos', () => {
|
||||||
|
pit('lists repos', () => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
hubUtil.login(process.env.INTEGRATION_USER, process.env.INTEGRATION_PASSWORD, () => {
|
||||||
|
regHubUtil.repos((error, repos) => {
|
||||||
|
expect(_.findWhere(repos, {name: 'test'})).toBeTruthy();
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
pit('lists tags for a repo', () => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
hubUtil.login(process.env.INTEGRATION_USER, process.env.INTEGRATION_PASSWORD, () => {
|
||||||
|
regHubUtil.tags(`${process.env.INTEGRATION_USER}/test`, (error, tags) => {
|
||||||
|
expect(error).toBeFalsy();
|
||||||
|
expect(tags).toEqual(['latest']);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ class RepositoryServerActions {
|
||||||
'reposLoading',
|
'reposLoading',
|
||||||
'resultsUpdated',
|
'resultsUpdated',
|
||||||
'recommendedUpdated',
|
'recommendedUpdated',
|
||||||
'reposUpdated'
|
'reposUpdated',
|
||||||
|
'error'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ import alt from '../alt';
|
||||||
class TagServerActions {
|
class TagServerActions {
|
||||||
constructor () {
|
constructor () {
|
||||||
this.generateActions(
|
this.generateActions(
|
||||||
'tagsUpdated'
|
'tagsUpdated',
|
||||||
|
'error'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,11 @@ class TagStore {
|
||||||
this.tags = {};
|
this.tags = {};
|
||||||
this.emitChange();
|
this.emitChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error ({repo}) {
|
||||||
|
this.loading[repo] = false;
|
||||||
|
this.emitChange();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default alt.createStore(TagStore);
|
export default alt.createStore(TagStore);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ var _ = require('underscore');
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
var accountServerActions = require('../actions/AccountServerActions');
|
var accountServerActions = require('../actions/AccountServerActions');
|
||||||
|
|
||||||
|
let HUB2_ENDPOINT = process.env.HUB2_ENDPOINT || 'https://hub.docker.com/v2';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init: function () {
|
init: function () {
|
||||||
accountServerActions.prompted({prompted: localStorage.getItem('auth.prompted')});
|
accountServerActions.prompted({prompted: localStorage.getItem('auth.prompted')});
|
||||||
|
|
@ -95,10 +97,11 @@ module.exports = {
|
||||||
localStorage.removeItem('auth.config');
|
localStorage.removeItem('auth.config');
|
||||||
},
|
},
|
||||||
|
|
||||||
login: function (username, password) {
|
login: function (username, password, callback) {
|
||||||
this.auth(username, password, (error, response, body) => {
|
this.auth(username, password, (error, response, body) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
accountServerActions.errors({errors: {detail: error.message}});
|
accountServerActions.errors({errors: {detail: error.message}});
|
||||||
|
callback(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,9 +115,11 @@ module.exports = {
|
||||||
localStorage.setItem('auth.config', new Buffer(username + ':' + password).toString('base64'));
|
localStorage.setItem('auth.config', new Buffer(username + ':' + password).toString('base64'));
|
||||||
accountServerActions.loggedin({username, verified: true});
|
accountServerActions.loggedin({username, verified: true});
|
||||||
accountServerActions.prompted({prompted: true});
|
accountServerActions.prompted({prompted: true});
|
||||||
|
if (callback) { callback(); }
|
||||||
require('./RegHubUtil').repos();
|
require('./RegHubUtil').repos();
|
||||||
} else {
|
} else {
|
||||||
accountServerActions.errors({errors: {detail: 'Did not receive login token.'}});
|
accountServerActions.errors({errors: {detail: 'Did not receive login token.'}});
|
||||||
|
if (callback) { callback(new Error('Did not receive login token.')); }
|
||||||
}
|
}
|
||||||
} else if (response.statusCode === 401) {
|
} else if (response.statusCode === 401) {
|
||||||
if (data && data.detail && data.detail.indexOf('Account not active yet') !== -1) {
|
if (data && data.detail && data.detail.indexOf('Account not active yet') !== -1) {
|
||||||
|
|
@ -123,15 +128,17 @@ module.exports = {
|
||||||
localStorage.setItem('auth.username', username);
|
localStorage.setItem('auth.username', username);
|
||||||
localStorage.setItem('auth.verified', false);
|
localStorage.setItem('auth.verified', false);
|
||||||
localStorage.setItem('auth.config', new Buffer(username + ':' + password).toString('base64'));
|
localStorage.setItem('auth.config', new Buffer(username + ':' + password).toString('base64'));
|
||||||
|
if (callback) { callback(); }
|
||||||
} else {
|
} else {
|
||||||
accountServerActions.errors({errors: data});
|
accountServerActions.errors({errors: data});
|
||||||
|
if (callback) { callback(new Error(data.detail)); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
auth: function (username, password, callback) {
|
auth: function (username, password, callback) {
|
||||||
request.post('https://hub.docker.com/v2/users/login/', {form: {username, password}}, (error, response, body) => {
|
request.post(`${HUB2_ENDPOINT}/users/login/`, {form: {username, password}}, (error, response, body) => {
|
||||||
callback(error, response, body);
|
callback(error, response, body);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
@ -153,7 +160,7 @@ module.exports = {
|
||||||
|
|
||||||
// Signs up and places a token under ~/.dockercfg and saves a jwt to localstore
|
// Signs up and places a token under ~/.dockercfg and saves a jwt to localstore
|
||||||
signup: function (username, password, email, subscribe) {
|
signup: function (username, password, email, subscribe) {
|
||||||
request.post('https://hub.docker.com/v2/users/signup/', {
|
request.post('${HUB2_ENDPOINT}/users/signup/', {
|
||||||
form: {
|
form: {
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@ var util = require('../utils/Util');
|
||||||
var hubUtil = require('../utils/HubUtil');
|
var hubUtil = require('../utils/HubUtil');
|
||||||
var repositoryServerActions = require('../actions/RepositoryServerActions');
|
var repositoryServerActions = require('../actions/RepositoryServerActions');
|
||||||
var tagServerActions = require('../actions/TagServerActions');
|
var tagServerActions = require('../actions/TagServerActions');
|
||||||
|
var Promise = require('bluebird');
|
||||||
|
|
||||||
|
let REGHUB2_ENDPOINT = process.env.REGHUB2_ENDPOINT || 'https://registry.hub.docker.com/v2';
|
||||||
let searchReq = null;
|
let searchReq = null;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
@ -38,7 +40,7 @@ module.exports = {
|
||||||
qs: {q: query, page}
|
qs: {q: query, page}
|
||||||
}, (error, response, body) => {
|
}, (error, response, body) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
repositoryServerActions.searchError({error});
|
repositoryServerActions.error({error});
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = JSON.parse(body);
|
let data = JSON.parse(body);
|
||||||
|
|
@ -66,7 +68,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
request.get({
|
request.get({
|
||||||
url: `https://registry.hub.docker.com/v2/repositories/${name}`,
|
url: `${REGHUB2_ENDPOINT}/repositories/${name}`,
|
||||||
}, (error, response, body) => {
|
}, (error, response, body) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
repositoryServerActions.error({error});
|
repositoryServerActions.error({error});
|
||||||
|
|
@ -86,28 +88,38 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
tags: function (repo) {
|
tags: function (repo, callback) {
|
||||||
hubUtil.request({
|
hubUtil.request({
|
||||||
url: `https://registry.hub.docker.com/v2/repositories/${repo}/tags`
|
url: `${REGHUB2_ENDPOINT}/repositories/${repo}/tags`
|
||||||
}, (error, response, body) => {
|
}, (error, response, body) => {
|
||||||
if (response.statusCode === 200) {
|
if (response.statusCode === 200) {
|
||||||
let data = JSON.parse(body);
|
let data = JSON.parse(body);
|
||||||
tagServerActions.tagsUpdated({repo, tags: data.tags});
|
tagServerActions.tagsUpdated({repo, tags: data.tags});
|
||||||
} else if (response.statusCude === 401) {
|
if (callback) { callback(null, data.tags); }
|
||||||
return;
|
} else if (error || response.statusCode === 401) {
|
||||||
|
repositoryServerActions.error({repo});
|
||||||
|
if (callback) { callback(new Error('Failed to fetch repos')); }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns the base64 encoded index token or null if no token exists
|
// Returns the base64 encoded index token or null if no token exists
|
||||||
repos: function () {
|
repos: function (callback) {
|
||||||
repositoryServerActions.reposLoading({repos: []});
|
repositoryServerActions.reposLoading({repos: []});
|
||||||
|
|
||||||
hubUtil.request({
|
hubUtil.request({
|
||||||
url: 'https://registry.hub.docker.com/v2/namespaces/',
|
url: `${REGHUB2_ENDPOINT}/namespaces/`,
|
||||||
}, (error, response, body) => {
|
}, (error, response, body) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
repositoryServerActions.reposError({error});
|
repositoryServerActions.error({error});
|
||||||
|
if (callback) { callback(error); }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.statusCode !== 200) {
|
||||||
|
let generalError = new Error('Failed to fetch repos');
|
||||||
|
repositoryServerActions.error({error: generalError});
|
||||||
|
if (callback) { callback({error: generalError}); }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,10 +127,11 @@ module.exports = {
|
||||||
let namespaces = data.namespaces;
|
let namespaces = data.namespaces;
|
||||||
async.map(namespaces, (namespace, cb) => {
|
async.map(namespaces, (namespace, cb) => {
|
||||||
hubUtil.request({
|
hubUtil.request({
|
||||||
url: `https://registry.hub.docker.com/v2/repositories/${namespace}`
|
url: `${REGHUB2_ENDPOINT}/repositories/${namespace}`
|
||||||
}, (error, response, body) => {
|
}, (error, response, body) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
repositoryServerActions.reposError({error});
|
repositoryServerActions.error({error});
|
||||||
|
if (callback) { callback(error); }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,6 +139,12 @@ module.exports = {
|
||||||
cb(null, data.results);
|
cb(null, data.results);
|
||||||
});
|
});
|
||||||
}, (error, lists) => {
|
}, (error, lists) => {
|
||||||
|
if (error) {
|
||||||
|
repositoryServerActions.error({error});
|
||||||
|
if (callback) { callback(error); }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let repos = [];
|
let repos = [];
|
||||||
for (let list of lists) {
|
for (let list of lists) {
|
||||||
repos = repos.concat(list);
|
repos = repos.concat(list);
|
||||||
|
|
@ -136,6 +155,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
|
|
||||||
repositoryServerActions.reposUpdated({repos});
|
repositoryServerActions.reposUpdated({repos});
|
||||||
|
if (callback) { callback(null, repos); }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
var mock = (function() {
|
var mock = (function() {
|
||||||
var store = {};
|
var store = {};
|
||||||
return {
|
return {
|
||||||
getItem: function(key) {
|
getItem: function(key) {
|
||||||
return store[key];
|
return store[key];
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue