Skip to content

Commit

Permalink
Add more password obfuscation test
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Sep 7, 2023
1 parent d67de82 commit ea9e61a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sethvargo/go-password v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.3.0 h1:6NjYksEUlhurdVehpc7S7dk6DAmcKv8V9gG0FsVN2U4=
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/sethvargo/go-password v0.2.0 h1:BTDl4CC/gjf/axHMaDQtw507ogrXLci6XRiLc7i/UHI=
github.com/sethvargo/go-password v0.2.0/go.mod h1:Ym4Mr9JXLBycr02MFuVQ/0JHidNetSgbzutTr3zsYXE=
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
20 changes: 20 additions & 0 deletions test/testcases/password_obfuscation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"testing"

"github.com/cyverse/go-irodsclient/utils/icommands"
"github.com/sethvargo/go-password/password"
"github.com/stretchr/testify/assert"
)

func TestPasswordObfuscation(t *testing.T) {
t.Run("test PasswordObfuscation", testEncodeDecodePassword)
t.Run("test EncodeDecodeRandomPassword", testEncodeDecodeRandomPassword)
}

func testEncodeDecodePassword(t *testing.T) {
Expand Down Expand Up @@ -37,3 +39,21 @@ func testEncodeDecodePassword(t *testing.T) {
//t.Logf("enc: %s", encodedPassword)
//t.Logf("dec: %s", decodedPassword)
}

func testEncodeDecodeRandomPassword(t *testing.T) {
for i := 0; i < 100000; i++ {
mypassword, err := password.Generate(20, 10, 10, false, true)
if err != nil {
t.Fatal(err)
}
//t.Logf("test password '%s'", mypassword)

encodedPassword := icommands.EncodePasswordString(mypassword, 1000)
decodedPassword := icommands.DecodePasswordString(encodedPassword, 1000)

//t.Logf("enc: %s", encodedPassword)
//t.Logf("dec: %s", decodedPassword)

assert.Equal(t, mypassword, decodedPassword)
}
}

0 comments on commit ea9e61a

Please sign in to comment.