v2ray-core/proxy/shadowsocks/ota_test.go

38 lines
1.1 KiB
Go
Raw Normal View History

2016-02-05 10:38:45 +00:00
package shadowsocks_test
import (
"testing"
2018-11-15 09:30:03 +00:00
"github.com/google/go-cmp/cmp"
"v2ray.com/core/common"
2016-12-09 10:35:27 +00:00
"v2ray.com/core/common/buf"
2016-08-20 18:55:45 +00:00
. "v2ray.com/core/proxy/shadowsocks"
2016-02-05 10:38:45 +00:00
)
func TestNormalChunkReading(t *testing.T) {
2016-12-09 11:08:25 +00:00
buffer := buf.New()
2018-11-14 21:55:20 +00:00
buffer.Write([]byte{0, 8, 39, 228, 69, 96, 133, 39, 254, 26, 201, 70, 11, 12, 13, 14, 15, 16, 17, 18})
2016-02-05 10:38:45 +00:00
reader := NewChunkReader(buffer, NewAuthenticator(ChunkKeyGenerator(
[]byte{21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36})))
2017-11-09 21:33:15 +00:00
payload, err := reader.ReadMultiBuffer()
2018-11-15 09:30:03 +00:00
common.Must(err)
if diff := cmp.Diff(payload[0].Bytes(), []byte{11, 12, 13, 14, 15, 16, 17, 18}); diff != "" {
t.Error(diff)
}
2016-02-05 10:38:45 +00:00
}
2016-10-20 22:33:23 +00:00
func TestNormalChunkWriting(t *testing.T) {
2018-08-16 10:05:33 +00:00
buffer := buf.New()
2016-10-20 22:33:23 +00:00
writer := NewChunkWriter(buffer, NewAuthenticator(ChunkKeyGenerator(
[]byte{21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36})))
2018-08-16 10:05:33 +00:00
b := buf.New()
2018-04-19 20:56:55 +00:00
b.Write([]byte{11, 12, 13, 14, 15, 16, 17, 18})
2018-11-16 10:08:12 +00:00
common.Must(writer.WriteMultiBuffer(buf.MultiBuffer{b}))
2018-11-15 09:30:03 +00:00
if diff := cmp.Diff(buffer.Bytes(), []byte{0, 8, 39, 228, 69, 96, 133, 39, 254, 26, 201, 70, 11, 12, 13, 14, 15, 16, 17, 18}); diff != "" {
t.Error(diff)
}
2016-10-20 22:33:23 +00:00
}