diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2015-10-13 13:59:46 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2015-10-13 13:59:46 +0000 |
commit | c6b59e0ae60e29e9238d3aca9fe13da883dea7f9 (patch) | |
tree | 6d72cb709765dd65f9b93995434d9b6e8bb61a9e /regress | |
parent | 3ee4ec27f23c8e64e6b52aaabb6d8626399fba16 (diff) |
Single byte read/write tests.
Diffstat (limited to 'regress')
-rw-r--r-- | regress/lib/libtls/gotls/tls_test.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/regress/lib/libtls/gotls/tls_test.go b/regress/lib/libtls/gotls/tls_test.go index 2331ec0be62..3a430924a72 100644 --- a/regress/lib/libtls/gotls/tls_test.go +++ b/regress/lib/libtls/gotls/tls_test.go @@ -118,6 +118,73 @@ func TestTLSBasic(t *testing.T) { } } +func TestTLSSingleByteReadWrite(t *testing.T) { + ts, u, caFile, err := newTestServer() + if err != nil { + t.Fatalf("Failed to start test server: %v", err) + } + defer os.Remove(caFile) + defer ts.Close() + + if err := Init(); err != nil { + t.Fatal(err) + } + + cfg, err := NewConfig() + if err != nil { + t.Fatal(err) + } + defer cfg.Free() + cfg.SetCAFile(caFile) + + tls, err := NewClient(cfg) + if err != nil { + t.Fatal(err) + } + defer tls.Free() + + t.Logf("Connecting to %s", u.Host) + + if err := tls.Connect(u.Host, ""); err != nil { + t.Fatal(err) + } + defer func() { + if err := tls.Close(); err != nil { + t.Fatalf("Close failed: %v", err) + } + }() + + for _, b := range []byte("GET / HTTP/1.0\n\n") { + n, err := tls.Write([]byte{b}) + if err != nil { + t.Fatal(err) + } + if n != 1 { + t.Fatalf("Wrote byte %v, got length %d, want 1", b, n) + } + } + + var body []byte + for { + buf := make([]byte, 1) + n, err := tls.Read(buf) + if err != nil { + t.Fatal(err) + } + if n == 0 { + break + } + if n != 1 { + t.Fatalf("Read single byte, got length %d, want 1", n) + } + body = append(body, buf...) + } + + if !strings.Contains(string(body), httpContent) { + t.Errorf("Response does not contain %q", httpContent) + } +} + func TestTLSInfo(t *testing.T) { ts, u, caFile, err := newTestServer() if err != nil { |