more session testing
This commit is contained in:
parent
354e0af4aa
commit
ff98b4bf4d
|
@ -69,7 +69,8 @@ module.exports = (config, app) => {
|
||||||
|
|
||||||
})
|
})
|
||||||
.get("/:appname/api/users", async (ctx) => {
|
.get("/:appname/api/users", async (ctx) => {
|
||||||
|
ctx.body = await ctx.instance.authApi.getUsers();
|
||||||
|
ctx.response.status = StatusCodes.OK;
|
||||||
})
|
})
|
||||||
.get("/:appname/api/accessLevels", async (ctx) => {
|
.get("/:appname/api/accessLevels", async (ctx) => {
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,6 @@ const statusCodes = require("../utilities/statusCodes");
|
||||||
|
|
||||||
module.exports = (app) => {
|
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 () => {
|
it("should return unauthorized if username is incorrect", async () => {
|
||||||
await app.post("/_master/api/authenticate", {
|
await app.post("/_master/api/authenticate", {
|
||||||
username: "unknownuser",
|
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", {
|
const response = await app.post("/_master/api/authenticate", {
|
||||||
username: app.masterAuth.username,
|
username: app.masterAuth.username,
|
||||||
password: app.masterAuth.password
|
password: app.masterAuth.password
|
||||||
});
|
})
|
||||||
|
.expect(statusCodes.OK);
|
||||||
|
|
||||||
const cookie = response.header['set-cookie'];
|
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", {
|
await app.post("/_master/api/createUser", {
|
||||||
user: {
|
user: {
|
||||||
name: "test_user",
|
name: testUserName,
|
||||||
accessLevels:["owner"],
|
accessLevels:["owner"],
|
||||||
enabled:true
|
enabled:true
|
||||||
|
|
||||||
},
|
},
|
||||||
password: "test_password"
|
password: testPassword
|
||||||
})
|
})
|
||||||
.set("cookie", cookie)
|
.set("cookie", ownerCookie)
|
||||||
.expect(statusCodes.OK);
|
.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).toBeDefined();
|
||||||
expect(newUserCookie).not.toEqual(cookie);
|
expect(newUserCookie).not.toEqual(ownerCookie);
|
||||||
|
|
||||||
|
app.get("/_master/api/users/")
|
||||||
|
.set("cookie", newUserCookie)
|
||||||
|
.expect(statusCodes.OK);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,6 +33,7 @@ module.exports = () => {
|
||||||
config,
|
config,
|
||||||
server:() => server,
|
server:() => server,
|
||||||
post: (url, body) => postRequest(server,url,body),
|
post: (url, body) => postRequest(server,url,body),
|
||||||
|
get: (url) => getRequest(server, url),
|
||||||
masterAuth: {
|
masterAuth: {
|
||||||
username: masterOwnerName,
|
username: masterOwnerName,
|
||||||
password: masterOwnerPassword
|
password: masterOwnerPassword
|
||||||
|
@ -47,6 +48,10 @@ const postRequest = (server, url, body) =>
|
||||||
.send(body)
|
.send(body)
|
||||||
.set('Accept', 'application/json');
|
.set('Accept', 'application/json');
|
||||||
|
|
||||||
|
const getRequest = (server, url) =>
|
||||||
|
request(server)
|
||||||
|
.get(url)
|
||||||
|
.set('Accept', 'application/json');
|
||||||
|
|
||||||
const reInitialize = async () => {
|
const reInitialize = async () => {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue