Skip to content

Commit

Permalink
Minor fixes to allow for endpoints with no mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiPolo committed Aug 11, 2020
1 parent a369ac2 commit 9ba5e09
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 69 deletions.
86 changes: 37 additions & 49 deletions Cargo.lock

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

28 changes: 28 additions & 0 deletions src/authentication.rs
Original file line number Diff line number Diff line change
@@ -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<hyper::Body>) {
// // 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<hyper::Body>) {}
}
7 changes: 3 additions & 4 deletions src/command_performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
}
3 changes: 2 additions & 1 deletion src/known_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(clippy::all)]
#![forbid(unsafe_code)]

mod authentication;
mod cli_args;
mod command_ls;
mod command_performance;
Expand Down Expand Up @@ -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));
Expand Down
20 changes: 16 additions & 4 deletions src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ impl Mutator {
let mut non_query_params: Vec<Vec<&Mutation>> = 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 {
Expand All @@ -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
Expand Down Expand Up @@ -323,8 +330,13 @@ impl Mutator {

fn mutations_from_mutagen_query(&self, endpoint: &Endpoint) -> Vec<Vec<Mutation>> {
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()
Expand Down
10 changes: 9 additions & 1 deletion src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ impl Endpoint {
}
}

// TODO: Do not limit to GET
pub fn new_supported(path_name: &str, methods: &openapiv3::PathItem) -> Vec<Self> {
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<Self> {
fn create_supported_endpoint(path_name: &str, methods: &openapiv3::PathItem) -> Vec<Self> {
let mut vec = Vec::new();
if Endpoint::url_with_variable(path_name) {
let maybe_get = methods
Expand Down
Loading

0 comments on commit 9ba5e09

Please sign in to comment.