ax(ueps): replace prose claim with usage-example comment in MarshalAndSign_Ugly
TestPacket_MarshalAndSign_Ugly commented "modifying any byte breaks HMAC verification" (prose description) but never called ReadAndVerify to prove it. Replaced with a usage-example comment and an actual ReadAndVerify call that asserts errIntegrityViolation is returned — AX Principle 2. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
cc829d1bc8
commit
11cbfd5107
1 changed files with 7 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package ueps
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -117,7 +118,9 @@ func TestPacket_MarshalAndSign_Bad(t *testing.T) {
|
|||
}
|
||||
|
||||
// frame, _ := builder.MarshalAndSign(secret)
|
||||
// corrupted[len(frame)-1] ^= 0xFF // modifying any byte breaks HMAC verification
|
||||
// corrupted[len(frame)-1] ^= 0xFF
|
||||
// _, err := ReadAndVerify(bufio.NewReader(bytes.NewReader(corrupted)), secret)
|
||||
// // err == errIntegrityViolation (HMAC mismatch detected)
|
||||
func TestPacket_MarshalAndSign_Ugly(t *testing.T) {
|
||||
builder := NewBuilder(0x03, []byte("sensitive"))
|
||||
sharedSecret := []byte("my-secret")
|
||||
|
|
@ -132,8 +135,9 @@ func TestPacket_MarshalAndSign_Ugly(t *testing.T) {
|
|||
copy(corrupted, frame)
|
||||
corrupted[len(corrupted)-1] ^= 0xFF
|
||||
|
||||
if bytes.Equal(frame, corrupted) {
|
||||
t.Error("expected corrupted frame to differ from original")
|
||||
_, verifyError := ReadAndVerify(bufio.NewReader(bytes.NewReader(corrupted)), sharedSecret)
|
||||
if verifyError == nil {
|
||||
t.Error("expected HMAC integrity violation for corrupted frame, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue