Skip to content

Commit

Permalink
Add SHIP Hello Pending Prolongation test
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Jan 3, 2024
1 parent 2497413 commit a079db6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
7 changes: 1 addition & 6 deletions ship/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,7 @@ func (c *ShipConnection) handleState(timeout bool, message []byte) {
c.handshakeHello_Init()

case SmeHelloStateReadyListen:
if timeout {
c.handshakeHello_ReadyTimeout()
return
}

c.handshakeHello_ReadyListen(message)
c.handshakeHello_ReadyListen(timeout, message)

case SmeHelloStatePendingInit:
c.handshakeHello_PendingInit()
Expand Down
7 changes: 6 additions & 1 deletion ship/hs_hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ func (c *ShipConnection) handshakeHello_Init() {
}

// SME_HELLO_STATE_READY_LISTEN
func (c *ShipConnection) handshakeHello_ReadyListen(message []byte) {
func (c *ShipConnection) handshakeHello_ReadyListen(timeout bool, message []byte) {
if timeout {
c.handshakeHello_ReadyTimeout()
return
}

var helloReturnMsg model.ConnectionHello
if err := c.processShipJsonMessage(message, &helloReturnMsg); err != nil {
c.setState(SmeHelloStateAbort, nil)
Expand Down
28 changes: 27 additions & 1 deletion ship/hs_hello_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (s *HelloSuite) Test_ReadyListen_Timeout() {
time.Sleep(tHelloInit + time.Second)
} else {
// speed up the test by running the method directly
sut.handshakeHello_ReadyTimeout()
sut.handshakeHello_ReadyListen(true, nil)
}

assert.Equal(s.T(), SmeHelloStateAbortDone, sut.getState())
Expand Down Expand Up @@ -112,6 +112,32 @@ func (s *HelloSuite) Test_ReadyListen_Ignore() {
shutdownTest(sut)
}

func (s *HelloSuite) Test_ReadyListen_Prolongation() {
sut, data := initTest(s.role)

sut.setState(SmeHelloStateReadyInit, nil) // inits the timer
sut.setState(SmeHelloStateReadyListen, nil)

data.allowWaitingForTrust = true

helloMsg := model.ConnectionHello{
ConnectionHello: model.ConnectionHelloType{
Phase: model.ConnectionHelloPhaseTypePending,
ProlongationRequest: util.Ptr(true),
},
}

msg, err := sut.shipMessage(model.MsgTypeControl, helloMsg)
assert.Nil(s.T(), err)
assert.NotNil(s.T(), msg)

sut.handleState(false, msg)

assert.Equal(s.T(), SmeHelloStateReadyListen, sut.getState())

shutdownTest(sut)
}

func (s *HelloSuite) Test_ReadyListen_Abort() {
sut, data := initTest(s.role)

Expand Down

0 comments on commit a079db6

Please sign in to comment.