1
0
Fork 0
mirror of synced 2024-06-26 18:10:51 +12:00

more session testing

This commit is contained in:
michael shanks 2019-06-14 23:03:01 +01:00
parent 354e0af4aa
commit ff98b4bf4d
3 changed files with 42 additions and 24 deletions

View file

@ -69,7 +69,8 @@ module.exports = (config, app) => {
})
.get("/:appname/api/users", async (ctx) => {
ctx.body = await ctx.instance.authApi.getUsers();
ctx.response.status = StatusCodes.OK;
})
.get("/:appname/api/accessLevels", async (ctx) => {

View file

@ -2,15 +2,6 @@ const statusCodes = require("../utilities/statusCodes");
module.exports = (app) => {
it("should return ok correct username and password supplied", async () => {
await app.post("/_master/api/authenticate", {
username: app.masterAuth.username,
password: app.masterAuth.password
})
.expect(statusCodes.OK);
});
it("should return unauthorized if username is incorrect", async () => {
await app.post("/_master/api/authenticate", {
username: "unknownuser",
@ -37,34 +28,55 @@ module.exports = (app) => {
});
it("should be able to create new user with authenticated cookie", async () => {
let ownerCookie;
it("should return ok correct username and password supplied", async () => {
const response = await app.post("/_master/api/authenticate", {
username: app.masterAuth.username,
password: app.masterAuth.password
});
const cookie = response.header['set-cookie'];
})
.expect(statusCodes.OK);
ownerCookie = response.header['set-cookie'];
});
const testUserName = "test_user";
const testPassword = "test_user_password";
it("should be able to create new user with authenticated cookie", async () => {
await app.post("/_master/api/createUser", {
user: {
name: "test_user",
name: testUserName,
accessLevels:["owner"],
enabled:true
},
password: "test_password"
password: testPassword
})
.set("cookie", cookie)
.set("cookie", ownerCookie)
.expect(statusCodes.OK);
const responseNewUser = await app.post("/_master/api/authenticate", {
username: "test_user",
password: "test_password"
});
const newUserCookie = responseNewUser.header['set-cookie'];
});
let newUserCookie;
it("should be able to authenticate with new user", async () => {
const responseNewUser = await app.post("/_master/api/authenticate", {
username: testUserName,
password: testPassword
})
.expect(statusCodes.OK);
newUserCookie = responseNewUser.header['set-cookie'];
expect(newUserCookie).toBeDefined();
expect(newUserCookie).not.toEqual(cookie);
expect(newUserCookie).not.toEqual(ownerCookie);
app.get("/_master/api/users/")
.set("cookie", newUserCookie)
.expect(statusCodes.OK);
});
};

View file

@ -33,6 +33,7 @@ module.exports = () => {
config,
server:() => server,
post: (url, body) => postRequest(server,url,body),
get: (url) => getRequest(server, url),
masterAuth: {
username: masterOwnerName,
password: masterOwnerPassword
@ -47,6 +48,10 @@ const postRequest = (server, url, body) =>
.send(body)
.set('Accept', 'application/json');
const getRequest = (server, url) =>
request(server)
.get(url)
.set('Accept', 'application/json');
const reInitialize = async () => {
try {