Skip to content

Commit

Permalink
feat: Adds typo plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Chernicoff committed Oct 30, 2024
1 parent 186ca5d commit a062841
Show file tree
Hide file tree
Showing 16 changed files with 1,432 additions and 16 deletions.
18 changes: 17 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ members = [
"plugins/entropy",
"plugins/linguist",
"plugins/review",
"plugins/binary"
, "plugins/identity"]
"plugins/binary",
"plugins/identity",
"plugins/typo"]

# Make sure Hipcheck is run with `cargo run`.
#
Expand Down
4 changes: 2 additions & 2 deletions config/Hipcheck.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
plugin "mitre/binary" version="0.1.0"
plugin "mitre/fuzz" version="0.1.0" manifest="./plugins/fuzz/plugin.kdl"
plugin "mitre/review" version="0.1.0"
plugin "mitre/typo" version="0.1.0"
plugin "mitre/typo" version="0.1.0" manifest="./plugins/typo/plugin.kdl"
plugin "mitre/affiliation" version="0.1.0"
plugin "mitre/entropy" version="0.1.0"
plugin "mitre/churn" version="0.1.0"
Expand All @@ -28,7 +28,7 @@ analyze {
}

category "attacks" {
analysis "mitre/typo" policy="(eq 0 (count $))" {
analysis "mitre/typo" policy="(lte (count (filter (eq #t) $)) 0) {
typo-file "./config/Typos.toml"
}

Expand Down
5 changes: 1 addition & 4 deletions hipcheck/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ fn default_query_explanation(
let core = db.core();
let key = get_plugin_key(publisher.as_str(), plugin.as_str());
let Some(p_handle) = core.plugins.get(&key) else {
return Err(hc_error!(
"Plugin '{}' not found",
key,
));
return Err(hc_error!("Plugin '{}' not found", key,));
};
Ok(p_handle.get_default_query_explanation().cloned())
}
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/plugin/retrieval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ use xz2::read::XzDecoder;
use super::get_current_arch;

/// The plugins currently are not delegated via the `plugin` system and are still part of `hipcheck` core
pub const MITRE_LEGACY_PLUGINS: [&str; 6] = [
pub const MITRE_LEGACY_PLUGINS: [&str; 5] = [
"activity",
"entropy",
"affiliation",
"binary",
"churn",
"typo",
];

/// determine all of the plugins that need to be run and locate download them, if they do not exist
Expand Down
3 changes: 1 addition & 2 deletions plugins/affiliation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ strum = { version = "0.26.3", features = ["derive"] }
tokio = { version = "1.40.0", features = ["rt"] }

[dev-dependencies]
hipcheck-sdk = { path = "../../sdk/rust", features = ["macros", "mock_engine"]}
test-log = "0.2.16"
hipcheck-sdk = { path = "../../sdk/rust", features = ["macros", "mock_engine"]}
4 changes: 1 addition & 3 deletions plugins/affiliation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ mod test {

use pathbuf::pathbuf;
use std::{env, result::Result as StdResult};
use test_log::test;

fn repo() -> LocalGitRepo {
LocalGitRepo {
path: "/home/users/me/.cache/hipcheck/clones/github/foo/bar/".to_string(),
Expand Down Expand Up @@ -547,7 +545,7 @@ mod test {
Ok(mock_responses)
}

#[test(tokio::test)]
#[tokio::test]
async fn test_affiliation() {
let orgs_file = pathbuf![&env::current_dir().unwrap(), "test", "example_orgs.kdl"];
let orgs_spec = OrgSpec::load_from(&orgs_file).unwrap();
Expand Down
10 changes: 10 additions & 0 deletions plugins/npm_dependencies/plugin.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
publisher "mitre"
name "npm_dependencies"
version "0.1.0"
license "Apache-2.0"
entrypoint {
on arch="aarch64-apple-darwin" "./target/debug/npm_dependencies_sdk"
on arch="x86_64-apple-darwin" "./target/debug/npm_dependencies_sdk"
on arch="x86_64-unknown-linux-gnu" "./target/debug/npm_dependencies_sdk"
on arch="x86_64-pc-windows-msvc" "./target/debug/npm_dependencies_sdk"
}
22 changes: 22 additions & 0 deletions plugins/typo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "typo_sdk"
version = "0.1.0"
license = "Apache-2.0"
edition = "2021"
publish = false

[dependencies]
anyhow = "1.0.91"
clap = { version = "4.5.18", features = ["derive"] }
hipcheck-sdk = { path = "../../sdk/rust", features = ["macros"] }
log = "0.4.22"
maplit = "1.0.2"
pathbuf = "1.0.0"
serde = { version = "1.0.210", features = ["derive", "rc"] }
serde_json = "1.0.128"
tokio = { version = "1.40.0", features = ["rt"] }
toml = "0.8.19"
url = "2.5.2"

[dev-dependencies]
hipcheck-sdk = { path = "../../sdk/rust", features = ["mock_engine"] }
13 changes: 13 additions & 0 deletions plugins/typo/plugin.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
publisher "mitre"
name "typo"
version "0.1.0"
license "Apache-2.0"
entrypoint {
on arch="aarch64-apple-darwin" "./target/debug/typo_sdk"
on arch="x86_64-apple-darwin" "./target/debug/typo_sdk"
on arch="x86_64-unknown-linux-gnu" "./target/debug/typo_sdk"
on arch="x86_64-pc-windows-msvc" "./target/debug/typo_sdk"
}
dependencies {
plugin "mitre/npm_dependencies" version="0.1.0" manifest="./plugins/npm_dependencies/plugin.kdl"
}
Loading

0 comments on commit a062841

Please sign in to comment.