TNOCS/node-auth

View on GitHub

Showing 41 of 41 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  const getSubjectPrivileges = (subject: Subject): IRule[] => {
    const rules: IRule[] = [];
    psCollection.find().forEach(ps => {
      ps.policies.forEach(p => {
        const ruleCollection = db.getCollection<IRule>(p.name);
Severity: Major
Found in src/lib/authorize/policy-store.ts and 1 other location - About 7 hrs to fix
src/lib/authorize/policy-store.ts on lines 309..322

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 176.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  const getResourcePrivileges = (resource: Resource): IRule[] => {
    const rules: IRule[] = [];
    psCollection.find().forEach(ps => {
      ps.policies.forEach(p => {
        const ruleCollection = db.getCollection<IRule>(p.name);
Severity: Major
Found in src/lib/authorize/policy-store.ts and 1 other location - About 7 hrs to fix
src/lib/authorize/policy-store.ts on lines 294..307

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 176.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    const isResourceRelevantForRule = (rule: IRule, req: IPermissionRequest): boolean => {
      if (!rule.resource || !req.resource) { return false; }
      for (const key in rule.resource) {
        if (!matchProperties(rule.resource[key], req.resource[key])) { return false; };
      }
    Severity: Major
    Found in src/lib/authorize/policy-store.ts and 1 other location - About 3 hrs to fix
    src/lib/authorize/policy-store.ts on lines 203..209

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 109.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    const isSubjectRelevantForRule = (rule: IRule, req: IPermissionRequest): boolean => {
      if (!rule.subject || !req.subject) { return false; }
      for (const key in rule.subject) {
        if (!matchProperties(rule.subject[key], req.subject[key])) { return false; };
      }
    Severity: Major
    Found in src/lib/authorize/policy-store.ts and 1 other location - About 3 hrs to fix
    src/lib/authorize/policy-store.ts on lines 218..224

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 109.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    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

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

            } else if (user) {
              const json = <IUser>user.toJSON();
              delete json.password;
              // if user is found and password is right create a token
              const token = jwt.sign(json, secretKey, {
    Severity: Major
    Found in src/lib/routes/login.ts and 1 other location - About 2 hrs to fix
    src/lib/routes/login.ts on lines 45..56

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 91.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

            if (isMatch && !err) {
              const json = <IUser>user.toJSON();
              delete json.password;
              // if user is found and password is right create a token
              const token = jwt.sign(json, secretKey, {
    Severity: Major
    Found in src/lib/routes/login.ts and 1 other location - About 2 hrs to fix
    src/lib/routes/login.ts on lines 80..91

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 91.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

          if (resource) {
            if (!req.resource) { req.resource = {}; }
            for (let key in resource) {
              if (!resource.hasOwnProperty(key)) { continue; }
              req.resource[key] = resource[key];
        Severity: Major
        Found in src/lib/authorize/pep.ts and 1 other location - About 2 hrs to fix
        src/lib/authorize/pep.ts on lines 16..22

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 82.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

          if (subject) {
            if (!req.subject) { req.subject = {}; }
            for (let key in subject) {
              if (!subject.hasOwnProperty(key)) { continue; }
              req.subject[key] = subject[key];
        Severity: Major
        Found in src/lib/authorize/pep.ts and 1 other location - About 2 hrs to fix
        src/lib/authorize/pep.ts on lines 24..30

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 82.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

          if (rule.subject) {
            if (!req.subject) { return false; }
            for (const key in rule.subject) {
              if (!matchProperties(rule.subject[key], req.subject[key])) { return false; };
            }
        Severity: Major
        Found in src/lib/authorize/policy-store.ts and 1 other location - About 2 hrs to fix
        src/lib/authorize/policy-store.ts on lines 187..192

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 78.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

          if (rule.resource) {
            if (!req.resource) { return false; }
            for (const key in rule.resource) {
              if (!matchProperties(rule.resource[key], req.resource[key])) { return false; };
            }
        Severity: Major
        Found in src/lib/authorize/policy-store.ts and 1 other location - About 2 hrs to fix
        src/lib/authorize/policy-store.ts on lines 181..186

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 78.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        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

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

            if (!user.admin && user._id.toString() !== id) {
              res.status(UNAUTHORIZED).json({ success: false, message: 'Request denied' });
              return;
            }
          Severity: Major
          Found in src/lib/routes/user.ts and 2 other locations - About 1 hr to fix
          src/lib/routes/user.ts on lines 68..71
          src/lib/routes/user.ts on lines 251..254

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 63.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Severity
          Category
          Status
          Source
          Language