test(license): cover public key validation (#2793)

This commit is contained in:
安正超
2026-05-04 23:12:59 +08:00
committed by GitHub
parent a830ab2a5d
commit 3ced40f221

View File

@@ -324,6 +324,7 @@ pub fn license_check() -> Result<()> {
#[cfg(test)]
mod tests {
use super::*;
use serial_test::serial;
#[test]
fn license_token_current_requires_future_expiration() {
@@ -336,4 +337,30 @@ mod tests {
assert!(!is_license_token_current(&token, 100));
assert!(!is_license_token_current(&token, 101));
}
#[test]
#[serial]
fn appauth_verifier_rejects_missing_public_key() {
temp_env::with_var(rustfs_config::ENV_RUSTFS_LICENSE_PUBLIC_KEY, None::<&str>, || {
assert_license_public_key_error(AppAuthLicenseVerifier.validate("signed-license", 0));
});
}
#[test]
#[serial]
fn appauth_verifier_rejects_blank_public_key() {
temp_env::with_var(rustfs_config::ENV_RUSTFS_LICENSE_PUBLIC_KEY, Some(" \t\n "), || {
assert_license_public_key_error(AppAuthLicenseVerifier.validate("signed-license", 0));
});
}
fn assert_license_public_key_error(result: LicenseResult<Token>) {
let err = result.expect_err("license verification should fail without a public key");
let LicenseError::Invalid(message) = err else {
panic!("expected invalid license error, got {err:?}");
};
assert!(message.contains(rustfs_config::ENV_RUSTFS_LICENSE_PUBLIC_KEY));
assert!(message.contains("RSA public key"));
}
}