1
0
Fork 0
mirror of synced 2024-06-14 16:35:02 +12:00

streaming issue...

This commit is contained in:
michael shanks 2019-06-19 22:05:53 +01:00
parent d207d442bb
commit 923e6c6716
10 changed files with 91 additions and 15 deletions

@ -1 +1 @@
Subproject commit c255f52c811f02d77797c10f8ed1993a6bcc883c
Subproject commit 10009efb45995dc6a01ae941e8e539e2226a115c

View file

@ -61,11 +61,11 @@ const writableFileStream = root => async path =>
join(root, path), "utf8"
);
const getFolderContents = root => async path => {
const getFolderContents = root => async path =>
await readdir(
join(root, path)
);
};
const renameFile = root => async (oldPath, newPath) =>
await rename(

View file

@ -1 +1 @@
{"levels":[{"name":"owner","permissions":[{"type":"create record","nodeKey":"/applications/1-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}/users/8-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}/users/8-{id}"},{"type":"create record","nodeKey":"/applications/1-{id}/users/8-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}/users/8-{id}"},{"type":"create record","nodeKey":"/applications/1-{id}/instances/2-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}/instances/2-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}/instances/2-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}/instances/2-{id}"},{"type":"create record","nodeKey":"/applications/1-{id}/versions/3-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}/versions/3-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}/versions/3-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}/versions/3-{id}"},{"type":"read index","nodeKey":"/applications/1-{id}/allinstances"},{"type":"read index","nodeKey":"/applications/1-{id}/activeinstances"},{"type":"read index","nodeKey":"/applications/1-{id}/activeusers"},{"type":"read index","nodeKey":"/applications/1-{id}/all_versions"},{"type":"read index","nodeKey":"/applications/1-{id}/instances/2-{id}/users_on_this_instance"},{"type":"read index","nodeKey":"/applications/1-{id}/versions/3-{id}/instances_for_this_version"},{"type":"read index","nodeKey":"/applications/1-{id}/versions/3-{id}/instances_on_this_version"},{"type":"set user access levels"},{"type":"manage collection"},{"type":"list access levels"},{"type":"list users"},{"type":"write access levels"},{"type":"enable or disable user"},{"type":"create temporary access"},{"type":"set password"},{"type":"create user"},{"type":"write templates"},{"type":"create record","nodeKey":"/applications/1-{id}/sessions/16-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}/sessions/16-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}/sessions/16-{id}"},{"type":"create record","nodeKey":"/sessions/17-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}/sessions/16-{id}"},{"type":"update record","nodeKey":"/sessions/17-{id}"},{"type":"delete record","nodeKey":"/sessions/17-{id}"},{"type":"read record","nodeKey":"/sessions/17-{id}"}]}],"version":0}
{"levels":[{"name":"owner","permissions":[{"type":"create record","nodeKey":"/applications/1-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}"},{"type":"create record","nodeKey":"/applications/1-{id}/users/8-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}/users/8-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}/users/8-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}/users/8-{id}"},{"type":"create record","nodeKey":"/applications/1-{id}/instances/2-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}/instances/2-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}/instances/2-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}/instances/2-{id}"},{"type":"create record","nodeKey":"/applications/1-{id}/versions/3-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}/versions/3-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}/versions/3-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}/versions/3-{id}"},{"type":"create record","nodeKey":"/applications/1-{id}/sessions/16-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}/sessions/16-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}/sessions/16-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}/sessions/16-{id}"},{"type":"create record","nodeKey":"/sessions/17-{id}"},{"type":"update record","nodeKey":"/sessions/17-{id}"},{"type":"delete record","nodeKey":"/sessions/17-{id}"},{"type":"read record","nodeKey":"/sessions/17-{id}"},{"type":"read index","nodeKey":"/mastersessions_by_user"},{"type":"read index","nodeKey":"/all_applications"},{"type":"read index","nodeKey":"/applications/1-{id}/allinstances"},{"type":"read index","nodeKey":"/applications/1-{id}/sessions_by_user"},{"type":"read index","nodeKey":"/applications/1-{id}/user_name_lookup"},{"type":"read index","nodeKey":"/applications/1-{id}/all_versions"},{"type":"read index","nodeKey":"/applications/1-{id}/instances/2-{id}/users_on_this_instance"},{"type":"read index","nodeKey":"/applications/1-{id}/versions/3-{id}/instances_for_this_version"},{"type":"read index","nodeKey":"/applications/1-{id}/versions/3-{id}/instances_on_this_version"},{"type":"write templates"},{"type":"create user"},{"type":"set password"},{"type":"create temporary access"},{"type":"enable or disable user"},{"type":"write access levels"},{"type":"list users"},{"type":"list access levels"},{"type":"manage index"},{"type":"manage collection"},{"type":"set user access levels"}]}],"version":0}

File diff suppressed because one or more lines are too long

View file

@ -107,6 +107,11 @@ module.exports = (config, app) => {
.post("/:appname/api/disableUser", async (ctx) => {
await ctx.instance.authApi.disableUser(
ctx.request.body.username);
await ctx.master.removeSessionsForUser(
ctx.params.appname,
ctx.request.body.username
);
ctx.response.status = StatusCodes.OK;
})
.get("/:appname/api/users", async (ctx) => {

View file

@ -26,5 +26,8 @@
"jest": "^24.8.0",
"server-destroy": "^1.0.1",
"supertest": "^4.0.2"
},
"jest" : {
"testEnvironment": "node"
}
}

View file

@ -1,13 +1,9 @@
const app = require("./testApp")();
const authenticateMaster = require("./authenticate");
beforeAll(() => {
return app.start();
})
beforeAll(async () => await app.start())
afterAll(() => {
app.destroy();
})
afterAll(async () => await app.destroy())
describe("authenticateMaster", () => authenticateMaster(app));

View file

@ -78,5 +78,39 @@ module.exports = (app) => {
.expect(statusCodes.OK);
});
it("should not be able to perform requests when user is disabled", async () => {
await app.post("/_master/api/disableUser", {
username: testUserName
})
.set("cookie", ownerCookie)
.expect(statusCodes.OK);
await app.get("/_master/api/users/")
.set("cookie", newUserCookie)
.expect(statusCodes.FORBIDDEN);
await app.post("/_master/api/authenticate", {
username: testUserName,
password: testPassword
})
.expect(statusCodes.UNAUTHORIZED);
});
it("should not be able to re-authenticate when user is disabled", async () => {
await app.post("/_master/api/authenticate", {
username: testUserName,
password: testPassword
})
.expect(statusCodes.UNAUTHORIZED);
});
it("should be able with re-authenticate when user is enabled again", async () => {
await app.post("/_master/api/authenticate", {
username: testUserName,
password: testPassword
})
.expect(statusCodes.OK);
});
};

