forked from whiym/fish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fish_test.go
52 lines (42 loc) · 1015 Bytes
/
fish_test.go
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package fish
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
const (
ebcKey = "blowfish"
ebcKeyNew = "newkey"
cbcKey = "cbc:blowfish"
badKey = ""
)
func TestNewFish(t *testing.T) {
f, err := NewFish(ebcKey)
assert.NoError(t, err)
assert.NotNil(t, f)
assert.Equal(t, modeEBC, f.mode)
assert.Equal(t, ebcKey, f.key)
assert.NotNil(t, f.cipher)
f, err = NewFish(cbcKey)
assert.NoError(t, err)
assert.NotNil(t, f)
assert.Equal(t, modeCBC, f.mode)
assert.Equal(t, strings.TrimPrefix(cbcKey, KeyPrefixCBC), f.key)
assert.NotNil(t, f.cipher)
f, err = NewFish(badKey)
assert.Error(t, err)
assert.Nil(t, f)
}
func TestFish_UpdateKey(t *testing.T) {
f, err := NewFish(ebcKey)
assert.NoError(t, err)
err = f.UpdateKey(badKey)
assert.Error(t, err)
assert.Equal(t, ebcKey, f.key)
orig := *f
err = f.UpdateKey(ebcKeyNew)
assert.NoError(t, err)
assert.Equal(t, ebcKeyNew, f.key)
assert.NotEqual(t, orig.key, f.key)
assert.NotEqual(t, orig.cipher, f.cipher)
}