smc-hub
Version:
CoCalc: Backend webserver component
97 lines (89 loc) • 2.88 kB
JavaScript
// Generated by CoffeeScript 2.5.1
(function() {
//########################################################################
// This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
// License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
//########################################################################
var api, expect, misc, setup, teardown;
api = require('./apitest');
({setup, teardown} = api);
misc = require('smc-util/misc');
expect = require('expect');
describe('tests creating an auth token via the api -- ', function() {
var account_id2, auth_token;
before(setup);
after(teardown);
account_id2 = void 0;
it("uses api call to create a second account", function(done) {
this.timeout(10000);
return api.call({
event: 'create_account',
body: {
first_name: "Sage2",
last_name: "CoCalc2",
email_address: "cocalc+2@sagemath.com",
password: "1234qwerty",
agreed_to_terms: true
},
cb: function(err, resp) {
expect(resp != null ? resp.event : void 0).toBe('account_created');
expect(misc.is_valid_uuid_string(resp != null ? resp.account_id : void 0)).toBe(true);
account_id2 = resp != null ? resp.account_id : void 0;
return done(err);
}
});
});
auth_token = void 0;
it("obtains an auth token for the second account", function(done) {
this.timeout(10000);
return api.call({
event: 'user_auth',
body: {
account_id: account_id2,
password: "1234qwerty"
},
cb: function(err, resp) {
if (err) {
done(err);
return;
}
expect(resp.event).toBe('user_auth_token');
expect(resp.auth_token.length).toBe(24);
auth_token = resp.auth_token;
return done();
}
});
});
it("check in the database that the token would work", function(done) {
this.timeout(10000);
return api.db.get_auth_token_account_id({
auth_token: auth_token,
cb: function(err, account_id) {
if (err) {
return done(err);
} else {
expect(account_id).toBe(account_id2);
return done();
}
}
});
});
return it("check that a wrong token does not work", function(done) {
var fake_token;
fake_token = '12341234123';
this.timeout(10000);
return api.db.get_auth_token_account_id({
auth_token: fake_token,
cb: function(err, account_id) {
if (err) {
return done(err);
} else {
expect(account_id).toBe(void 0);
return done();
}
}
});
});
});
}).call(this);
//# sourceMappingURL=auth-token.js.map