msimerson/Haraka

View on GitHub
plugins/auth/auth_base.js

Summary

Maintainability
D
1 day
Test Coverage

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

exports.check_user = function (next, connection, credentials, method) {
    const plugin = this;
    connection.notes.authenticating = false;
    if (!(credentials[0] && credentials[1])) {
        connection.respond(504, 'Invalid AUTH string', () => {
Severity: Minor
Found in plugins/auth/auth_base.js - 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 check_user has 53 lines of code (exceeds 25 allowed). Consider refactoring.
Open

exports.check_user = function (next, connection, credentials, method) {
    const plugin = this;
    connection.notes.authenticating = false;
    if (!(credentials[0] && credentials[1])) {
        connection.respond(504, 'Invalid AUTH string', () => {
Severity: Major
Found in plugins/auth/auth_base.js - About 2 hrs to fix

    Function passwd_ok has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function passwd_ok (valid, opts) {
            const status_code = (typeof(opts) === 'object' && opts.code) || (valid ? 235 : 535);
            const status_message = (typeof(opts) === 'object' ? opts.message : opts) ||
                    (valid  ? '2.7.0 Authentication successful' : '5.7.8 Authentication failed');
    
    
    Severity: Minor
    Found in plugins/auth/auth_base.js - About 1 hr to fix

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

      exports.auth_login = function (next, connection, params) {
          if ((!connection.notes.auth_login_asked_login && params[0]) ||
              ( connection.notes.auth_login_asked_login &&
               !connection.notes.auth_login_userlogin)) {
      
      
      Severity: Minor
      Found in plugins/auth/auth_base.js - 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 hook_unrecognized_command has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      exports.hook_unrecognized_command = function (next, connection, params) {
          if (params[0].toUpperCase() === AUTH_COMMAND && params[1]) {
              return this.select_auth_method(next, connection, params.slice(1).join(' '));
          }
          if (!connection.notes.authenticating) return next();
      Severity: Minor
      Found in plugins/auth/auth_base.js - 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 check_plain_passwd has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      exports.check_plain_passwd = function (connection, user, passwd, cb) {
          function callback (plain_pw) {
              if (plain_pw === null  ) return cb(false);
              if (plain_pw !== passwd) return cb(false);
              cb(true);
      Severity: Minor
      Found in plugins/auth/auth_base.js - 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 check_cram_md5_passwd has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      exports.check_cram_md5_passwd = function (connection, user, passwd, cb) {
          function callback (plain_pw) {
              if (plain_pw == null) return cb(false);
      
              const hmac = crypto.createHmac('md5', plain_pw.toString());
      Severity: Minor
      Found in plugins/auth/auth_base.js - 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

      Avoid too many return statements within this function.
      Open

          if (method === AUTH_METHOD_CRAM_MD5) return this.auth_cram_md5(next, connection);
      Severity: Major
      Found in plugins/auth/auth_base.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return this.auth_plain(next, connection, params);
        Severity: Major
        Found in plugins/auth/auth_base.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              if (method === AUTH_METHOD_LOGIN) return this.auth_login(next, connection, split);
          Severity: Major
          Found in plugins/auth/auth_base.js - About 30 mins to fix

            Function select_auth_method has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            exports.select_auth_method = function (next, connection, method) {
                const split = method.split(/\s+/);
                method = split.shift().toUpperCase();
                if (!connection.notes.allowed_auth_methods) return next();
                if (!connection.notes.allowed_auth_methods.includes(method)) return next();
            Severity: Minor
            Found in plugins/auth/auth_base.js - About 25 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

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

                if (this.get_plain_passwd.length == 2) {
                    this.get_plain_passwd(user, callback);
                }
                else if (this.get_plain_passwd.length == 3) {
                    this.get_plain_passwd(user, connection, callback);
            Severity: Major
            Found in plugins/auth/auth_base.js and 1 other location - About 1 hr to fix
            plugins/auth/auth_base.js on lines 76..84

            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 71.

            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 (this.get_plain_passwd.length == 2) {
                    this.get_plain_passwd(user, callback);
                }
                else if (this.get_plain_passwd.length == 3) {
                    this.get_plain_passwd(user, connection, callback);
            Severity: Major
            Found in plugins/auth/auth_base.js and 1 other location - About 1 hr to fix
            plugins/auth/auth_base.js on lines 54..62

            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 71.

            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

            There are no issues that match your filters.

            Category
            Status