You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
715 B
26 lines
715 B
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))
|
|
}
|
|
|