github.com/psiphon-Labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/upstreamproxy/go-ntlm/ntlm/helpers_test.go (about) 1 //Copyright 2013 Thomson Reuters Global Resources. BSD License please see License file for more information 2 3 package ntlm 4 5 import ( 6 "bytes" 7 "encoding/hex" 8 "testing" 9 ) 10 11 func TestUTf16ToString(t *testing.T) { 12 expected, _ := hex.DecodeString("5500730065007200") 13 result := utf16FromString("User") 14 if !bytes.Equal(expected, result) { 15 t.Errorf("UTF16ToString failed got %s expected %s", hex.EncodeToString(result), "5500730065007200") 16 } 17 } 18 19 func TestMacsEquals(t *testing.T) { 20 // the MacsEqual should ignore the values in the second 4 bytes 21 firstSlice := []byte{0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xf0, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff} 22 secondSlice := []byte{0xf1, 0xf2, 0xf3, 0xf4, 0x00, 0x00, 0x00, 0x00, 0xf9, 0xf0, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff} 23 if !MacsEqual(firstSlice, secondSlice) { 24 t.Errorf("Expected MacsEqual(%v, %v) to be true", firstSlice, secondSlice) 25 } 26 } 27 28 func TestMacsEqualsFail(t *testing.T) { 29 // the last bytes in the following test case should cause MacsEqual to return false 30 firstSlice := []byte{0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xf0, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff} 31 secondSlice := []byte{0xf1, 0xf2, 0xf3, 0xf4, 0x00, 0x00, 0x00, 0x00, 0xf9, 0xf0, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xfe} 32 if MacsEqual(firstSlice, secondSlice) { 33 t.Errorf("Expected MacsEqual(%v, %v) to be false", firstSlice, secondSlice) 34 } 35 }