View file

@ -26,8 +26,12 @@ module.exports = () => {
return ({
start: async () => {
await reInitialize();
server = await app(config);
try {
await reInitialize();
server = await app(config);
} catch(e) {
console.log(e.message);
}
enableDestroy(server);
},
config,

View file

@ -79,6 +79,7 @@ module.exports = async (config) => {
const session = bb.recordApi.getNew("/sessions", "mastersession");
bb.recordApi.setCustomId(session, sessionId);
session.user_json = JSON.stringify(authUser);
session.username = username;
await bb.recordApi.save(session);
return session;
}
@ -106,6 +107,7 @@ module.exports = async (config) => {
bb.recordApi.setCustomId(session, sessionId);
session.user_json = JSON.stringify(authUser);
session.instanceDatastoreConfig = instance.datastoreconfig;
session.username = username;
await bb.recordApi.save(session);
return session;
};
@ -154,6 +156,38 @@ module.exports = async (config) => {
};
const removeSessionsForUser = async (appname, username) => {
if(isMaster(appname)) {
const sessions = await bb.indexApi.listItems(
"/mastersessions_by_user",
{
rangeStartParams:{name:username},
rangeEndParams:{name:username},
searchPhrase:`username:${username}`
}
);
for(let session of sessions) {
await bb.recordApi.delete(session.key);
}
}
else {
const app = await getApplication(appname);
const sessions = await bb.indexApi.listItems(
`/applications/${app.id}/sessions_by_user`,
{
rangeStartParams:{name:username},
rangeEndParams:{name:username},
searchPhrase:`username:${username}`
}
);
for(let session of sessions) {
await bb.recordApi.delete(session.key);
}
}
}
return ({
getApplication,
getSession,
@ -161,7 +195,7 @@ module.exports = async (config) => {
authenticate,
getInstanceApiForSession,
getFullAccessInstanceApiForUsername,
createTemporaryAccessCode
removeSessionsForUser
});
}