diff --git a/Cargo.lock b/Cargo.lock index 966793f..e79c8dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -197,9 +197,9 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.1" +version = "2.33.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" +checksum = "10040cdf04294b565d9e0319955430099ec3813a64c952b86a41200ad714ae48" dependencies = [ "ansi_term 0.11.0", "atty", @@ -234,9 +234,9 @@ dependencies = [ [[package]] name = "console" -version = "0.11.3" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c0994e656bba7b922d8dd1245db90672ffb701e684e45be58f20719d69abc5a" +checksum = "c0b1aacfaffdbff75be81c15a399b4bedf78aaefe840e8af1d299ac2ade885d2" dependencies = [ "encode_unicode", "lazy_static", @@ -363,9 +363,9 @@ checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" [[package]] name = "either" -version = "1.5.3" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" [[package]] name = "encode_unicode" @@ -384,9 +384,9 @@ dependencies = [ [[package]] name = "error-chain" -version = "0.12.2" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d371106cc88ffdfb1eabd7111e432da544f16f3e2d7bf1dfe8bf575f1df045cd" +checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" dependencies = [ "backtrace", "version_check", @@ -540,9 +540,9 @@ checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" [[package]] name = "goose" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f162bdd5e04a92784e6800e8984a0e872af45d3ef615e18295e76a493f4700e" +checksum = "be90af9a8090c64da65851977b697be77e8f73d4fdb7c2281343c059b74a47c0" dependencies = [ "ctrlc", "futures", @@ -591,9 +591,9 @@ checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177" [[package]] name = "hashbrown" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb" +checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25" dependencies = [ "autocfg", ] @@ -696,9 +696,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" +checksum = "86b45e59b16c76b11bf9738fd5d38879d3bd28ad292d7b313608becb17ae2df9" dependencies = [ "autocfg", "hashbrown", @@ -1195,9 +1195,9 @@ checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" [[package]] name = "proc-macro-error" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc175e9777c3116627248584e8f8b3e2987405cabe1c0adf7d1dd28f09dc7880" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", "proc-macro2", @@ -1208,14 +1208,12 @@ dependencies = [ [[package]] name = "proc-macro-error-attr" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cc9795ca17eb581285ec44936da7fc2335a3f34f2ddd13118b6f4d515435c50" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", "quote", - "syn", - "syn-mid", "version_check", ] @@ -1557,9 +1555,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" +checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" dependencies = [ "serde_derive", ] @@ -1576,9 +1574,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" +checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" dependencies = [ "proc-macro2", "quote", @@ -1657,9 +1655,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41" +checksum = "a3e12110bc539e657a646068aaf5eb5b63af9d0c1f7b29c97113fad80e15f035" dependencies = [ "arc-swap", "libc", @@ -1794,9 +1792,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de2f5e239ee807089b62adce73e48c625e0ed80df02c7ab3f068f5db5281065c" +checksum = "de5472fb24d7e80ae84a7801b7978f95a19ec32cb1876faea59ab711eb901976" dependencies = [ "clap", "lazy_static", @@ -1805,9 +1803,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "510413f9de616762a4fbeab62509bf15c729603b72d7cd71280fbca431b1c118" +checksum = "1e0eb37335aeeebe51be42e2dc07f031163fbabfa6ac67d7ea68b5c2f68d5f99" dependencies = [ "heck", "proc-macro-error", @@ -1836,26 +1834,15 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.36" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cdb98bcb1f9d81d07b536179c269ea15999b5d14ea958196413869445bb5250" +checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] -[[package]] -name = "syn-mid" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tempdir" version = "0.3.7" @@ -2065,9 +2052,9 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" [[package]] name = "tracing" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbdf4ccd1652592b01286a5dbe1e2a77d78afaa34beadd9872a5f7396f92aaa9" +checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c" dependencies = [ "cfg-if", "log", @@ -2076,9 +2063,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.11" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ae75f0d28ae10786f3b1895c55fe72e79928fd5ccdebb5438c75e93fec178f" +checksum = "db63662723c316b43ca36d833707cc93dff82a02ba3d7e354f342682cc8b3545" dependencies = [ "lazy_static", ] @@ -2106,9 +2093,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.2.9" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4f5dd7095c2481b7b3cbed71c8de53085fb3542bc3c2b4c73cba43e8f11c7ba" +checksum = "abd165311cc4d7a555ad11cc77a37756df836182db0d81aac908c8184c584f40" dependencies = [ "ansi_term 0.12.1", "chrono", @@ -2119,6 +2106,7 @@ dependencies = [ "serde_json", "sharded-slab", "smallvec", + "thread_local", "tracing-core", "tracing-log", "tracing-serde", diff --git a/src/authentication.rs b/src/authentication.rs new file mode 100644 index 0000000..118b602 --- /dev/null +++ b/src/authentication.rs @@ -0,0 +1,28 @@ +//use mauth_client::*; + +// pub struct Authentication { +// mauth_info: mauth_client::MAuthInfo +// } + +// impl Authentication { +// pub fn new() -> Self { +// Authentication { +// mauth_info: MAuthInfo::from_default_file().expect("Mauth file missing") +// } +// } +// pub fn authenticate(&self, mut requ: &mut hyper::Request) { +// // on empty body we digest "" TODO: Support request bodies +// let (_, body_digest) = MAuthInfo::build_body_with_digest("".to_string()); +// self.mauth_info.sign_request_v2(&mut requ, &body_digest); +// self.mauth_info.sign_request_v1(&mut requ, &body_digest); +// } +// } + +pub struct Authentication {} + +impl Authentication { + pub fn new() -> Self { + Authentication {} + } + pub fn authenticate(&self, mut _requ: &mut hyper::Request) {} +} diff --git a/src/command_performance.rs b/src/command_performance.rs index b77f1c2..9bdf86f 100644 --- a/src/command_performance.rs +++ b/src/command_performance.rs @@ -56,14 +56,14 @@ pub fn run<'a>( println!(""); }); - let goose_values = goose_attack + let goose_stats = goose_attack .register_taskset(taskset!("Minos Performance Test").register_task(task!(call_url))) .execute() .expect("Errors while running performance test"); indicative.join().unwrap(); - goose_values.display(); + goose_stats.print(); } async fn call_url(user: &GooseUser) -> GooseTaskResult { @@ -148,8 +148,7 @@ fn parse_timespan(time_str: &str) -> usize { Some(_) => usize::from_str(&time_matches["seconds"]).unwrap(), None => 0, }; - let total = hours * 60 * 60 + minutes * 60 + seconds; - total + hours * 60 * 60 + minutes * 60 + seconds } } } diff --git a/src/known_param.rs b/src/known_param.rs index cc6ea77..2154fe7 100644 --- a/src/known_param.rs +++ b/src/known_param.rs @@ -19,7 +19,8 @@ impl KnownParam { // pattern {user_uuid} path: /v1/users/{user_uuid}/onboard -> true // pattern {user_uuid} path: /v1/users/{user_uuid}/friends/{friend_uuid} -> false fn path_matches(&self, full_path: &str) -> bool { - self.context == "path" + (self.context == "path" + || (self.context != "query" && full_path.contains(&self.context))) && full_path.contains(&self.pattern) && full_path.matches('}').count() == self.pattern.matches('}').count() } diff --git a/src/main.rs b/src/main.rs index bdba96b..88f7014 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![deny(clippy::all)] #![forbid(unsafe_code)] +mod authentication; mod cli_args; mod command_ls; mod command_performance; @@ -48,7 +49,7 @@ fn main() { .iter() .filter(|p| p.0.contains(&config.matches)) .flat_map(|(path_name, methods)| { - operation::Endpoint::create_supported_endpoint(path_name, methods.to_item_ref()) + operation::Endpoint::new_supported(path_name, methods.to_item_ref()) }).collect(); let scenarios = endpoints.iter().flat_map(|e| mutator.mutate(&e)); diff --git a/src/mutation.rs b/src/mutation.rs index bdeba94..7880f82 100644 --- a/src/mutation.rs +++ b/src/mutation.rs @@ -133,6 +133,7 @@ impl Mutator { let mut non_query_params: Vec> = Vec::new(); debug!("QM size {:?}", query_mutations.len()); + // Each vector has the mutations for one parameter and we do not care about that order // But we care that 200 is at the top so we order by expedted for mutations_vec in query_mutations { @@ -158,8 +159,14 @@ impl Mutator { // As per the sorting the first item on each column should be a passing mutation let mut all_good = Vec::new(); - for i in 0..total.len() { - all_good.push(total[i][0]); + + // If for instance an endpoint has only one required param but it is not know + // And we are creating only passing mutations + // Then we can't create any mutation and this will be empty. Remove these + total = total.into_iter().filter(|x| !x.is_empty()).collect(); + + for endpoint_mutation in &total { + all_good.push(endpoint_mutation[0]); } // If any error here that means we can't combine that category @@ -323,8 +330,13 @@ impl Mutator { fn mutations_from_mutagen_query(&self, endpoint: &Endpoint) -> Vec> { let mut params = Vec::new(); - params.extend(endpoint.method.optional_parameters()); - params.extend(endpoint.method.required_parameters()); + if !endpoint.method.optional_parameters().is_empty() { + params.extend(endpoint.method.optional_parameters()); + } + if !endpoint.method.required_parameters().is_empty() { + params.extend(endpoint.method.required_parameters()); + } + params .iter() diff --git a/src/operation.rs b/src/operation.rs index 04f6187..248acbd 100644 --- a/src/operation.rs +++ b/src/operation.rs @@ -40,8 +40,16 @@ impl Endpoint { } } + // TODO: Do not limit to GET + pub fn new_supported(path_name: &str, methods: &openapiv3::PathItem) -> Vec { + Self::create_supported_endpoint(path_name, methods) + .into_iter() + .filter(|x| x.crud == CRUD::Show || x.crud == CRUD::Index) + .collect() + } + // TODO Return Vec which may be empty instead - pub fn create_supported_endpoint(path_name: &str, methods: &openapiv3::PathItem) -> Vec { + fn create_supported_endpoint(path_name: &str, methods: &openapiv3::PathItem) -> Vec { let mut vec = Vec::new(); if Endpoint::url_with_variable(path_name) { let maybe_get = methods diff --git a/src/service.rs b/src/service.rs index 87a0063..3ef2835 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1,12 +1,11 @@ use std::fmt; - use crate::cli_args::*; use crate::request_param::RequestParam; +use crate::authentication::Authentication; use tracing::{debug, info}; use rand::Rng; use reqwest::header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE}; use reqwest::Method; -//use mauth_client::*; #[derive(Debug)] pub struct Request { @@ -111,6 +110,7 @@ pub struct Service { base_url: String, base_path: String, client: reqwest::Client, //reqwest::blocking::Client, + authentication: Authentication, } pub struct ServiceResponse { @@ -122,10 +122,12 @@ pub struct ServiceResponse { impl Service { pub fn new(config: &CLIArgs, base_path: String) -> Self { let client = reqwest::Client::new(); + let authentication = Authentication::new(); Service { base_url: config.base_url.clone(), base_path, client, + authentication, } } @@ -150,13 +152,7 @@ impl Service { "{:?} is not a valid URL. Check the base URL.", &endpoint )); - - // TODO: Do not re-read the file multiple times - // Add mauth headers - // let mauth_info = MAuthInfo::from_default_file().expect("Mauth file missing"); - // // on empy body we digest "" TODO: Support request bodies - // let (_, body_digest) = MAuthInfo::build_body_with_digest("".to_string()); - // mauth_info.sign_request_v2(&mut requ, &body_digest); + self.authentication.authenticate(&mut requ); requ } @@ -193,3 +189,4 @@ impl Service { }) } } +