From 963dae829d33d43efdd7c2986967cfe17f0b4225 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Tue, 7 Apr 2020 21:19:40 +0100 Subject: [PATCH] Fix tests --- internal/client/auth_test.go | 6 +++--- internal/multiplex/obfs_test.go | 10 ++-------- internal/multiplex/session_test.go | 23 +++++++++++++---------- internal/multiplex/stream_test.go | 4 ++-- internal/server/activeuser_test.go | 4 ++-- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/internal/client/auth_test.go b/internal/client/auth_test.go index de4dfa3..6fc39c7 100644 --- a/internal/client/auth_test.go +++ b/internal/client/auth_test.go @@ -14,7 +14,7 @@ func TestMakeAuthenticationPayload(t *testing.T) { seed io.Reader time time.Time expPayload authenticationPayload - expSecret []byte + expSecret [32]byte }{ { &authInfo{ @@ -54,7 +54,7 @@ func TestMakeAuthenticationPayload(t *testing.T) { 0x3b, 0xb8, 0x8b, 0xfb, 0xb6, 0x40, 0xf0, 0x2c, 0x6c, 0x55, 0xb9, 0xfc, 0x5d, 0x34, 0x89, 0x41}, }, - []byte{ + [32]byte{ 0xc7, 0xc6, 0x9b, 0xbe, 0xec, 0xf8, 0x35, 0x55, 0x67, 0x20, 0xcd, 0xeb, 0x74, 0x16, 0xc5, 0x60, 0xee, 0x9d, 0x63, 0x1a, 0x44, 0xc5, 0x09, 0xf6, @@ -67,7 +67,7 @@ func TestMakeAuthenticationPayload(t *testing.T) { if payload != tc.expPayload { t.Errorf("payload doesn't match:\nexp %v\ngot %v", tc.expPayload, payload) } - if !bytes.Equal(sharedSecret, tc.expSecret) { + if sharedSecret != tc.expSecret { t.Errorf("secret doesn't match:\nexp %x\ngot %x", tc.expPayload, payload) } }() diff --git a/internal/multiplex/obfs_test.go b/internal/multiplex/obfs_test.go index 6a1e77d..c7c19b2 100644 --- a/internal/multiplex/obfs_test.go +++ b/internal/multiplex/obfs_test.go @@ -12,8 +12,8 @@ import ( ) func TestGenerateObfs(t *testing.T) { - sessionKey := make([]byte, 32) - rand.Read(sessionKey) + var sessionKey [32]byte + rand.Read(sessionKey[:]) run := func(obfuscator *Obfuscator, ct *testing.T) { obfsBuf := make([]byte, 512) @@ -84,12 +84,6 @@ func TestGenerateObfs(t *testing.T) { t.Errorf("unknown encryption mehtod error expected") } }) - t.Run("bad key length", func(t *testing.T) { - _, err := GenerateObfs(0xff, sessionKey[:31], true) - if err == nil { - t.Errorf("bad key length error expected") - } - }) } func BenchmarkObfs(b *testing.B) { diff --git a/internal/multiplex/session_test.go b/internal/multiplex/session_test.go index 34567ae..b4a0bcc 100644 --- a/internal/multiplex/session_test.go +++ b/internal/multiplex/session_test.go @@ -34,8 +34,8 @@ func TestRecvDataFromRemote(t *testing.T) { } obfsBuf := make([]byte, 17000) - sessionKey := make([]byte, 32) - rand.Read(sessionKey) + var sessionKey [32]byte + rand.Read(sessionKey[:]) t.Run("plain ordered", func(t *testing.T) { obfuscator, _ := GenerateObfs(E_METHOD_PLAIN, sessionKey, true) seshConfigOrdered.Obfuscator = obfuscator @@ -153,11 +153,12 @@ func TestRecvDataFromRemote_Closing_InOrder(t *testing.T) { rand.Read(testPayload) obfsBuf := make([]byte, 17000) - sessionKey := make([]byte, 32) + var sessionKey [32]byte + rand.Read(sessionKey[:]) + obfuscator, _ := GenerateObfs(E_METHOD_PLAIN, sessionKey, true) seshConfigOrdered.Obfuscator = obfuscator - rand.Read(sessionKey) sesh := MakeSession(0, seshConfigOrdered) f1 := &Frame{ @@ -283,11 +284,12 @@ func TestRecvDataFromRemote_Closing_OutOfOrder(t *testing.T) { rand.Read(testPayload) obfsBuf := make([]byte, 17000) - sessionKey := make([]byte, 32) + var sessionKey [32]byte + rand.Read(sessionKey[:]) + obfuscator, _ := GenerateObfs(E_METHOD_PLAIN, sessionKey, true) seshConfigOrdered.Obfuscator = obfuscator - rand.Read(sessionKey) sesh := MakeSession(0, seshConfigOrdered) // receive stream 1 closing first @@ -341,10 +343,11 @@ func TestRecvDataFromRemote_Closing_OutOfOrder(t *testing.T) { func TestParallel(t *testing.T) { rand.Seed(0) - sessionKey := make([]byte, 32) + var sessionKey [32]byte + rand.Read(sessionKey[:]) + obfuscator, _ := GenerateObfs(E_METHOD_PLAIN, sessionKey, true) seshConfigOrdered.Obfuscator = obfuscator - rand.Read(sessionKey) sesh := MakeSession(0, seshConfigOrdered) numStreams := 10 @@ -410,8 +413,8 @@ func BenchmarkRecvDataFromRemote_Ordered(b *testing.B) { } obfsBuf := make([]byte, 17000) - sessionKey := make([]byte, 32) - rand.Read(sessionKey) + var sessionKey [32]byte + rand.Read(sessionKey[:]) b.Run("plain", func(b *testing.B) { obfuscator, _ := GenerateObfs(E_METHOD_PLAIN, sessionKey, true) diff --git a/internal/multiplex/stream_test.go b/internal/multiplex/stream_test.go index d917bee..b218adb 100644 --- a/internal/multiplex/stream_test.go +++ b/internal/multiplex/stream_test.go @@ -12,8 +12,8 @@ import ( ) func setupSesh(unordered bool) *Session { - sessionKey := make([]byte, 32) - rand.Read(sessionKey) + var sessionKey [32]byte + rand.Read(sessionKey[:]) obfuscator, _ := GenerateObfs(0x00, sessionKey, true) seshConfig := &SessionConfig{ diff --git a/internal/server/activeuser_test.go b/internal/server/activeuser_test.go index 3abe934..559bdaf 100644 --- a/internal/server/activeuser_test.go +++ b/internal/server/activeuser_test.go @@ -11,8 +11,8 @@ import ( ) func getSeshConfig(unordered bool) *mux.SessionConfig { - sessionKey := make([]byte, 32) - rand.Read(sessionKey) + var sessionKey [32]byte + rand.Read(sessionKey[:]) obfuscator, _ := mux.GenerateObfs(0x00, sessionKey, true) seshConfig := &mux.SessionConfig{