-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathhelpers_test.go
35 lines (30 loc) · 1.36 KB
/
helpers_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
//Copyright 2013 Thomson Reuters Global Resources. BSD License please see License file for more information
package ntlm
import (
"bytes"
"encoding/hex"
"testing"
)
func TestUTf16ToString(t *testing.T) {
expected, _ := hex.DecodeString("5500730065007200")
result := utf16FromString("User")
if !bytes.Equal(expected, result) {
t.Errorf("UTF16ToString failed got %s expected %s", hex.EncodeToString(result), "5500730065007200")
}
}
func TestMacsEquals(t *testing.T) {
// the MacsEqual should ignore the values in the second 4 bytes
firstSlice := []byte{0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xf0, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff}
secondSlice := []byte{0xf1, 0xf2, 0xf3, 0xf4, 0x00, 0x00, 0x00, 0x00, 0xf9, 0xf0, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff}
if !MacsEqual(firstSlice, secondSlice) {
t.Errorf("Expected MacsEqual(%v, %v) to be true", firstSlice, secondSlice)
}
}
func TestMacsEqualsFail(t *testing.T) {
// the last bytes in the following test case should cause MacsEqual to return false
firstSlice := []byte{0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xf0, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff}
secondSlice := []byte{0xf1, 0xf2, 0xf3, 0xf4, 0x00, 0x00, 0x00, 0x00, 0xf9, 0xf0, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xfe}
if MacsEqual(firstSlice, secondSlice) {
t.Errorf("Expected MacsEqual(%v, %v) to be false", firstSlice, secondSlice)
}
}