Skip to content

Commit

Permalink
Add TestAssocAbort
Browse files Browse the repository at this point in the history
Add test to assert that sending an abort takes the assocation
to closed.
  • Loading branch information
Sean-Der committed Feb 1, 2020
1 parent 807f7b9 commit 5bce07a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
34 changes: 34 additions & 0 deletions association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,40 @@ func TestAssocReset(t *testing.T) {
})
}

func TestAssocAbort(t *testing.T) {
const si uint16 = 1
const msg = "ABC"
br := test.NewBridge()

a0, a1, err := createNewAssociationPair(br, ackModeNoDelay, 0)
assert.NoError(t, err)

abort := &chunkAbort{
errorCauses: []errorCause{&errorCauseProtocolViolation{
errorCauseHeader: errorCauseHeader{code: protocolViolation},
}},
}
packet, err := a0.createPacket([]chunk{abort}).marshal()
assert.NoError(t, err)

_, _, err = establishSessionPair(br, a0, a1, si)
assert.NoError(t, err)

// Both associations are established
assert.Equal(t, established, a0.getState())
assert.Equal(t, established, a1.getState())

_, err = a0.netConn.Write(packet)
assert.NoError(t, err)
br.Process()

// The receiving association should be closed because it got an ABORT
assert.Equal(t, established, a0.getState())
assert.Equal(t, closed, a1.getState())

closeAssociationPair(br, a0, a1)
}

type fakeEchoConn struct {
echo chan []byte
done chan struct{}
Expand Down
12 changes: 11 additions & 1 deletion chunk_abort.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ func (a *chunkAbort) unmarshal(raw []byte) error {
return nil
}
func (a *chunkAbort) marshal() ([]byte, error) {
return nil, errors.Errorf("Unimplemented")
a.chunkHeader.typ = ctAbort
a.flags = 0x00
a.raw = []byte{}
for _, ec := range a.errorCauses {
raw, err := ec.marshal()
if err != nil {
return nil, err
}
a.raw = append(a.raw, raw...)
}
return a.chunkHeader.marshal()
}

func (a *chunkAbort) check() (abort bool, err error) {
Expand Down

0 comments on commit 5bce07a

Please sign in to comment.