github.com/metacubex/mihomo@v1.18.5/transport/hysteria/obfs/xplus_test.go (about) 1 package obfs 2 3 import ( 4 "bytes" 5 "testing" 6 ) 7 8 func TestXPlusObfuscator(t *testing.T) { 9 x := NewXPlusObfuscator([]byte("Vaundy")) 10 tests := []struct { 11 name string 12 p []byte 13 }{ 14 {name: "1", p: []byte("HelloWorld")}, 15 {name: "2", p: []byte("Regret is just a horrible attempt at time travel that ends with you feeling like crap")}, 16 {name: "3", p: []byte("To be, or not to be, that is the question:\nWhether 'tis nobler in the mind to suffer\n" + 17 "The slings and arrows of outrageous fortune,\nOr to take arms against a sea of troubles\n" + 18 "And by opposing end them. To die—to sleep,\nNo more; and by a sleep to say we end")}, 19 {name: "empty", p: []byte("")}, 20 } 21 for _, tt := range tests { 22 t.Run(tt.name, func(t *testing.T) { 23 buf := make([]byte, 10240) 24 n := x.Obfuscate(tt.p, buf) 25 n2 := x.Deobfuscate(buf[:n], buf[n:]) 26 if !bytes.Equal(tt.p, buf[n:n+n2]) { 27 t.Errorf("Inconsistent deobfuscate result: got %v, want %v", buf[n:n+n2], tt.p) 28 } 29 }) 30 } 31 }