mirror of https://github.com/cbeuw/Cloak
Add and fix some tests
This commit is contained in:
parent
e0e33e12d6
commit
237b9d131b
|
|
@ -29,7 +29,7 @@ func TestRecvNewFrame(t *testing.T) {
|
||||||
var testSorted []uint32
|
var testSorted []uint32
|
||||||
for x := 0; x < len(set); x++ {
|
for x := 0; x < len(set); x++ {
|
||||||
oct := make([]byte, 8)
|
oct := make([]byte, 8)
|
||||||
stream.sortedBuf.Write(oct)
|
stream.sortedBuf.Read(oct)
|
||||||
//log.Print(p)
|
//log.Print(p)
|
||||||
testSorted = append(testSorted, uint32(binary.BigEndian.Uint64(oct)))
|
testSorted = append(testSorted, uint32(binary.BigEndian.Uint64(oct)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package multiplex
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
"testing/quick"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestOobfs(t *testing.T) {
|
||||||
|
sessionKey := make([]byte, 32)
|
||||||
|
rand.Read(sessionKey)
|
||||||
|
obfuscator, err := GenerateObfs(0x01, sessionKey)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to generate obfuscator %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f := &Frame{}
|
||||||
|
_testFrame, _ := quick.Value(reflect.TypeOf(f), rand.New(rand.NewSource(42)))
|
||||||
|
testFrame := _testFrame.Interface().(*Frame)
|
||||||
|
obfsed, err := obfuscator.Obfs(testFrame)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("failed to obfs ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resultFrame, err := obfuscator.Deobfs(obfsed)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("failed to deobfs ", err)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(testFrame, resultFrame) {
|
||||||
|
t.Error("expecting", testFrame,
|
||||||
|
"got", resultFrame)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue