Skip to content

Commit

Permalink
Change panic to Errorf
Browse files Browse the repository at this point in the history
  • Loading branch information
pontus committed Mar 11, 2024
1 parent 5ebb396 commit 4049375
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
23 changes: 11 additions & 12 deletions model/headers/headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func TestHeaderMarshallingWithNonce(t *testing.T) {

writerPrivateKey, err := keys.ReadPrivateKey(strings.NewReader(sshEd25519SecEnc), []byte("123123"))
if err != nil {
panic(err)
t.Errorf("Reading private key from string failed: %v", err)
}

readerPublicKey, err := keys.ReadPublicKey(strings.NewReader(crypt4ghX25519Pub))
if err != nil {
panic(err)
t.Errorf("Reading public key from string failed: %v", err)
}
var nonce = [12]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
magic := [8]byte{}
Expand Down Expand Up @@ -104,11 +104,11 @@ func TestNewHeader(t *testing.T) {
buffer := bytes.NewBuffer(decodedHeader)
readerSecretKey, err := keys.ReadPrivateKey(strings.NewReader(crypt4ghX25519Sec), []byte("password"))
if err != nil {
panic(err)
t.Errorf("Reading private key from string failed: %v", err)
}
header, err := NewHeader(buffer, readerSecretKey)
if err != nil {
panic(err)
t.Errorf("Reading public key from string failed: %v", err)
}
if fmt.Sprintf("%v", header) != "&{[99 114 121 112 116 52 103 104] 1 2 [{[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 108 0 <nil> {65564 {0} 0 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]}} {[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 100 0 <nil> {{1} 3 [1 2 3]}}]}" {
t.Fail()
Expand Down Expand Up @@ -154,12 +154,12 @@ func TestHeaderMarshallingWithoutNonce(t *testing.T) {

writerPrivateKey, err := keys.ReadPrivateKey(strings.NewReader(sshEd25519SecEnc), []byte("123123"))
if err != nil {
panic(err)
t.Errorf("Reading private key from string failed: %v", err)
}

readerPublicKey, err := keys.ReadPublicKey(strings.NewReader(crypt4ghX25519Pub))
if err != nil {
panic(err)
t.Errorf("Reading public key from string failed: %v", err)
}
magic := [8]byte{}
copy(magic[:], MagicNumber)
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestReEncryptedHeaderReplacementAndAddition(t *testing.T) {

newHeader, err := ReEncryptHeader(oldHeader, readerSecretKey, newReaderPublicKeyList, del, anotherDel)
if err != nil {
panic(err)
t.Errorf("Reencrypting header gave unexpected failure: %v", err)
}
t.Logf("Header: %v", newHeader)

Expand All @@ -297,7 +297,7 @@ func TestReEncryptedHeaderReplacementAndAddition(t *testing.T) {
buffer := bytes.NewBuffer(newHeader)
header, err := NewHeader(buffer, newReaderSecretKey)
if err != nil {
panic(err)
t.Errorf("NewHeader gave unexpected failure: %v", err)
}

newDel, ok := header.HeaderPackets[1].EncryptedHeaderPacket.(DataEditListHeaderPacket)
Expand Down Expand Up @@ -335,7 +335,7 @@ func TestReEncryptedHeaderReplacementAndAddition(t *testing.T) {
buffer = bytes.NewBuffer(newerHeader)
header, err = NewHeader(buffer, readerSecretKey)
if err != nil {
panic(err)
t.Errorf("NewHeader gave unexpected failure: %v", err)
}

newDel, ok = header.HeaderPackets[1].EncryptedHeaderPacket.(DataEditListHeaderPacket)
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestReEncryptedHeader(t *testing.T) {

newHeader, err := ReEncryptHeader(oldHeader, readerSecretKey, newReaderPublicKeyList)
if err != nil {
panic(err)
t.Errorf("ReEncryptHeader gave unexpected failure: %v", err)
}

// if the headers are similar then that is not ok
Expand All @@ -389,7 +389,7 @@ func TestReEncryptedHeader(t *testing.T) {
buffer := bytes.NewBuffer(newHeader)
header, err := NewHeader(buffer, newReaderSecretKey)
if err != nil {
panic(err)
t.Errorf("NewHeader gave unexpected failure: %v", err)
}
if fmt.Sprintf("%v", header) != "&{[99 114 121 112 116 52 103 104] 1 1 [{[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 108 0 <nil> {65564 {0} 0 [111 194 187 210 222 31 213 211 134 204 70 51 56 197 11 150 188 141 28 253 188 188 76 243 7 143 50 179 45 172 135 132]}}]}" {
t.Error(header)
Expand Down Expand Up @@ -428,5 +428,4 @@ func TestEncryptedSegmentSize(t *testing.T) {
if err == nil {
t.Errorf("EncryptedSegmentSize worked where it should fail: %v", err)
}

}
1 change: 0 additions & 1 deletion streaming/streaming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1482,5 +1482,4 @@ func TestReEncryptedHeaderReplacementAndAdditionFileRead(t *testing.T) {
t.Logf("Expected: %v", sourceBytes[:100])
t.Errorf("Unexpected data after re-encryption and del added")
}

}

0 comments on commit 4049375

Please sign in to comment.