veraison / go-cose

go library for CBOR Object Signing and Encryption (COSE)
Mozilla Public License 2.0
49 stars 26 forks source link

Fix intermittent failures in headers tests #145

Closed setrofim closed 1 year ago

setrofim commented 1 year ago

Split the "iv and partial iv present" test case into separate "iv present" and "partial iv present" cases in headers test.

The issue is that validateHeaderParameters takes a map of extracted header parameters and range's over them, validating each one. Ranging over maps in Go does not guarantee a stable order.

This meant that ether the "IV" or the "Partial IV" parameter could be checked first in the "iv and partial iv present" test case, resulting in different errors being reported on different runs.

The test harness only allows specifying one expected error, so when the order of the header params map iteration switched, the actual and expected errors didn't match resulting in test failure.

One way to fix it would be sort map values before iterating over them, however that would be an unnecessary overhead, since the order only matters in the context of the test (where a specific error is expected).

Therefore, the alternative solution is to split the test case into two, with only one possible error resulting from each.

codecov[bot] commented 1 year ago

Codecov Report

Merging #145 (eb97d7e) into main (bfa9f54) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #145   +/-   ##
=======================================
  Coverage   92.77%   92.77%           
=======================================
  Files          10       10           
  Lines        1024     1024           
=======================================
  Hits          950      950           
  Misses         49       49           
  Partials       25       25           

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more