Skip to content

Commit

Permalink
cmd: Unit tests for extractMaxSequenceNumber
Browse files Browse the repository at this point in the history
This commit simply adds two small unit tests for the
extractMaxSequenceNumber function. The first test covers the bug fixed
in the previous commit.

Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
  • Loading branch information
pchaigno committed Aug 28, 2023
1 parent c6cb225 commit ae0ed2a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cilium/cmd/encrypt_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,43 @@ func (s *EncryptStatusSuite) TestGetXfrmStats(c *C) {
}
c.Assert(currentCount, Equals, errCount)
}

func (s *EncryptStatusSuite) TestExtractMaxSequenceNumber(c *C) {
ipOutput := `src 10.84.1.32 dst 10.84.0.30
proto esp spi 0x00000003 reqid 1 mode tunnel
replay-window 0
mark 0x3cb23e00/0xffffff00 output-mark 0xe00/0xf00
aead rfc4106(gcm(aes)) 0x64ad37a9d8a8f20fb2e74ef6000f9d580898719f 128
anti-replay context: seq 0x0, oseq 0xc3, bitmap 0x00000000
sel src 0.0.0.0/0 dst 0.0.0.0/0
src 0.0.0.0 dst 10.84.1.32
proto esp spi 0x00000003 reqid 1 mode tunnel
replay-window 0
mark 0xd00/0xf00 output-mark 0xd00/0xf00
aead rfc4106(gcm(aes)) 0x64ad37a9d8a8f20fb2e74ef6000f9d580898719f 128
anti-replay context: seq 0x0, oseq 0x1410, bitmap 0x00000000
sel src 0.0.0.0/0 dst 0.0.0.0/0
src 10.84.1.32 dst 10.84.2.145
proto esp spi 0x00000003 reqid 1 mode tunnel
replay-window 0
mark 0x7e63e00/0xffffff00 output-mark 0xe00/0xf00
aead rfc4106(gcm(aes)) 0x64ad37a9d8a8f20fb2e74ef6000f9d580898719f 128
anti-replay context: seq 0x0, oseq 0x13e0, bitmap 0x00000000
sel src 0.0.0.0/0 dst 0.0.0.0/0`

maxSeqNumber := extractMaxSequenceNumber(ipOutput)
c.Assert(maxSeqNumber, Equals, int64(0x1410))
}

// Attempt to simulate a case where the output would be interrupted mid-sentence.
func (s *EncryptStatusSuite) TestExtractMaxSequenceNumberError(c *C) {
ipOutput := `src 10.84.1.32 dst 10.84.0.30
proto esp spi 0x00000003 reqid 1 mode tunnel
replay-window 0
mark 0x3cb23e00/0xffffff00 output-mark 0xe00/0xf00
aead rfc4106(gcm(aes)) 0x64ad37a9d8a8f20fb2e74ef6000f9d580898719f 128
anti-replay context: seq 0x0, oseq 0x`

maxSeqNumber := extractMaxSequenceNumber(ipOutput)
c.Assert(maxSeqNumber, Equals, int64(0))
}

0 comments on commit ae0ed2a

Please sign in to comment.