RocketChat/Rocket.Chat

View on GitHub
apps/meteor/app/custom-oauth/server/custom_oauth_server.js

Summary

Maintainability
F
3 days
Test Coverage

File custom_oauth_server.js has 368 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { LDAP } from '@rocket.chat/core-services';
import { Logger } from '@rocket.chat/logger';
import { Users } from '@rocket.chat/models';
import { serverFetch as fetch } from '@rocket.chat/server-fetch';
import { Accounts } from 'meteor/accounts-base';
Severity: Minor
Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js - About 4 hrs to fix

    Function addHookToProcessUser has 56 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        addHookToProcessUser() {
            BeforeUpdateOrCreateUserFromExternalService.push(async (serviceName, serviceData /* , options*/) => {
                if (serviceName !== this.name) {
                    return;
                }
    Severity: Major
    Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js - About 2 hrs to fix

      Function configure has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          configure(options) {
              if (!Match.test(options, Object)) {
                  throw new Meteor.Error('CustomOAuth: Options is required and must be Object');
              }
      
      
      Severity: Minor
      Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js - About 1 hr to fix

        Function getAccessToken has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            async getAccessToken(query) {
                const config = await ServiceConfiguration.configurations.findOneAsync({ service: this.name });
                if (!config) {
                    throw new Accounts.ConfigError();
                }
        Severity: Minor
        Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js - About 1 hr to fix

          Function normalizeIdentity has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              normalizeIdentity(identity) {
                  if (identity) {
                      for (const normalizer of Object.values(normalizers)) {
                          const result = normalizer(identity);
                          if (result) {
          Severity: Minor
          Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js - 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 configure has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              configure(options) {
                  if (!Match.test(options, Object)) {
                      throw new Meteor.Error('CustomOAuth: Options is required and must be Object');
                  }
          
          
          Severity: Minor
          Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js - 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 registerAccessTokenService has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              registerAccessTokenService(name) {
                  const self = this;
                  const whitelisted = ['id', 'email', 'username', 'name', this.rolesClaim];
          
                  registerAccessTokenService(name, async (options) => {
          Severity: Minor
          Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

                            if (
                                user.services &&
                                user.services[serviceName] &&
                                user.services[serviceName].id === serviceData.id &&
                                user.name === serviceData.name &&
            Severity: Major
            Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js - About 1 hr to fix

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

                  async getAccessToken(query) {
                      const config = await ServiceConfiguration.configurations.findOneAsync({ service: this.name });
                      if (!config) {
                          throw new Accounts.ConfigError();
                      }
              Severity: Minor
              Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.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

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

                  getEmail(data) {
                      try {
                          const value = fromTemplate(this.emailField, data);
              
                          if (!value) {
              Severity: Major
              Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js and 1 other location - About 2 hrs to fix
              apps/meteor/app/custom-oauth/server/custom_oauth_server.js on lines 262..273

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

              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

                  getUsername(data) {
                      try {
                          const value = fromTemplate(this.usernameField, data);
              
                          if (!value) {
              Severity: Major
              Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js and 1 other location - About 2 hrs to fix
              apps/meteor/app/custom-oauth/server/custom_oauth_server.js on lines 275..286

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

              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

                      try {
                          const request = await fetch(`${this.tokenPath}`, {
                              method: 'POST',
                              headers,
                              body: params,
              Severity: Major
              Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js and 1 other location - About 1 hr to fix
              apps/meteor/app/custom-oauth/server/custom_oauth_server.js on lines 173..188

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

              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

                      try {
                          const request = await fetch(`${this.identityPath}`, { method: 'GET', headers, params });
              
                          if (!request.ok) {
                              throw new Error(request.statusText);
              Severity: Major
              Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js and 1 other location - About 1 hr to fix
              apps/meteor/app/custom-oauth/server/custom_oauth_server.js on lines 135..150

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

              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 (this.keyField === 'username') {
                                  user = this.mergeUsersDistinctServices
                                      ? await Users.findOneByUsernameIgnoringCase(serviceData.username)
                                      : await Users.findOneByUsernameAndServiceNameIgnoringCase(serviceData.username, serviceData.id, serviceName);
                              } else if (this.keyField === 'email') {
              Severity: Major
              Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js and 1 other location - About 1 hr to fix
              apps/meteor/app/custom-oauth/server/custom_oauth_server.js on lines 340..344

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

              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

                              } else if (this.keyField === 'email') {
                                  user = this.mergeUsersDistinctServices
                                      ? await Users.findOneByEmailAddress(serviceData.email)
                                      : await Users.findOneByEmailAddressAndServiceNameIgnoringCase(serviceData.email, serviceData.id, serviceName);
                              }
              Severity: Major
              Found in apps/meteor/app/custom-oauth/server/custom_oauth_server.js and 1 other location - About 1 hr to fix
              apps/meteor/app/custom-oauth/server/custom_oauth_server.js on lines 336..344

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

              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