Repository navigation
Repair CI workflow pins, lint violations, and scanner fixtures #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -666,10 +666,8 @@ | |
| /// Evaluate a gating request and return a decision | ||
| pub fn evaluate(&self, request: &GatingRequest) -> Result<GatingDecision, ContractError> { | ||
| let start = std::time::Instant::now(); | ||
| let mut stages_executed = Vec::new(); | ||
|
|
||
| // Stage 1: Oracle evaluation | ||
| stages_executed.push("oracle".to_string()); | ||
| let stages_executed = vec!["oracle".to_string()]; | ||
| let oracle_eval = self.oracle.check_proposal(&request.proposal)?; | ||
|
|
||
| // Determine verdict based on oracle result | ||
|
|
@@ -1415,9 +1413,11 @@ | |
| Custom(String), | ||
| } | ||
|
|
||
| impl RedTeamCategory { | ||
| pub fn from_str(s: &str) -> Self { | ||
| match s.to_lowercase().as_str() { | ||
| impl std::str::FromStr for RedTeamCategory { | ||
| type Err = std::convert::Infallible; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| Ok(match s.to_lowercase().as_str() { | ||
| "documentation_bypass" | "doc_bypass" | "comment_bypass" => { | ||
| RedTeamCategory::DocumentationBypass | ||
| } | ||
|
|
@@ -1430,7 +1430,7 @@ | |
| "secret_hiding" | "secret_splitting" => RedTeamCategory::SecretEvasion, | ||
| "false_positive_avoidance" | "false_positive" => RedTeamCategory::FalsePositiveCheck, | ||
| other => RedTeamCategory::Custom(other.to_string()), | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1565,7 +1565,7 @@ | |
| let runner = ContractRunner::new(); | ||
| let request = GatingRequest::new(create_proposal( | ||
| "config.rs", | ||
| r#"let password = "supersecret123456""#, // scanner-allow: rust-secrets | ||
| r#"let password = "supersecret123456""#, // scanner-allow: rust-secrets | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you fix this stuff if it needs it, but I mean whatever you do here - is it about putting an exclusion in or is it something else (I realise now it's just a fake one) |
||
| )); | ||
|
|
||
| let decision = runner.evaluate(&request).unwrap(); | ||
|
|
@@ -1666,8 +1666,14 @@ | |
|
|
||
| #[test] | ||
| fn test_refusal_category_display() { | ||
| assert_eq!(RefusalCategory::ForbiddenLanguage.display_name(), "Forbidden Language"); | ||
| assert_eq!(RefusalCategory::SecurityViolation.display_name(), "Security Violation"); | ||
| assert_eq!( | ||
| RefusalCategory::ForbiddenLanguage.display_name(), | ||
| "Forbidden Language" | ||
| ); | ||
| assert_eq!( | ||
| RefusalCategory::SecurityViolation.display_name(), | ||
| "Security Violation" | ||
| ); | ||
| assert_eq!(RefusalCategory::SystemError.display_name(), "System Error"); | ||
| } | ||
|
|
||
|
|
@@ -1682,9 +1688,18 @@ | |
|
|
||
| #[test] | ||
| fn test_refusal_category_severity() { | ||
| assert_eq!(RefusalCategory::SecurityViolation.severity(), Severity::Critical); | ||
| assert_eq!(RefusalCategory::ForbiddenLanguage.severity(), Severity::Critical); | ||
| assert_eq!(RefusalCategory::ForbiddenToolchain.severity(), Severity::High); | ||
| assert_eq!( | ||
| RefusalCategory::SecurityViolation.severity(), | ||
| Severity::Critical | ||
| ); | ||
| assert_eq!( | ||
| RefusalCategory::ForbiddenLanguage.severity(), | ||
| Severity::Critical | ||
| ); | ||
| assert_eq!( | ||
| RefusalCategory::ForbiddenToolchain.severity(), | ||
| Severity::High | ||
| ); | ||
| assert_eq!(RefusalCategory::VerbositySmell.severity(), Severity::Low); | ||
| } | ||
|
|
||
|
|
@@ -1705,8 +1720,7 @@ | |
| ..Default::default() | ||
| }; | ||
|
|
||
| let request = GatingRequest::new(proposal.clone()) | ||
| .with_context(context.clone()); | ||
| let request = GatingRequest::new(proposal.clone()).with_context(context.clone()); | ||
|
|
||
| assert_eq!(request.context.source, "test"); | ||
| assert_eq!(request.context.session_id, Some("session-123".to_string())); | ||
|
|
@@ -1715,40 +1729,38 @@ | |
| #[test] | ||
| fn test_refusal_with_evidence() { | ||
| let runner = ContractRunner::new(); | ||
| let request = GatingRequest::new(create_proposal( | ||
| "main.ts", | ||
| "const x: string = 'hello';", | ||
| )); | ||
| let request = GatingRequest::new(create_proposal("main.ts", "const x: string = 'hello';")); | ||
|
|
||
| let decision = runner.evaluate(&request).unwrap(); | ||
| assert!(decision.refusal.is_some()); | ||
|
|
||
| let refusal = decision.refusal.unwrap(); | ||
| assert!(!refusal.evidence.is_empty()); | ||
| assert_eq!(refusal.evidence[0].evidence_type, EvidenceType::ContentMarker); | ||
| assert_eq!( | ||
| refusal.evidence[0].evidence_type, | ||
| EvidenceType::ContentMarker | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_python_forbidden_with_remediation() { | ||
| let runner = ContractRunner::new(); | ||
| let request = GatingRequest::new(create_proposal( | ||
| "script.py", | ||
| "import os", | ||
| )); | ||
| let request = GatingRequest::new(create_proposal("script.py", "import os")); | ||
|
|
||
| let decision = runner.evaluate(&request).unwrap(); | ||
| let refusal = decision.refusal.unwrap(); | ||
| assert!(refusal.remediation.is_some()); | ||
| assert!(refusal.remediation.unwrap().contains("only allowed in salt")); | ||
| assert!(refusal | ||
| .remediation | ||
| .unwrap() | ||
| .contains("only allowed in salt")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_go_forbidden_with_rust_remediation() { | ||
| let runner = ContractRunner::new(); | ||
| let request = GatingRequest::new(create_proposal( | ||
| "main.go", | ||
| "package main\nfunc main() {}", | ||
| )); | ||
| let request = | ||
| GatingRequest::new(create_proposal("main.go", "package main\nfunc main() {}")); | ||
|
|
||
| let decision = runner.evaluate(&request).unwrap(); | ||
| let refusal = decision.refusal.unwrap(); | ||
|
|
@@ -1763,7 +1775,10 @@ | |
| let request = GatingRequest::new(create_proposal("lib.rs", "pub fn foo() {}")); | ||
|
|
||
| let decision = runner.evaluate(&request).unwrap(); | ||
| assert!(decision.processing.stages_executed.contains(&"oracle".to_string())); | ||
| assert!(decision | ||
| .processing | ||
| .stages_executed | ||
| .contains(&"oracle".to_string())); | ||
| assert!(decision.evaluations.oracle.is_some()); | ||
| } | ||
|
|
||
|
|
@@ -1961,28 +1976,49 @@ | |
|
|
||
| #[test] | ||
| fn test_red_team_category_from_str() { | ||
| assert_eq!(RedTeamCategory::from_str("doc_bypass"), RedTeamCategory::DocumentationBypass); | ||
| assert_eq!(RedTeamCategory::from_str("marker_obfuscation"), RedTeamCategory::MarkerObfuscation); | ||
| assert_eq!(RedTeamCategory::from_str("encoding"), RedTeamCategory::EncodedContent); | ||
| assert_eq!(RedTeamCategory::from_str("boundary"), RedTeamCategory::BoundaryCondition); | ||
| assert_eq!(RedTeamCategory::from_str("polyglot"), RedTeamCategory::ContentInjection); | ||
| assert_eq!(RedTeamCategory::from_str("secret_hiding"), RedTeamCategory::SecretEvasion); | ||
| assert_eq!(RedTeamCategory::from_str("false_positive"), RedTeamCategory::FalsePositiveCheck); | ||
| assert_eq!( | ||
| "doc_bypass".parse::<RedTeamCategory>().unwrap(), | ||
| RedTeamCategory::DocumentationBypass | ||
| ); | ||
| assert_eq!( | ||
| "marker_obfuscation".parse::<RedTeamCategory>().unwrap(), | ||
| RedTeamCategory::MarkerObfuscation | ||
| ); | ||
| assert_eq!( | ||
| "encoding".parse::<RedTeamCategory>().unwrap(), | ||
| RedTeamCategory::EncodedContent | ||
| ); | ||
| assert_eq!( | ||
| "boundary".parse::<RedTeamCategory>().unwrap(), | ||
| RedTeamCategory::BoundaryCondition | ||
| ); | ||
| assert_eq!( | ||
| "polyglot".parse::<RedTeamCategory>().unwrap(), | ||
| RedTeamCategory::ContentInjection | ||
| ); | ||
| assert_eq!( | ||
| "secret_hiding".parse::<RedTeamCategory>().unwrap(), | ||
| RedTeamCategory::SecretEvasion | ||
| ); | ||
| assert_eq!( | ||
| "false_positive".parse::<RedTeamCategory>().unwrap(), | ||
| RedTeamCategory::FalsePositiveCheck | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_elixir_compliant() { | ||
| let runner = ContractRunner::new(); | ||
| // Elixir with .ex extension and defmodule marker | ||
| let request = GatingRequest::new(create_proposal( | ||
| "app.ex", | ||
| "defmodule MyModule, do: :ok", | ||
| )); | ||
| let request = GatingRequest::new(create_proposal("app.ex", "defmodule MyModule, do: :ok")); | ||
|
|
||
| let decision = runner.evaluate(&request).unwrap(); | ||
| // Should be allowed as tier1 language | ||
| assert!(matches!(decision.verdict, Verdict::Allow), | ||
| "Elixir should be allowed, got {:?}", decision.verdict); | ||
| assert!( | ||
| matches!(decision.verdict, Verdict::Allow), | ||
| "Elixir should be allowed, got {:?}", | ||
| decision.verdict | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
|
|
@@ -2050,11 +2086,12 @@ | |
| #[test] | ||
| fn test_npm_with_deno_allowed() { | ||
| let runner = ContractRunner::new(); | ||
| let mut request = GatingRequest::new(create_proposal( | ||
| "package.json", | ||
| r#"{"name": "test"}"#, | ||
| )); | ||
| request.proposal.files_affected.push("deno.json".to_string()); | ||
| let mut request = | ||
| GatingRequest::new(create_proposal("package.json", r#"{"name": "test"}"#)); | ||
| request | ||
| .proposal | ||
| .files_affected | ||
| .push("deno.json".to_string()); | ||
|
|
||
| let decision = runner.evaluate(&request).unwrap(); | ||
| assert_eq!(decision.verdict, Verdict::Allow); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay this needs to be fixed right away