mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
fixing backend tests
This commit is contained in:
parent
d07fa645c4
commit
a7d9bc81c5
@ -8,6 +8,7 @@ import {Config} from "../../../common/config/private/Config";
|
|||||||
export class AuthenticationMWs {
|
export class AuthenticationMWs {
|
||||||
|
|
||||||
private static async getSharingUser(req: Request) {
|
private static async getSharingUser(req: Request) {
|
||||||
|
console.log(req);
|
||||||
if (Config.Client.Sharing.enabled === true &&
|
if (Config.Client.Sharing.enabled === true &&
|
||||||
Config.Client.Sharing.passwordProtected === false &&
|
Config.Client.Sharing.passwordProtected === false &&
|
||||||
(!!req.query.sk || !!req.params.sharingKey)) {
|
(!!req.query.sk || !!req.params.sharingKey)) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {expect} from "chai";
|
import {expect} from "chai";
|
||||||
import {AuthenticationMWs} from "../../../../../backend/middlewares/user/AuthenticationMWs";
|
import {AuthenticationMWs} from "../../../../../backend/middlewares/user/AuthenticationMWs";
|
||||||
import {Error, ErrorCodes} from "../../../../../common/entities/Error";
|
import {Error, ErrorCodes} from "../../../../../common/entities/Error";
|
||||||
import {UserRoles} from "../../../../../common/entities/UserDTO";
|
import {UserDTO, UserRoles} from "../../../../../common/entities/UserDTO";
|
||||||
import {ObjectManagerRepository} from "../../../../../backend/model/ObjectManagerRepository";
|
import {ObjectManagerRepository} from "../../../../../backend/model/ObjectManagerRepository";
|
||||||
import {UserManager} from "../../../../../backend/model/memory/UserManager";
|
import {UserManager} from "../../../../../backend/model/memory/UserManager";
|
||||||
import {Config} from "../../../../../common/config/private/Config";
|
import {Config} from "../../../../../common/config/private/Config";
|
||||||
@ -18,7 +18,9 @@ describe('Authentication middleware', () => {
|
|||||||
let req: any = {
|
let req: any = {
|
||||||
session: {
|
session: {
|
||||||
user: "A user"
|
user: "A user"
|
||||||
}
|
},
|
||||||
|
query: {},
|
||||||
|
params: {}
|
||||||
};
|
};
|
||||||
let next: any = (err) => {
|
let next: any = (err) => {
|
||||||
expect(err).to.be.undefined;
|
expect(err).to.be.undefined;
|
||||||
@ -30,7 +32,9 @@ describe('Authentication middleware', () => {
|
|||||||
|
|
||||||
it('should call next with error on not authenticated', (done) => {
|
it('should call next with error on not authenticated', (done) => {
|
||||||
let req: any = {
|
let req: any = {
|
||||||
session: {}
|
session: {},
|
||||||
|
query: {},
|
||||||
|
params: {}
|
||||||
};
|
};
|
||||||
Config.Client.authenticationRequired = true;
|
Config.Client.authenticationRequired = true;
|
||||||
let res: any = {};
|
let res: any = {};
|
||||||
@ -117,11 +121,15 @@ describe('Authentication middleware', () => {
|
|||||||
ObjectManagerRepository.reset();
|
ObjectManagerRepository.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should call next on missing...', () => {
|
describe('should call input Error next on missing...', () => {
|
||||||
it('body', (done) => {
|
it('body', (done) => {
|
||||||
let req: any = {};
|
let req: any = {
|
||||||
let next: any = (err) => {
|
query: {},
|
||||||
expect(err).to.be.undefined;
|
params: {}
|
||||||
|
};
|
||||||
|
let next: any = (err: Error) => {
|
||||||
|
expect(err).not.to.be.undefined;
|
||||||
|
expect(err.code).to.be.eql(ErrorCodes.INPUT_ERROR);
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
AuthenticationMWs.login(req, null, next);
|
AuthenticationMWs.login(req, null, next);
|
||||||
@ -130,10 +138,13 @@ describe('Authentication middleware', () => {
|
|||||||
|
|
||||||
it('loginCredential', (done) => {
|
it('loginCredential', (done) => {
|
||||||
let req: any = {
|
let req: any = {
|
||||||
body: {}
|
body: {},
|
||||||
|
query: {},
|
||||||
|
params: {}
|
||||||
};
|
};
|
||||||
let next: any = (err) => {
|
let next: any = (err: Error) => {
|
||||||
expect(err).to.be.undefined;
|
expect(err).not.to.be.undefined;
|
||||||
|
expect(err.code).to.be.eql(ErrorCodes.INPUT_ERROR);
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
AuthenticationMWs.login(req, null, next);
|
AuthenticationMWs.login(req, null, next);
|
||||||
@ -144,10 +155,13 @@ describe('Authentication middleware', () => {
|
|||||||
|
|
||||||
it('loginCredential content', (done) => {
|
it('loginCredential content', (done) => {
|
||||||
let req: any = {
|
let req: any = {
|
||||||
body: {loginCredential: {}}
|
body: {loginCredential: {}},
|
||||||
|
query: {},
|
||||||
|
params: {}
|
||||||
};
|
};
|
||||||
let next: any = (err) => {
|
let next: any = (err: Error) => {
|
||||||
expect(err).to.be.undefined;
|
expect(err).not.to.be.undefined;
|
||||||
|
expect(err.code).to.be.eql(ErrorCodes.INPUT_ERROR);
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
AuthenticationMWs.login(req, null, next);
|
AuthenticationMWs.login(req, null, next);
|
||||||
@ -163,7 +177,9 @@ describe('Authentication middleware', () => {
|
|||||||
username: "aa",
|
username: "aa",
|
||||||
password: "bb"
|
password: "bb"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
query: {},
|
||||||
|
params: {}
|
||||||
};
|
};
|
||||||
let next: any = (err: Error) => {
|
let next: any = (err: Error) => {
|
||||||
expect(err).not.to.be.undefined;
|
expect(err).not.to.be.undefined;
|
||||||
@ -171,8 +187,8 @@ describe('Authentication middleware', () => {
|
|||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
ObjectManagerRepository.getInstance().UserManager = <UserManager>{
|
ObjectManagerRepository.getInstance().UserManager = <UserManager>{
|
||||||
findOne: (filter, cb) => {
|
findOne: (filter): Promise<UserDTO> => {
|
||||||
cb(null, null);
|
return Promise.reject(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AuthenticationMWs.login(req, null, next);
|
AuthenticationMWs.login(req, null, next);
|
||||||
@ -188,7 +204,9 @@ describe('Authentication middleware', () => {
|
|||||||
username: "aa",
|
username: "aa",
|
||||||
password: "bb"
|
password: "bb"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
query: {},
|
||||||
|
params: {}
|
||||||
};
|
};
|
||||||
let next: any = (err: Error) => {
|
let next: any = (err: Error) => {
|
||||||
expect(err).to.be.undefined;
|
expect(err).to.be.undefined;
|
||||||
@ -196,8 +214,8 @@ describe('Authentication middleware', () => {
|
|||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
ObjectManagerRepository.getInstance().UserManager = <UserManager>{
|
ObjectManagerRepository.getInstance().UserManager = <UserManager>{
|
||||||
findOne: (filter, cb: any) => {
|
findOne: (filter) => {
|
||||||
cb(null, "test user");
|
return Promise.resolve("test user");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AuthenticationMWs.login(req, null, next);
|
AuthenticationMWs.login(req, null, next);
|
||||||
|
Loading…
Reference in New Issue
Block a user