microsoft / security-utilities

Security utilities for key generation, string redaction, etc.
MIT License
25 stars 11 forks source link

test: fix panic in generate_and_detect_common_annotated_key_test #90

Closed rwoll closed 2 months ago

rwoll commented 2 months ago

Starting on the 1st of September, generate_and_detect_common_annotated_key_test began failing with:

---- end_to_end_tests::generate_and_detect_common_annotated_key_test stdout ----
thread 'end_to_end_tests::generate_and_detect_common_annotated_key_test' panicked at src\end_to_end_tests.rs:23:49:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

generate_common_annotated_test_key was producing Ok("") since the hard-coded test_char combined with this month happened to generate an invalid key.

The code was hitting the second branch of generate_common_annotated_test_key:

        // The HIS v2 standard requires that there be no special characters in the generated key.
        if !key.contains('+') && !key.contains('/') {
            if !long_form {
                key = key.substring(0, key.len() - 4).to_string();
            }
            return Ok(key);
        } else if test_char.is_some() {
            // We could not produce a valid test key given the current signature,
            // checksum seed, reserved bits and specified test character.
            key = String::new();
            break;
        }

This hardens the test to prevent failing as time changes.

Follow up:

No release note as product code was not changed.