diff --git a/src/appstore.js b/src/appstore.js index 28f21513b..4183c52c4 100644 --- a/src/appstore.js +++ b/src/appstore.js @@ -269,7 +269,7 @@ async function registerCloudron3(domain, version) { await settings.set(settings.CLOUDRON_ID_KEY, response.body.id); await settings.set(settings.APPSTORE_API_TOKEN_KEY, response.body.token); - debug(`registerCloudron: Cloudron registered with id ${response.body.id}`); + debug(`registerCloudron3: Cloudron registered with id ${response.body.id}`); } async function registerCloudron(data) { diff --git a/src/provision.js b/src/provision.js index a077afafb..cdccc7c09 100644 --- a/src/provision.js +++ b/src/provision.js @@ -7,7 +7,8 @@ exports = module.exports = { getStatus, }; -const assert = require('assert'), +const appstore = require('./appstore.js'), + assert = require('assert'), backups = require('./backups.js'), backuptask = require('./backuptask.js'), BoxError = require('./boxerror.js'), @@ -147,6 +148,9 @@ async function activate(username, password, email, displayName, ip, auditSource) debug(`activate: user: ${username} email:${email}`); + const dashboardLocation = await dashboard.getLocation(); + await appstore.registerCloudron3(dashboardLocation.domain, constants.VERSION); + const [error, ownerId] = await safe(users.createOwner(email, username, password, displayName, auditSource)); if (error && error.reason === BoxError.ALREADY_EXISTS) throw new BoxError(BoxError.CONFLICT, 'Already activated'); if (error) throw error; diff --git a/src/routes/provision.js b/src/routes/provision.js index 5594d014f..fa2619c31 100644 --- a/src/routes/provision.js +++ b/src/routes/provision.js @@ -12,11 +12,9 @@ exports = module.exports = { detectIP }; -const appstore = require('../appstore.js'), - assert = require('assert'), +const assert = require('assert'), AuditSource = require('../auditsource.js'), BoxError = require('../boxerror.js'), - dashboard = require('../dashboard.js'), HttpError = require('connect-lastmile').HttpError, HttpSuccess = require('connect-lastmile').HttpSuccess, network = require('../network.js'), @@ -113,16 +111,7 @@ async function activate(req, res, next) { const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress; - let [error, result] = await safe(dashboard.getConfig()); - if (error) return next(new HttpError(500, 'internal error')); - - const version = result.version; - const domain = result.adminDomain; - - [error, result] = await safe(appstore.registerCloudron3(domain, version)); - if (error) return next(new HttpError(409, 'appstore not reachable')); - - [error, result] = await safe(provision.activate(username, password, email, displayName, ip, AuditSource.fromRequest(req))); + const [error, result] = await safe(provision.activate(username, password, email, displayName, ip, AuditSource.fromRequest(req))); if (error) return next(BoxError.toHttpError(error)); next(new HttpSuccess(201, result)); diff --git a/src/routes/test/appstore-test.js b/src/routes/test/appstore-test.js index 8cc5efb1a..5d39a176a 100644 --- a/src/routes/test/appstore-test.js +++ b/src/routes/test/appstore-test.js @@ -94,7 +94,7 @@ describe('Appstore Cloudron Registration API - existing user', function () { .reply(200, { userId: 'userId', accessToken: 'SECRET_TOKEN' }); const scope3 = nock(await appstore.getApiServerOrigin()) - .post('/api/v1/register_cloudron', (body) => !!body.domain && body.accessToken === 'SECRET_TOKEN') + .post('/api/v1/register_cloudron', (body) => typeof body.domain === 'string' && typeof body.version === 'string') .reply(201, { cloudronId: 'cid', cloudronToken: 'CLOUDRON_TOKEN' }); const response = await superagent.post(`${serverUrl}/api/v1/appstore/register_cloudron`) diff --git a/src/routes/test/common.js b/src/routes/test/common.js index 067e5a9b3..41e7f4493 100644 --- a/src/routes/test/common.js +++ b/src/routes/test/common.js @@ -8,6 +8,7 @@ const apps = require('../../apps.js'), expect = require('expect.js'), fs = require('fs'), mailer = require('../../mailer.js'), + nock = require('nock'), oidc = require('../../oidc.js'), safe = require('safetydance'), server = require('../../server.js'), @@ -135,12 +136,16 @@ async function setup() { await timers.setTimeout(2000); // create owner + const scope1 = nock(await appstore.getApiServerOrigin()) + .post('/api/v1/register_cloudron3', (body) => typeof body.domain === 'string' && typeof body.version === 'string') + .reply(201, { id: 'cid', token: 'CLOUDRON_TOKEN' }); response = await superagent.post(`${serverUrl}/api/v1/provision/activate`) .query({ setupToken: 'somesetuptoken' }) .send({ username: owner.username, password: owner.password, email: owner.email }); expect(response.status).to.eql(201); owner.token = response.body.token; owner.id = response.body.userId; + expect(scope1.isDone()).to.be.ok(); // create an admin response = await superagent.post(`${serverUrl}/api/v1/users`) @@ -191,7 +196,6 @@ async function checkMails(number) { async function waitForTask(taskId) { debug(`Waiting for task: ${taskId}`); - // eslint-disable-next-line no-constant-condition for (let i = 0; i < 30; i++) { const result = await tasks.get(taskId); expect(result).to.not.be(null);