Auth module refactoring in order to be reusable (#4940)
* Auth module refactoring in order to be reusable * Ensure cache controller is properly forwarded from helpers * Nits
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
describe('Auth', () => {
|
||||
const Auth = require('../lib/Auth.js').Auth;
|
||||
|
||||
const { Auth, getAuthForSessionToken } = require('../lib/Auth.js');
|
||||
const Config = require('../lib/Config');
|
||||
describe('getUserRoles', () => {
|
||||
let auth;
|
||||
let config;
|
||||
@@ -90,4 +90,33 @@ describe('Auth', () => {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should load auth without a config', async () => {
|
||||
const user = new Parse.User();
|
||||
await user.signUp({
|
||||
username: 'hello',
|
||||
password: 'password'
|
||||
});
|
||||
expect(user.getSessionToken()).not.toBeUndefined();
|
||||
const userAuth = await getAuthForSessionToken({
|
||||
sessionToken: user.getSessionToken()
|
||||
});
|
||||
expect(userAuth.user instanceof Parse.User).toBe(true);
|
||||
expect(userAuth.user.id).toBe(user.id);
|
||||
});
|
||||
|
||||
it('should load auth with a config', async () => {
|
||||
const user = new Parse.User();
|
||||
await user.signUp({
|
||||
username: 'hello',
|
||||
password: 'password'
|
||||
});
|
||||
expect(user.getSessionToken()).not.toBeUndefined();
|
||||
const userAuth = await getAuthForSessionToken({
|
||||
sessionToken: user.getSessionToken(),
|
||||
config: Config.get('test'),
|
||||
});
|
||||
expect(userAuth.user instanceof Parse.User).toBe(true);
|
||||
expect(userAuth.user.id).toBe(user.id);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -832,10 +832,7 @@ describe('Cloud Code', () => {
|
||||
expect(body.result).toEqual('second data');
|
||||
done();
|
||||
})
|
||||
.catch(error => {
|
||||
fail(JSON.stringify(error));
|
||||
done();
|
||||
});
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('trivial beforeSave should not affect fetched pointers (regression test for #1238)', done => {
|
||||
|
||||
@@ -142,7 +142,7 @@ describe('Parse Role testing', () => {
|
||||
|
||||
});
|
||||
|
||||
it("should recursively load roles", (done) => {
|
||||
function testLoadRoles(config, done) {
|
||||
const rolesNames = ["FooRole", "BarRole", "BazRole"];
|
||||
const roleIds = {};
|
||||
createTestUser().then((user) => {
|
||||
@@ -159,7 +159,7 @@ describe('Parse Role testing', () => {
|
||||
return createRole(rolesNames[2], anotherRole, null);
|
||||
}).then((lastRole) => {
|
||||
roleIds[lastRole.get("name")] = lastRole.id;
|
||||
const auth = new Auth({ config: Config.get("test"), isMaster: true, user: user });
|
||||
const auth = new Auth({ config, isMaster: true, user: user });
|
||||
return auth._loadRoles();
|
||||
})
|
||||
}).then((roles) => {
|
||||
@@ -172,6 +172,14 @@ describe('Parse Role testing', () => {
|
||||
fail("should succeed")
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
it("should recursively load roles", (done) => {
|
||||
testLoadRoles(Config.get('test'), done);
|
||||
});
|
||||
|
||||
it("should recursively load roles without config", (done) => {
|
||||
testLoadRoles(undefined, done);
|
||||
});
|
||||
|
||||
it("_Role object should not save without name.", (done) => {
|
||||
|
||||
Reference in New Issue
Block a user