set fail-fast and get the rest of these tests

This commit is contained in:
idk
2021-07-28 08:09:30 -04:00
parent 3f4d02dc3e
commit 27547611ed
5 changed files with 24 additions and 14 deletions

View File

@ -19,7 +19,7 @@ $(EXE):
$(GO) build -v -o $(EXE)
test:
$(GO) test ./...
$(GO) test -failfast ./...
clean:
$(GO) clean -v

View File

@ -156,7 +156,8 @@ func (certificate Certificate) Data() (data []byte, err error) {
// Read a Certificate from a slice of bytes, returning any extra data on the end of the slice
// and any errors if a valid Certificate could not be read.
//
func ReadCertificate(data []byte) (certificate Certificate, remainder []byte, err error) {
func ReadCertificate(data []byte) (certificate *Certificate, remainder []byte, err error) {
certificate = &Certificate{}
certificate.CertType, err = NewInteger(data[0:1])
certificate.CertLen = &Integer{}
cert_len := len(data)

View File

@ -79,7 +79,7 @@ const (
)
type KeyCertificate struct {
Certificate
CertificateInterface
PKType *Integer
PKExtra []byte
SPKType *Integer
@ -91,7 +91,7 @@ type KeyCertificate struct {
//
func (key_certificate KeyCertificate) Data() ([]byte, error) {
var r []byte
r = append(r, key_certificate.Certificate.Cert()...)
r = append(r, key_certificate.CertificateInterface.Cert()...)
r = append(r, key_certificate.PKType.Bytes()...)
r = append(r, key_certificate.SPKType.Bytes()...)
return r, nil
@ -103,7 +103,7 @@ func (key_certificate KeyCertificate) Data() ([]byte, error) {
//
func (key_certificate KeyCertificate) SigningPublicKeyType() (signing_pubkey_type int, err error) {
// signing_key_type := key_certificate.SPKType
// data_len := len(key_certificate.Certificate.CertBytes)
// data_len := len(key_certificate.CertificateInterface.CertBytes)
if len(key_certificate.SPKType.Bytes()) < 2 {
log.WithFields(log.Fields{
"at": "(KeyCertificate) SingingPublicKeyType",
@ -263,7 +263,7 @@ func ReadKeyCertificate(data []byte) (key_certificate KeyCertificate, err error)
return
}
log.Println("KEYSANDCERT CERT TYPE=", cert_type, cert.CertBytes)
key_certificate.Certificate = cert
key_certificate.CertificateInterface = cert
data = cert.CertBytes
data_len := len(data)
if data_len < 2 {

View File

@ -137,7 +137,7 @@ func (keys_and_cert KeysAndCert) GetSigningPublicKey() (signing_public_key crypt
// KeysAndCert or Certificate.
//
func (keys_and_cert KeysAndCert) GetCertificate() (cert CertificateInterface, err error) {
data_len := len(keys_and_cert.Bytes())
data_len := len(keys_and_cert.Cert())
if data_len < KEYS_AND_CERT_MIN_SIZE {
log.WithFields(log.Fields{
"at": "ReadKeysAndCert",
@ -145,7 +145,16 @@ func (keys_and_cert KeysAndCert) GetCertificate() (cert CertificateInterface, er
"required_len": KEYS_AND_CERT_MIN_SIZE,
"reason": "not enough data",
}).Error("error parsing keys and cert")
err = errors.New("error parsing KeysAndCert: data is smaller than minimum valid size")
err = errors.New("certificate parsing warning: certificate data is shorter than specified by length")
}
if data_len > KEYS_AND_CERT_MIN_SIZE {
log.WithFields(log.Fields{
"at": "ReadKeysAndCert",
"data_len": data_len,
"required_len": KEYS_AND_CERT_MIN_SIZE,
"reason": "too much data",
}).Error("error parsing keys and cert")
err = errors.New("certificate parsing warning: certificate data is longer than specified by length")
}
cert = keys_and_cert.CertificateInterface
return
@ -245,17 +254,17 @@ 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_MIN_SIZE])
cert, remainder, err := ReadCertificate(data[KEYS_AND_CERT_DATA_SIZE:])
if err != nil {
//return
log.Error("ERROR READ CERTIFICATE", err)
err = nil
}
log.Println("READ CERTIFICATE")
keys_and_cert.CertificateInterface = &cert
log.Println("READ CERTIFICATE", cert.Cert())
keys_and_cert.CertificateInterface = cert
spk, pk, remainder, err := ReadKeys(data, cert)
if err != nil {
// return

View File

@ -18,9 +18,9 @@ func TestCertificateWithMissingData(t *testing.T) {
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
}
cert_bytes := []byte(cert.Cert())
if assert.Equal(len(cert_data), len(cert_bytes)) {
// 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")
}
// }
}
func TestCertificateWithValidData(t *testing.T) {