diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2021-08-18 18:13:18 -0600 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2021-08-18 18:13:44 -0600 |
commit | a9d8aa2591cd03fe1a9da72bab8d311e4840e8f1 (patch) | |
tree | 98a32eb3a2719f10dc0d55a206851e3793e61388 /srv/chat/user_test.go | |
parent | bec64827d19d64aae86ca3d2b26de800b427a540 (diff) |
implemented basic userID generation
Diffstat (limited to 'srv/chat/user_test.go')
-rw-r--r-- | srv/chat/user_test.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/srv/chat/user_test.go b/srv/chat/user_test.go new file mode 100644 index 0000000..2169cde --- /dev/null +++ b/srv/chat/user_test.go @@ -0,0 +1,26 @@ +package chat + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestUserIDCalculator(t *testing.T) { + + const name, password = "name", "password" + + c := NewUserIDCalculator([]byte("foo")) + + // calculating with same params twice should result in same UserID + userID := c.Calculate(name, password) + assert.Equal(t, userID, c.Calculate(name, password)) + + // changing either name or password should result in a different Hash + assert.NotEqual(t, userID.Hash, c.Calculate(name+"!", password).Hash) + assert.NotEqual(t, userID.Hash, c.Calculate(name, password+"!").Hash) + + // changing the secret should change the UserID + c.Secret = []byte("bar") + assert.NotEqual(t, userID, c.Calculate(name, password)) +} |