fix another test

This commit is contained in:
idk
2022-01-09 12:45:50 -05:00
parent a87847ef51
commit d9543745a4
3 changed files with 24 additions and 10 deletions

4
.vscode/launch.json vendored
View File

@ -3,5 +3,7 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
"configurations": [
]
}

View File

@ -259,9 +259,19 @@ func ReadKeysAndCert(data []byte) (keys_and_cert KeysAndCert, remainder []byte,
"reason": "not enough data",
}).Error("error parsing keys and cert")
err = errors.New("error parsing KeysAndCert: data is smaller than minimum valid size")
// return
return
}
cert, remainder, err := ReadCertificate(data[KEYS_AND_CERT_DATA_SIZE:])
if err != nil {
log.WithFields(log.Fields{
"at": "ReadKeysAndCert",
"data_len": data_len,
"required_len": KEYS_AND_CERT_MIN_SIZE,
"reason": "error parsing certificate",
}).Error("error parsing keys and cert")
err = errors.New("error parsing KeysAndCert: error parsing certificate")
return
}
keys_and_cert.CertificateInterface = cert
spk, pk, remainder, err := ReadKeys(data, cert)
keys_and_cert.SigningPublicKey = spk

View File

@ -1,30 +1,32 @@
package common
import (
"github.com/stretchr/testify/assert"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCertificateWithMissingData(t *testing.T) {
assert := assert.New(t)
cert_data := []byte{0x05, 0x00, 0x04, 0x00, 0x01}
//cert_data := []byte{0x05, 0x00, 0x04, 0x00, 0x01}
data := make([]byte, 128+256)
data = append(data, cert_data...)
keys_and_cert, _, err := ReadKeysAndCert(data)
//data = append(data, cert_data...)
keys_and_cert, remainder, err := ReadKeysAndCert(data)
if assert.NotNil(err) {
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
}
t.Log("\n\nREMAINDER", remainder, "\n\n")
cert, err := keys_and_cert.GetCertificate()
t.Log("\n\nSTART\n\n")
if assert.NotNil(err) {
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
}else{
} else {
t.Log("\n\nEND\n\n", cert.Cert())
}
// cert_bytes := []byte(cert.Cert())
// cert_bytes := []byte(cert.Cert())
// if assert.Equal(len(cert_data), len(cert_bytes)) {
// assert.Equal(cert_bytes, cert_data, "keys_and_cert.GetCertificate() did not return available data when cert was missing some data")
// assert.Equal(cert_bytes, cert_data, "keys_and_cert.GetCertificate() did not return available data when cert was missing some data")
// }
}