summaryrefslogtreecommitdiff
path: root/srv/src/chat/user_test.go
blob: 2169cdea0c0b26e2ab0244a34af4ee9b11a150f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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))
}