This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: base64 password hash in file members provider to avoid json issues.
- Loading branch information
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package file | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/demodesk/neko/pkg/utils" | ||
) | ||
|
||
// Ensure that hashes are the same after encoding and decoding using json | ||
func TestMemberProviderCtx_hash(t *testing.T) { | ||
provider := &MemberProviderCtx{ | ||
config: Config{ | ||
Hash: true, | ||
}, | ||
} | ||
|
||
// generate random strings | ||
passwords := []string{} | ||
for i := 0; i < 10; i++ { | ||
password, err := utils.NewUID(32) | ||
if err != nil { | ||
t.Errorf("utils.NewUID() returned error: %s", err) | ||
} | ||
passwords = append(passwords, password) | ||
} | ||
|
||
for _, password := range passwords { | ||
hashedPassword := provider.hash(password) | ||
|
||
// json encode password hash | ||
hashedPasswordJSON, err := json.Marshal(hashedPassword) | ||
if err != nil { | ||
t.Errorf("json.Marshal() returned error: %s", err) | ||
} | ||
|
||
// json decode password hash json | ||
var hashedPasswordStr string | ||
err = json.Unmarshal(hashedPasswordJSON, &hashedPasswordStr) | ||
if err != nil { | ||
t.Errorf("json.Unmarshal() returned error: %s", err) | ||
} | ||
|
||
if hashedPasswordStr != hashedPassword { | ||
t.Errorf("hashedPasswordStr: %s != hashedPassword: %s", hashedPasswordStr, hashedPassword) | ||
} | ||
} | ||
} |