Setting the appstore config also deals with appstore registration

- First time it registers the cloudron
- Resetting the account will verify that the Cloudron belongs to this user
- If cloudronId is invalid/unknown we reregister
This commit is contained in:
Johannes Zellner
2016-08-01 15:10:45 +02:00
parent d5644ae3f1
commit 1f1237e785
3 changed files with 166 additions and 6 deletions

View File

@@ -372,5 +372,112 @@ describe('Settings API', function () {
});
});
});
});
describe('appstore_config', function () {
it('get appstore_config fails', function (done) {
superagent.get(SERVER_URL + '/api/v1/settings/appstore_config')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body).to.eql({});
done();
});
});
it('cannot set without data', function (done) {
superagent.post(SERVER_URL + '/api/v1/settings/appstore_config')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
done();
});
});
it('set fails with wrong appstore token', function (done) {
var scope = nock(config.apiServerOrigin()).post('/api/v1/users/nebulon/cloudrons?accessToken=sometoken').reply(401);
superagent.post(SERVER_URL + '/api/v1/settings/appstore_config')
.query({ access_token: token })
.send({ userId: 'nebulon', token: 'sometoken' })
.end(function (err, res) {
expect(scope.isDone()).to.be.ok();
expect(res.statusCode).to.equal(406);
expect(res.body.message).to.equal('invalid appstore token');
done();
});
});
it('set succeeds for unknown cloudron', function (done) {
var scope = nock(config.apiServerOrigin()).post('/api/v1/users/nebulon/cloudrons?accessToken=sometoken').reply(201, { cloudron: { id: 'cloudron0' }});
superagent.post(SERVER_URL + '/api/v1/settings/appstore_config')
.query({ access_token: token })
.send({ userId: 'nebulon', token: 'sometoken' })
.end(function (err, res) {
expect(scope.isDone()).to.be.ok();
expect(res.statusCode).to.equal(202);
expect(res.body).to.eql({ userId: 'nebulon', token: 'sometoken', cloudronId: 'cloudron0' });
done();
});
});
it('set fails with wrong appstore user', function (done) {
var scope = nock(config.apiServerOrigin()).get('/api/v1/users/nebulon/cloudrons/cloudron0?accessToken=sometoken').reply(403);
superagent.post(SERVER_URL + '/api/v1/settings/appstore_config')
.query({ access_token: token })
.send({ userId: 'nebulon', token: 'sometoken' })
.end(function (err, res) {
expect(scope.isDone()).to.be.ok();
expect(res.statusCode).to.equal(406);
expect(res.body.message).to.equal('wrong user');
done();
});
});
it('get succeeds', function (done) {
superagent.get(SERVER_URL + '/api/v1/settings/appstore_config')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body).to.eql({ userId: 'nebulon', token: 'sometoken', cloudronId: 'cloudron0' });
done();
});
});
it('set succeeds with cloudronId', function (done) {
var scope = nock(config.apiServerOrigin()).get('/api/v1/users/nebulon/cloudrons/cloudron0?accessToken=someothertoken').reply(200, { cloudron: { id: 'cloudron0' }});
superagent.post(SERVER_URL + '/api/v1/settings/appstore_config')
.query({ access_token: token })
.send({ userId: 'nebulon', token: 'someothertoken' })
.end(function (err, res) {
expect(scope.isDone()).to.be.ok();
expect(res.statusCode).to.equal(202);
expect(res.body).to.eql({ userId: 'nebulon', token: 'someothertoken', cloudronId: 'cloudron0' });
done();
});
});
it('set succeeds with cloudronId but unkown one (reregister)', function (done) {
var scope0 = nock(config.apiServerOrigin()).get('/api/v1/users/nebulon/cloudrons/cloudron0?accessToken=someothertoken').reply(404);
var scope1 = nock(config.apiServerOrigin()).post('/api/v1/users/nebulon/cloudrons?accessToken=someothertoken').reply(201, { cloudron: { id: 'cloudron1' }});
superagent.post(SERVER_URL + '/api/v1/settings/appstore_config')
.query({ access_token: token })
.send({ userId: 'nebulon', token: 'someothertoken' })
.end(function (err, res) {
expect(scope0.isDone()).to.be.ok();
expect(scope1.isDone()).to.be.ok();
expect(res.statusCode).to.equal(202);
expect(res.body).to.eql({ userId: 'nebulon', token: 'someothertoken', cloudronId: 'cloudron1' });
done();
});
});
});
});