mse: Check that readUntil doesn't read indefinitely while synchronizing

This commit is contained in:
Matt Joiner 2015-03-18 18:16:27 +11:00
parent eb29dcec80
commit 0d5c10ef53
1 changed files with 18 additions and 0 deletions

View File

@ -2,7 +2,9 @@ package mse
import (
"bytes"
"crypto/rand"
"io"
"io/ioutil"
"net"
"sync"
@ -102,3 +104,19 @@ func BenchmarkHandshake(b *testing.B) {
allHandshakeTests(b)
}
}
type trackReader struct {
r io.Reader
n int64
}
func (me *trackReader) Read(b []byte) (n int, err error) {
n, err = me.r.Read(b)
me.n += int64(n)
return
}
func TestReceiveRandomData(t *testing.T) {
tr := trackReader{rand.Reader, 0}
ReceiveHandshake(readWriter{&tr, ioutil.Discard}, nil)
}