Skip to content

Commit

Permalink
user id case insensitive - #186
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhatsharma committed Jun 4, 2022
1 parent c567226 commit 210bf89
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
package auth

import (
"strings"

"github.com/zinclabs/zinc/pkg/meta"
)

func VerifyCredentials(userID, password string) (*meta.User, bool) {
userID = strings.ToLower(userID)
user, ok := ZINC_CACHED_USERS.Get(userID)
if !ok {
return user, false
Expand Down
11 changes: 11 additions & 0 deletions pkg/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ func TestVerifyCredentials(t *testing.T) {
},
want1: false,
},
{
name: "test with case insensitive user id",
args: args{
userID: "Admin",
password: "Complexpass#123",
},
want: meta.User{
ID: "admin",
},
want1: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/auth/createuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package auth

import (
"encoding/base64"
"strings"
"time"

"golang.org/x/crypto/argon2"
Expand All @@ -28,6 +29,7 @@ import (
)

func CreateUser(id, name, plaintextPassword, role string) (*meta.User, error) {
id = strings.ToLower(id)
var newUser *meta.User
existingUser, userExists, err := GetUser(id)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/auth/deleteuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
package auth

import (
"strings"

"github.com/zinclabs/zinc/pkg/metadata"
)

func DeleteUser(id string) error {
id = strings.ToLower(id)
return metadata.User.Delete(id)
}

0 comments on commit 210bf89

Please sign in to comment.