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"
|
|
|
|
"v2ray.com/core/testing/assert"
|
2016-02-05 05:38:45 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNormalChunkReading(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2016-02-05 05:38:45 -05:00
|
|
|
|
2016-12-09 05:35:27 -05:00
|
|
|
buffer := buf.NewBuffer()
|
2016-12-06 05:03:42 -05:00
|
|
|
buffer.AppendBytes(
|
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})))
|
|
|
|
payload, err := reader.Read()
|
|
|
|
assert.Error(err).IsNil()
|
2016-12-05 09:19:14 -05:00
|
|
|
assert.Bytes(payload.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) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
2016-12-09 05:35:27 -05:00
|
|
|
buffer := buf.NewLocalBuffer(512)
|
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})))
|
|
|
|
|
2016-12-09 05:35:27 -05:00
|
|
|
b := buf.NewLocalBuffer(256)
|
2016-12-06 05:03:42 -05:00
|
|
|
b.Append([]byte{11, 12, 13, 14, 15, 16, 17, 18})
|
|
|
|
err := writer.Write(b)
|
2016-10-20 18:33:23 -04:00
|
|
|
assert.Error(err).IsNil()
|
2016-12-05 09:19:14 -05:00
|
|
|
assert.Bytes(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
|
|
|
}
|