1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/proxy/shadowsocks/ota_test.go

37 lines
1.1 KiB
Go
Raw Normal View History

2016-02-05 05:38:45 -05:00
package shadowsocks_test
import (
"testing"
2016-12-09 05:35:27 -05:00
"v2ray.com/core/common/buf"
2016-08-20 14:55:45 -04:00
. "v2ray.com/core/proxy/shadowsocks"
2017-10-24 10:15:35 -04:00
. "v2ray.com/ext/assert"
2016-02-05 05:38:45 -05:00
)
func TestNormalChunkReading(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2016-02-05 05:38:45 -05:00
2016-12-09 06:08:25 -05:00
buffer := buf.New()
2018-07-30 16:45:06 -04:00
buffer.WriteBytes(
2016-02-05 05:38:45 -05:00
0, 8, 39, 228, 69, 96, 133, 39, 254, 26, 201, 70, 11, 12, 13, 14, 15, 16, 17, 18)
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 16:33:15 -05:00
payload, err := reader.ReadMultiBuffer()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(payload[0].Bytes(), Equals, []byte{11, 12, 13, 14, 15, 16, 17, 18})
2016-02-05 05:38:45 -05:00
}
2016-10-20 18:33:23 -04:00
func TestNormalChunkWriting(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2016-10-20 18:33:23 -04:00
2018-08-16 06:05:33 -04:00
buffer := buf.New()
2016-10-20 18:33:23 -04: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 06:05:33 -04:00
b := buf.New()
2018-04-19 16:56:55 -04:00
b.Write([]byte{11, 12, 13, 14, 15, 16, 17, 18})
2017-11-09 16:33:15 -05:00
err := writer.WriteMultiBuffer(buf.NewMultiBufferValue(b))
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(buffer.Bytes(), Equals, []byte{0, 8, 39, 228, 69, 96, 133, 39, 254, 26, 201, 70, 11, 12, 13, 14, 15, 16, 17, 18})
2016-10-20 18:33:23 -04:00
}