ecadlabs/signatory

View on GitHub
pkg/middlewares/jwt.go

Summary

Maintainability
C
1 day
Test Coverage
B
81%

Method JWT.CheckUpdateNewCred has a Cognitive Complexity of 43 (exceeds 20 allowed). Consider refactoring.
Open

func (j *JWT) CheckUpdateNewCred() error {
    for user, data := range j.Users {
        if data.NewData != nil {
            if data.NewData.Password == data.Password || data.NewData.Secret == data.Secret {
                return fmt.Errorf("JWT: new credentials are same as old for user %s", user)
Severity: Minor
Found in pkg/middlewares/jwt.go - About 4 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 validateSecretAndPass has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring.
Open

func validateSecretAndPass(secret []string) error {
    var length int = 16
    var stype string = "password"
    for _, s := range secret {
        // Check length
Severity: Minor
Found in pkg/middlewares/jwt.go - About 3 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

Consider simplifying this complex logical expression.
Open

            if c >= 32 && c <= 126 && !((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
Severity: Critical
Found in pkg/middlewares/jwt.go - About 1 hr to fix

    Method JWT.CheckUpdateNewCred has 12 return statements (exceeds 4 allowed).
    Open

    func (j *JWT) CheckUpdateNewCred() error {
        for user, data := range j.Users {
            if data.NewData != nil {
                if data.NewData.Password == data.Password || data.NewData.Secret == data.Secret {
                    return fmt.Errorf("JWT: new credentials are same as old for user %s", user)
    Severity: Major
    Found in pkg/middlewares/jwt.go - About 1 hr to fix

      Method JWT.Authenticate has 8 return statements (exceeds 4 allowed).
      Open

      func (j *JWT) Authenticate(user string, token string) (string, error) {
          var tok *jwt.Token
          var err error
          ud, ok := j.GetUserData(user)
          if ok {
      Severity: Major
      Found in pkg/middlewares/jwt.go - About 50 mins to fix

        Function validateSecretAndPass has 6 return statements (exceeds 4 allowed).
        Open

        func validateSecretAndPass(secret []string) error {
            var length int = 16
            var stype string = "password"
            for _, s := range secret {
                // Check length
        Severity: Major
        Found in pkg/middlewares/jwt.go - About 40 mins to fix

          Method JWTMiddleware.LoginHandler has 5 return statements (exceeds 4 allowed).
          Open

          func (m *JWTMiddleware) LoginHandler(w http.ResponseWriter, r *http.Request) {
              user := r.Header.Get("username")
              pass := r.Header.Get("password")
              if user == "" || pass == "" {
                  w.WriteHeader(http.StatusUnauthorized)
          Severity: Major
          Found in pkg/middlewares/jwt.go - About 35 mins to fix

            There are no issues that match your filters.

            Category
            Status