TNOCS/node-auth

View on GitHub

Showing 25 of 41 total issues

Function createPolicyStore has 129 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const createPolicyStore = (db: Loki) => {
  const psCollection = db.getCollection<IPolicySetCollection>('policy-sets');

  /**
   * Returns all policy sets.
Severity: Major
Found in src/lib/authorize/policy-store.ts - About 5 hrs to fix

    Function isRuleRelevant has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    const isRuleRelevant = (rule: IRule, req: IPermissionRequest, checkAction = true): boolean => {
      if (rule.action && checkAction) {
        if (!req.action || !((req.action & rule.action) === req.action)) { return false; }
      }
      if (rule.subject) {
    Severity: Minor
    Found in src/lib/authorize/policy-store.ts - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    File policy-store.ts has 273 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { Resource } from './../models/resource';
    import { NOT_MODIFIED, CREATED, OK, NO_CONTENT } from 'http-status-codes';
    import * as lokijs from 'lokijs';
    import { IRule } from '../models/rule';
    import { Subject } from '../models/subject';
    Severity: Minor
    Found in src/lib/authorize/policy-store.ts - About 2 hrs to fix

      Function createRoutes has 63 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function createRoutes(secretKey: string, options: INodeAuthOptions) {
        const apiRoutes = express.Router();
        loginRoute.init(options);
        userRoute.init(options);
        verifyRoute.init(options);
      Severity: Major
      Found in src/lib/node-auth.ts - About 2 hrs to fix

        Function addExtraAttributesToRequest has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

        function addExtraAttributesToRequest(extraAttributes: IBaseRule, req: IPermissionRequest) {
          if (!extraAttributes) { return; }
          const subject = extraAttributes.subject;
          if (subject) {
            if (!req.subject) { req.subject = {}; }
        Severity: Minor
        Found in src/lib/authorize/pep.ts - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function matchProperties has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        const matchProperties = (ruleProp: boolean | string | number | string[] | number[], reqProp: boolean | string | number | string[] | number[]) => {
          if (ruleProp instanceof Array) {
            // ruleProp is an array
            if (reqProp instanceof Array) {
              // they are both arrays
        Severity: Minor
        Found in src/lib/authorize/policy-store.ts - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function createNewUser has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

        function createNewUser(req: Request, res: Response) {
          const name = req['body'].name;
          const email = req['body'].email;
          const password = req['body'].password;
          const admin = req['body'].admin;
        Severity: Minor
        Found in src/lib/routes/user.ts - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function callback has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const callback = (err: Error, ps: IPolicyStore) => {
          if (err) { throw err; }
          policyStore = ps;
        
          const auth = NodeAuth(server, <INodeAuthOptions>{
        Severity: Minor
        Found in src/example/server.ts - About 1 hr to fix

          Function createRoutes has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          function createRoutes(secretKey: string, options: INodeAuthOptions) {
            const apiRoutes = express.Router();
            loginRoute.init(options);
            userRoute.init(options);
            verifyRoute.init(options);
          Severity: Minor
          Found in src/lib/node-auth.ts - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function getPolicyEditor has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            const getPolicyEditor = (policyName: string, policySetName: string) => {
              const name = createPolicyName(policySetName, policyName);
              const ruleCollection = db.getCollection<IRule>(name);
              const getRules = (req: IPermissionRequest) => {
                return ruleCollection
          Severity: Minor
          Found in src/lib/authorize/policy-store.ts - About 1 hr to fix

            Function verifyEmail has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function verifyEmail(req: Request, res: Response) {
              const id = req.params['id'];
              const token = req.query['t'];
              if (!id || !token) {
                res.status(BAD_REQUEST).json({ success: false, message: 'Please create a valid request!' });
            Severity: Minor
            Found in src/lib/routes/verify.ts - About 1 hr to fix

              Function createApiRoute has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function createApiRoute(apiRoutes: express.Router, options: INodeAuthOptions) {
                let routes = [];
              
                const apiRoute = (options.api && typeof options.api === 'string') ? options.api : '/api';
              
              
              Severity: Minor
              Found in src/lib/node-auth.ts - About 1 hr to fix

                Function login has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export function login(req: Request, res: Response) {
                  const email = req['body'].email;
                  const pwd = req['body'].password;
                
                  const token = getToken(req);
                Severity: Minor
                Found in src/lib/routes/login.ts - About 1 hr to fix

                  Function authenticateUser has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function authenticateUser(secretKey: string, blockUnauthenticatedUser = true) {
                    const authnErrorHandler = blockUnauthenticatedUser
                      ? (req: express.Request, res: express.Response, next: express.NextFunction, msg?: string) => {
                        // AuthN failed, so return an error.
                        res.status(UNAUTHORIZED).json({
                  Severity: Minor
                  Found in src/lib/node-auth.ts - About 1 hr to fix

                    Function updateUser has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export function updateUser(req: Request, res: Response) {
                      const updatedUser: IUser = req['body'];
                      const id: string = req.params['id'];
                      const user: IUser = req['user'];
                    
                    
                    Severity: Minor
                    Found in src/lib/routes/user.ts - About 1 hr to fix

                      Function createPrivileges has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                      export function createPrivileges(req: Request, res: Response) {
                        const handler = (newPrivilegeReq: IPrivilegeRequest) => {
                          return (msg: ResponseMessage) => {
                            if (msg.success) {
                              const ruleStatus = createPrivilege(newPrivilegeReq);
                      Severity: Minor
                      Found in src/lib/routes/authorize.ts - About 55 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Function deletePrivileges has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                      export function deletePrivileges(req: Request, res: Response) {
                        const handler = (newPrivilege: IPrivilegeRequest) => {
                          return (msg: ResponseMessage) => {
                            if (msg.success) {
                              const ruleStatus = deletePrivilege(newPrivilege);
                      Severity: Minor
                      Found in src/lib/routes/authorize.ts - About 55 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Function updatePrivileges has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                      export function updatePrivileges(req: Request, res: Response) {
                        const handler = (newPrivilege: IPrivilegeRequest) => {
                          return (msg: ResponseMessage) => {
                            if (msg.success) {
                              const ruleStatus = updatePrivilege(newPrivilege);
                      Severity: Minor
                      Found in src/lib/routes/authorize.ts - About 55 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Function createApiRoute has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function createApiRoute(apiRoutes: express.Router, options: INodeAuthOptions) {
                        let routes = [];
                      
                        const apiRoute = (options.api && typeof options.api === 'string') ? options.api : '/api';
                      
                      
                      Severity: Minor
                      Found in src/lib/node-auth.ts - About 35 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Function getPolicyEditor has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function getPolicyEditor(newPrivilege: IPrivilegeRequest) {
                        const policy = newPrivilege.policy || -1;
                        if (typeof policy === 'number') {
                          const policySet = policyStore.getPolicySet(newPrivilege.policySet);
                          if (policy >= policySet.policies.length) { return null; }
                      Severity: Minor
                      Found in src/lib/routes/authorize.ts - About 35 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Severity
                      Category
                      Status
                      Source
                      Language