Support admin login for cloudron deletion
This commit is contained in:
parent
f62da202ae
commit
3ad8f97c0e
14
appstore.js
14
appstore.js
@ -16,6 +16,11 @@ function AppStore(origin) {
|
|||||||
password: null,
|
password: null,
|
||||||
accessToken: null
|
accessToken: null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this._adminCredentials = {
|
||||||
|
password: null,
|
||||||
|
accessToken: null
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
AppStore.prototype.getAccessToken = function (user) {
|
AppStore.prototype.getAccessToken = function (user) {
|
||||||
@ -33,6 +38,10 @@ AppStore.prototype.setCredentials = function (password, accessToken) {
|
|||||||
this._credentials = { password: password, accessToken: accessToken };
|
this._credentials = { password: password, accessToken: accessToken };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AppStore.prototype.setAdminCredentials = function (password, accessToken) {
|
||||||
|
this._adminCredentials = { password: password, accessToken: accessToken };
|
||||||
|
};
|
||||||
|
|
||||||
AppStore.prototype.getCloudrons = function () {
|
AppStore.prototype.getCloudrons = function () {
|
||||||
var res = request.get(this._origin + '/api/v1/cloudrons').query({ accessToken: this._credentials.accessToken, page: 1, per_page: 50 }).end();
|
var res = request.get(this._origin + '/api/v1/cloudrons').query({ accessToken: this._credentials.accessToken, page: 1, per_page: 50 }).end();
|
||||||
return res.body.boxes;
|
return res.body.boxes;
|
||||||
@ -87,11 +96,12 @@ AppStore.prototype.createCloudron = function (box) {
|
|||||||
return res.body.box;
|
return res.body.box;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Only allowed by admins
|
||||||
AppStore.prototype.deleteCloudron = function (box) {
|
AppStore.prototype.deleteCloudron = function (box) {
|
||||||
var res = request.post(this._origin + '/api/v1/cloudrons/' + box.id)
|
var res = request.post(this._origin + '/api/v1/cloudrons/' + box.id)
|
||||||
.query({ accessToken: this._credentials.accessToken })
|
.query({ accessToken: this._adminCredentials.accessToken })
|
||||||
.set('X-HTTP-Method-Override', 'DELETE')
|
.set('X-HTTP-Method-Override', 'DELETE')
|
||||||
.send({ password: this._credentials.password })
|
.send({ password: this._adminCredentials.password })
|
||||||
.end();
|
.end();
|
||||||
common. verifyResponse(res, 'Could not delete cloudron');
|
common. verifyResponse(res, 'Could not delete cloudron');
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ exports = module.exports = {
|
|||||||
verifyResponse: verifyResponse,
|
verifyResponse: verifyResponse,
|
||||||
verifyResponse2: verifyResponse2,
|
verifyResponse2: verifyResponse2,
|
||||||
getOwner: getOwner,
|
getOwner: getOwner,
|
||||||
|
getAdmin: getAdmin,
|
||||||
stripeSecret: stripeSecret,
|
stripeSecret: stripeSecret,
|
||||||
stripUnreachable: stripUnreachable
|
stripUnreachable: stripUnreachable
|
||||||
};
|
};
|
||||||
@ -65,6 +66,14 @@ function getOwner() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAdmin() {
|
||||||
|
return {
|
||||||
|
username: process.env.APPSTORE_ADMIN_USERNAME || gEcosystem.env.APPSTORE_ADMIN_USERNAME,
|
||||||
|
password: process.env.APPSTORE_ADMIN_PASSWORD || gEcosystem.env.APPSTORE_ADMIN_PASSWORD,
|
||||||
|
email: process.env.APPSTORE_ADMIN_EMAIL || gEcosystem.env.APPSTORE_ADMIN_EMAIL
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function stripeSecret() {
|
function stripeSecret() {
|
||||||
return process.env.STRIPE_SECRET || gEcosystem.env.STRIPE_SECRET;
|
return process.env.STRIPE_SECRET || gEcosystem.env.STRIPE_SECRET;
|
||||||
}
|
}
|
||||||
|
@ -19,18 +19,22 @@ describe('Cleanup old cloudrons', function () {
|
|||||||
var appStore = new AppStore('https://api.staging.cloudron.io');
|
var appStore = new AppStore('https://api.staging.cloudron.io');
|
||||||
|
|
||||||
var owner = common.getOwner();
|
var owner = common.getOwner();
|
||||||
|
var admin = common.getAdmin();
|
||||||
var cloudrons;
|
var cloudrons;
|
||||||
|
|
||||||
it('can login to the store', function () {
|
it('can login to the store', function () {
|
||||||
var accessToken = appStore.getAccessToken(owner);
|
var accessToken = appStore.getAccessToken(owner);
|
||||||
appStore.setCredentials(owner.password, accessToken);
|
appStore.setCredentials(owner.password, accessToken);
|
||||||
|
|
||||||
|
var adminAccessToken = appStore.getAccessToken(admin);
|
||||||
|
appStore.setCredentials(admin.password, adminAccessToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can list cloudrons', function () {
|
it('can list cloudrons', function () {
|
||||||
cloudrons = appStore.getCloudrons();
|
cloudrons = appStore.getCloudrons();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can delete the cloudrons', function () {
|
it('admin can delete the cloudrons', function () {
|
||||||
for (var i = 0; i < cloudrons.length; i++) {
|
for (var i = 0; i < cloudrons.length; i++) {
|
||||||
appStore.deleteCloudron(cloudrons[i]);
|
appStore.deleteCloudron(cloudrons[i]);
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,15 @@ describe('Application flow test', function () {
|
|||||||
var appStore = new AppStore('https://api.staging.cloudron.io');
|
var appStore = new AppStore('https://api.staging.cloudron.io');
|
||||||
|
|
||||||
var owner = common.getOwner();
|
var owner = common.getOwner();
|
||||||
|
var admin = common.getAdmin();
|
||||||
var cloudron, appId, box;
|
var cloudron, appId, box;
|
||||||
|
|
||||||
it('can login to the store', function () {
|
it('can login to the store', function () {
|
||||||
var accessToken = appStore.getAccessToken(owner);
|
var accessToken = appStore.getAccessToken(owner);
|
||||||
appStore.setCredentials(owner.password, accessToken);
|
appStore.setCredentials(owner.password, accessToken);
|
||||||
|
|
||||||
|
var adminAccessToken = appStore.getAccessToken(admin);
|
||||||
|
appStore.setCredentials(admin.password, adminAccessToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can create a cloudron', function () {
|
it('can create a cloudron', function () {
|
||||||
|
@ -26,11 +26,15 @@ describe('Cloudron backup testing', function () {
|
|||||||
var appStore = new AppStore('https://api.staging.cloudron.io');
|
var appStore = new AppStore('https://api.staging.cloudron.io');
|
||||||
|
|
||||||
var owner = common.getOwner();
|
var owner = common.getOwner();
|
||||||
|
var admin = common.getAdmin();
|
||||||
var cloudron, appId, box, backupInfo;
|
var cloudron, appId, box, backupInfo;
|
||||||
|
|
||||||
it('can login to the store', function () {
|
it('can login to the store', function () {
|
||||||
var accessToken = appStore.getAccessToken(owner);
|
var accessToken = appStore.getAccessToken(owner);
|
||||||
appStore.setCredentials(owner.password, accessToken);
|
appStore.setCredentials(owner.password, accessToken);
|
||||||
|
|
||||||
|
var adminAccessToken = appStore.getAccessToken(admin);
|
||||||
|
appStore.setCredentials(admin.password, adminAccessToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can create a cloudron', function () {
|
it('can create a cloudron', function () {
|
||||||
|
@ -28,6 +28,7 @@ describe('Cloudron update testing', function () {
|
|||||||
var appStore = new AppStore('https://api.staging.cloudron.io');
|
var appStore = new AppStore('https://api.staging.cloudron.io');
|
||||||
|
|
||||||
var owner = common.getOwner();
|
var owner = common.getOwner();
|
||||||
|
var admin = common.getAdmin();
|
||||||
var res, fromVersion, toVersion, cloudron, appId, box, nextVersion;
|
var res, fromVersion, toVersion, cloudron, appId, box, nextVersion;
|
||||||
|
|
||||||
before('can release a fake version to staging', function () {
|
before('can release a fake version to staging', function () {
|
||||||
@ -52,6 +53,9 @@ describe('Cloudron update testing', function () {
|
|||||||
it('can login to the store', function () {
|
it('can login to the store', function () {
|
||||||
var accessToken = appStore.getAccessToken(owner);
|
var accessToken = appStore.getAccessToken(owner);
|
||||||
appStore.setCredentials(owner.password, accessToken);
|
appStore.setCredentials(owner.password, accessToken);
|
||||||
|
|
||||||
|
var adminAccessToken = appStore.getAccessToken(admin);
|
||||||
|
appStore.setCredentials(admin.password, adminAccessToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can create a cloudron', function () {
|
it('can create a cloudron', function () {
|
||||||
|
@ -23,11 +23,15 @@ describe('Cloudron user creation testing', function () {
|
|||||||
var appStore = new AppStore('https://api.staging.cloudron.io');
|
var appStore = new AppStore('https://api.staging.cloudron.io');
|
||||||
|
|
||||||
var owner = common.getOwner();
|
var owner = common.getOwner();
|
||||||
|
var admin = common.getAdmin();
|
||||||
var cloudron, box, newUser;
|
var cloudron, box, newUser;
|
||||||
|
|
||||||
it('can login to the store', function () {
|
it('can login to the store', function () {
|
||||||
var accessToken = appStore.getAccessToken(owner);
|
var accessToken = appStore.getAccessToken(owner);
|
||||||
appStore.setCredentials(owner.password, accessToken);
|
appStore.setCredentials(owner.password, accessToken);
|
||||||
|
|
||||||
|
var adminAccessToken = appStore.getAccessToken(admin);
|
||||||
|
appStore.setCredentials(admin.password, adminAccessToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can create a cloudron', function () {
|
it('can create a cloudron', function () {
|
||||||
|
@ -25,11 +25,15 @@ describe('Appstore new user flow', function () {
|
|||||||
var appStore = new AppStore('https://api.staging.cloudron.io');
|
var appStore = new AppStore('https://api.staging.cloudron.io');
|
||||||
|
|
||||||
var owner = common.getOwner();
|
var owner = common.getOwner();
|
||||||
|
var admin = common.getAdmin();
|
||||||
var cloudron, appId, box;
|
var cloudron, appId, box;
|
||||||
|
|
||||||
it('can login to the store', function () {
|
it('can login to the store', function () {
|
||||||
var accessToken = appStore.getAccessToken(owner);
|
var accessToken = appStore.getAccessToken(owner);
|
||||||
appStore.setCredentials(owner.password, accessToken);
|
appStore.setCredentials(owner.password, accessToken);
|
||||||
|
|
||||||
|
var adminAccessToken = appStore.getAccessToken(admin);
|
||||||
|
appStore.setCredentials(admin.password, adminAccessToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can get profile', function () {
|
it('can get profile', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user