Skip to content

Commit a36e06d

Browse files
Copilotdsherret
andcommitted
Replace integration test with unit test for AuditResponse deserialization
Co-authored-by: dsherret <1609021+dsherret@users.noreply.github.com>
1 parent 6ec0957 commit a36e06d

File tree

8 files changed

+26
-51
lines changed

8 files changed

+26
-51
lines changed

cli/tools/pm/audit.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,3 +921,29 @@ mod socket_dev {
921921
pub alerts: Vec<FirewallAlert>,
922922
}
923923
}
924+
925+
#[cfg(test)]
926+
mod tests {
927+
use super::npm::AuditResponse;
928+
use deno_core::serde_json;
929+
930+
#[test]
931+
fn test_audit_response_deserialize_without_actions() {
932+
// Test that AuditResponse can be deserialized when the `actions` field is missing
933+
// This can happen with some npm registry responses
934+
let json = r#"{
935+
"advisories": {},
936+
"metadata": {
937+
"vulnerabilities": {
938+
"low": 0,
939+
"moderate": 0,
940+
"high": 0,
941+
"critical": 0
942+
}
943+
}
944+
}"#;
945+
let response: AuditResponse = serde_json::from_str(json).unwrap();
946+
assert!(response.actions.is_empty());
947+
assert!(response.advisories.is_empty());
948+
}
949+
}

tests/registry/npm/@denotest/no-actions-audit/1.0.0/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/registry/npm/@denotest/no-actions-audit/1.0.0/package.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/specs/audit/missing_actions_field/__test__.jsonc

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/specs/audit/missing_actions_field/audit.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/specs/audit/missing_actions_field/install.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/specs/audit/missing_actions_field/package.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/util/server/servers/npm_registry.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -524,29 +524,6 @@ fn process_npm_security_audits_body(
524524

525525
let requires_map = value.get("requires")?.as_object()?;
526526
let requires_map_keys = requires_map.keys().cloned().collect::<Vec<_>>();
527-
528-
// Test case for response without `actions` field - simulates real npm registry
529-
// behavior where actions field may be omitted
530-
if requires_map_keys.contains(&"@denotest/no-actions-audit".to_string()) {
531-
return Some(json!({
532-
"advisories": {},
533-
"muted": [],
534-
"metadata": {
535-
"vulnerabilities": {
536-
"info": 0,
537-
"low": 0,
538-
"moderate": 0,
539-
"high": 0,
540-
"critical": 0,
541-
},
542-
"dependencies": 0,
543-
"devDependencies": 0,
544-
"optionalDependencies": 0,
545-
"totalDependencies": 0
546-
}
547-
}));
548-
}
549-
550527
if requires_map_keys.contains(&"@denotest/with-vuln1".to_string()) {
551528
actions.push(get_action_for_with_vuln1());
552529
advisories.insert(101010, get_advisory_for_with_vuln1());

0 commit comments

Comments
 (0)