test: add tests for DecodeMessage

This commit is contained in:
Derrick Hammer 2024-01-08 08:28:10 -05:00
parent b3a6d6ddcc
commit 61faaf5694
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 43 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package signed
import (
"bytes"
"encoding/base64"
"git.lumeweb.com/LumeWeb/libs5-go/types"
"github.com/stretchr/testify/assert"
"github.com/vmihailenco/msgpack/v5"
@ -89,3 +90,45 @@ func TestHandshakeDone_EncodeMsgpack(t *testing.T) {
})
}
}
func TestHandshakeDone_DecodeMessage_Success(t *testing.T) {
data := "xBFleGFtcGxlX2NoYWxsZW5nZQM="
h := HandshakeDone{}
dataDec, err := base64.StdEncoding.DecodeString(data)
assert.NoError(t, err)
enc := msgpack.NewDecoder(bytes.NewReader(dataDec))
err = h.DecodeMessage(enc)
assert.NoError(t, err)
assert.EqualValues(t, types.SupportedFeatures, h.supportedFeatures)
assert.EqualValues(t, []byte("example_challenge"), h.challenge)
}
func TestHandshakeDone_DecodeMessage_InvalidFeatures(t *testing.T) {
data := "xBFleGFtcGxlX2NoYWxsZW5nZSo="
h := HandshakeDone{}
dataDec, err := base64.StdEncoding.DecodeString(data)
assert.NoError(t, err)
enc := msgpack.NewDecoder(bytes.NewReader(dataDec))
err = h.DecodeMessage(enc)
assert.NotEqualValues(t, types.SupportedFeatures, h.supportedFeatures)
assert.EqualValues(t, []byte("example_challenge"), h.challenge)
}
func TestHandshakeDone_DecodeMessage_BadChallenge(t *testing.T) {
data := "xA1iYWRfY2hhbGxlbmdlAw=="
h := HandshakeDone{}
dataDec, err := base64.StdEncoding.DecodeString(data)
assert.NoError(t, err)
enc := msgpack.NewDecoder(bytes.NewReader(dataDec))
err = h.DecodeMessage(enc)
assert.EqualValues(t, types.SupportedFeatures, h.supportedFeatures)
assert.NotEqualValues(t, []byte("example_challenge"), h.challenge)
}