Skip to content

Commit

Permalink
Fix typing for alertErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt authored and MarcoPolo committed May 2, 2024
1 parent 24571ec commit 634f1fe
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 10 deletions.
18 changes: 8 additions & 10 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,13 +626,12 @@ func (c *Conn) readAndBuffer(ctx context.Context) error {
}

var e *alertError
if errors.As(err, &e) {
if e.IsFatalOrCloseNotify() {
return e
}
} else if err != nil {
if errors.As(err, &e) && e.IsFatalOrCloseNotify() {
return e
}
if err != nil {
return err
}
}
if hasHandshake {
done := make(chan struct{})
Expand Down Expand Up @@ -661,13 +660,12 @@ func (c *Conn) handleQueuedPackets(ctx context.Context) error {
}
}
var e *alertError
if errors.As(err, &e) {
if e.IsFatalOrCloseNotify() {
return e
}
} else if err != nil {
if errors.As(err, &e) && e.IsFatalOrCloseNotify() {
return e
}
if err != nil {
return err
}
}
return nil
}
Expand Down
50 changes: 50 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3135,3 +3135,53 @@ func TestApplicationDataQueueLimited(t *testing.T) {
ca.Close()
<-done
}

func TestApplicationDataWithClientHelloRejected(t *testing.T) {
// Limit runtime in case of deadlocks
lim := test.TimeOut(time.Second * 20)
defer lim.Stop()

// Check for leaking routines
report := test.CheckRoutines(t)
defer report()

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

ca, cb := dpipe.Pipe()
defer ca.Close()
defer cb.Close()

done := make(chan struct{})
go func() {
if _, err := testServer(ctx, cb, &Config{}, true); err == nil {
t.Error("expected handshake to fail")
}
close(done)
}()
extensions := []extension.Extension{}

time.Sleep(50 * time.Millisecond)

err := sendClientHello([]byte{}, ca, 0, extensions)
if err != nil {
t.Fatal(err)
}

// Send an application data packet
packet, err := (&recordlayer.RecordLayer{
Header: recordlayer.Header{
Version: protocol.Version1_2,
SequenceNumber: uint64(3),
Epoch: 0,
},
Content: &protocol.ApplicationData{
Data: []byte{1, 2, 3, 4},
},
}).Marshal()
if err != nil {
t.Fatal(err)
}
ca.Write(packet)
<-done
}

0 comments on commit 634f1fe

Please sign in to comment.