All files / lib/auth check.ts

97.37% Statements 37/38
70% Branches 7/10
100% Functions 4/4
97.37% Lines 37/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 391x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 1x 1x 4x 4x 4x   1x 1x 1x  
/**
 * @file 权限校验脚本
 * @Author wangjie19
 * @Date 2020-07-23 20:01:04
 * @Last Modified by: wangjie19
 * @Last Modified time: 2020-07-23 20:44:01
 */
 
import json from "./user.json";
 
interface IAuthInfo {
    user: string,
    password: string,
    db: string
}
 
class CheckAuth {
    /** 用户 */
    user: string
    /** 密码 */
    password: string
    /** 数据库 */
    db: string
    constructor(props: IAuthInfo) {
        const {user, password, db} = props;
        this.user = user;
        this.password = password;
        this.db = db;
    }
 
    check(): boolean {
        const  {user, password, db} = this;
        let mapUser = json.filter(item => item.user === user);
        return mapUser.length ? mapUser[0].db === db && mapUser[0].password === password : false;
    }
}
 
export default CheckAuth;