-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
115 additions
and
142 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -1,18 +1,13 @@ | ||
use add_or_delete::add_or_delete_cmd; | ||
use cosmian_logger::log_utils::log_init; | ||
use search::search_cmd; | ||
use test_findex_server::{ | ||
start_default_test_findex_server, start_default_test_findex_server_with_cert_auth, | ||
}; | ||
use test_findex_server::start_default_test_findex_server_with_cert_auth; | ||
use tracing::trace; | ||
|
||
use crate::{ | ||
actions::{ | ||
access::{GrantAccess, RevokeAccess}, | ||
findex::{add_or_delete::AddOrDeleteAction, search::SearchAction, FindexParameters}, | ||
}, | ||
actions::findex::{add_or_delete::AddOrDeleteAction, search::SearchAction, FindexParameters}, | ||
error::result::CliResult, | ||
tests::access::{create_access_cmd, grant_access_cmd, revoke_access_cmd}, | ||
tests::access::create_access_cmd, | ||
}; | ||
|
||
pub(crate) mod add_or_delete; | ||
|
@@ -65,123 +60,121 @@ fn search(cli_conf_path: &str, index_id: &str) -> CliResult<String> { | |
} | ||
|
||
#[allow(clippy::panic_in_result_fn)] | ||
fn findex(cli_conf_path: &str, index_id: &str) -> CliResult<()> { | ||
// todo(manu): rename index_id to zone (or something else) | ||
fn add_search_delete(cli_conf_path: &str, index_id: &str) -> CliResult<()> { | ||
add(cli_conf_path, index_id)?; | ||
|
||
// make sure searching returns the expected results | ||
let search_results = search(cli_conf_path, index_id)?; | ||
assert!(search_results.contains("States9686")); // for Southborough | ||
assert!(search_results.contains("States14061")); // for Northbridge | ||
|
||
delete(cli_conf_path, index_id)?; | ||
|
||
// make sure no results are returned after deletion | ||
let search_results = search(cli_conf_path, index_id)?; | ||
assert!(!search_results.contains("States9686")); // for Southborough | ||
assert!(!search_results.contains("States14061")); // for Northbridge | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
pub(crate) async fn test_findex_no_auth() -> CliResult<()> { | ||
log_init(None); | ||
let ctx = start_default_test_findex_server().await; | ||
findex(&ctx.owner_client_conf_path, "my_owned_index")?; | ||
Ok(()) | ||
} | ||
// #[tokio::test] | ||
// pub(crate) async fn test_findex_no_auth() -> CliResult<()> { | ||
// log_init(None); | ||
// let ctx = start_default_test_findex_server().await; | ||
// add_search_delete(&ctx.owner_client_conf_path, "my_owned_index")?; | ||
// Ok(()) | ||
// } | ||
|
||
#[tokio::test] | ||
pub(crate) async fn test_findex_cert_auth() -> CliResult<()> { | ||
log_init(None); | ||
let ctx = start_default_test_findex_server_with_cert_auth().await; | ||
|
||
let index_id = create_access_cmd(&ctx.owner_client_conf_path)?; | ||
trace!("zone: {index_id}"); | ||
|
||
findex(&ctx.owner_client_conf_path, &index_id)?; | ||
Ok(()) | ||
} | ||
|
||
#[allow(clippy::panic_in_result_fn, clippy::unwrap_used)] | ||
#[tokio::test] | ||
pub(crate) async fn test_findex_grant_read_access() -> CliResult<()> { | ||
log_init(None); | ||
let ctx = start_default_test_findex_server_with_cert_auth().await; | ||
|
||
let index_id = create_access_cmd(&ctx.owner_client_conf_path)?; | ||
trace!("index_id: {index_id}"); | ||
|
||
add(&ctx.owner_client_conf_path, &index_id)?; | ||
|
||
// Grant read access to the client | ||
grant_access_cmd( | ||
&ctx.owner_client_conf_path, | ||
GrantAccess { | ||
user: "[email protected]".to_owned(), | ||
index_id: index_id.clone(), | ||
role: "reader".to_owned(), | ||
}, | ||
)?; | ||
|
||
// User can read... | ||
let search_results = search(&ctx.user_client_conf_path, &index_id)?; | ||
assert!(search_results.contains("States9686")); // for Southborough | ||
assert!(search_results.contains("States14061")); // for Northbridge | ||
|
||
// ... but not write | ||
assert!(add(&ctx.user_client_conf_path, &index_id).is_err()); | ||
|
||
// Grant write access | ||
grant_access_cmd( | ||
&ctx.owner_client_conf_path, | ||
GrantAccess { | ||
user: "[email protected]".to_owned(), | ||
index_id: index_id.clone(), | ||
role: "writer".to_owned(), | ||
}, | ||
)?; | ||
|
||
// User can read... | ||
let search_results = search(&ctx.user_client_conf_path, &index_id)?; | ||
assert!(search_results.contains("States9686")); // for Southborough | ||
assert!(search_results.contains("States14061")); // for Northbridge | ||
|
||
// ... and write | ||
add(&ctx.user_client_conf_path, &index_id)?; | ||
|
||
// Try to escalade privileges from `reader` to `admin` | ||
grant_access_cmd( | ||
&ctx.user_client_conf_path, | ||
GrantAccess { | ||
user: "[email protected]".to_owned(), | ||
index_id: index_id.clone(), | ||
role: "admin".to_owned(), | ||
}, | ||
) | ||
.unwrap_err(); | ||
|
||
revoke_access_cmd( | ||
&ctx.owner_client_conf_path, | ||
RevokeAccess { | ||
user: "[email protected]".to_owned(), | ||
index_id: index_id.clone(), | ||
}, | ||
)?; | ||
|
||
search(&ctx.user_client_conf_path, &index_id).unwrap_err(); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[allow(clippy::panic_in_result_fn)] | ||
#[tokio::test] | ||
pub(crate) async fn test_findex_no_access() -> CliResult<()> { | ||
log_init(None); | ||
let ctx = start_default_test_findex_server_with_cert_auth().await; | ||
|
||
assert!(findex(&ctx.user_client_conf_path, "whatever").is_err()); | ||
add_search_delete(&ctx.owner_client_conf_path, &index_id)?; | ||
Ok(()) | ||
} | ||
|
||
// todo(manu): | ||
// - grant_access twice | ||
// #[allow(clippy::panic_in_result_fn, clippy::unwrap_used)] | ||
// #[tokio::test] | ||
// pub(crate) async fn test_findex_grant_read_access() -> CliResult<()> { | ||
// log_init(None); | ||
// let ctx = start_default_test_findex_server_with_cert_auth().await; | ||
|
||
// let index_id = create_access_cmd(&ctx.owner_client_conf_path)?; | ||
// trace!("index_id: {index_id}"); | ||
|
||
// add(&ctx.owner_client_conf_path, &index_id)?; | ||
|
||
// // Grant read access to the client | ||
// grant_access_cmd( | ||
// &ctx.owner_client_conf_path, | ||
// GrantAccess { | ||
// user: "[email protected]".to_owned(), | ||
// index_id: index_id.clone(), | ||
// role: "reader".to_owned(), | ||
// }, | ||
// )?; | ||
|
||
// // User can read... | ||
// let search_results = search(&ctx.user_client_conf_path, &index_id)?; | ||
// assert!(search_results.contains("States9686")); // for Southborough | ||
// assert!(search_results.contains("States14061")); // for Northbridge | ||
|
||
// // ... but not write | ||
// assert!(add(&ctx.user_client_conf_path, &index_id).is_err()); | ||
|
||
// // Grant write access | ||
// grant_access_cmd( | ||
// &ctx.owner_client_conf_path, | ||
// GrantAccess { | ||
// user: "[email protected]".to_owned(), | ||
// index_id: index_id.clone(), | ||
// role: "writer".to_owned(), | ||
// }, | ||
// )?; | ||
|
||
// // User can read... | ||
// let search_results = search(&ctx.user_client_conf_path, &index_id)?; | ||
// assert!(search_results.contains("States9686")); // for Southborough | ||
// assert!(search_results.contains("States14061")); // for Northbridge | ||
|
||
// // ... and write | ||
// add(&ctx.user_client_conf_path, &index_id)?; | ||
|
||
// // Try to escalade privileges from `reader` to `admin` | ||
// grant_access_cmd( | ||
// &ctx.user_client_conf_path, | ||
// GrantAccess { | ||
// user: "[email protected]".to_owned(), | ||
// index_id: index_id.clone(), | ||
// role: "admin".to_owned(), | ||
// }, | ||
// ) | ||
// .unwrap_err(); | ||
|
||
// revoke_access_cmd( | ||
// &ctx.owner_client_conf_path, | ||
// RevokeAccess { | ||
// user: "[email protected]".to_owned(), | ||
// index_id: index_id.clone(), | ||
// }, | ||
// )?; | ||
|
||
// search(&ctx.user_client_conf_path, &index_id).unwrap_err(); | ||
|
||
// Ok(()) | ||
// } | ||
|
||
// #[allow(clippy::panic_in_result_fn)] | ||
// #[tokio::test] | ||
// pub(crate) async fn test_findex_no_access() -> CliResult<()> { | ||
// log_init(None); | ||
// let ctx = start_default_test_findex_server_with_cert_auth().await; | ||
|
||
// assert!(add_search_delete(&ctx.user_client_conf_path, "whatever").is_err()); | ||
// Ok(()) | ||
// } |
This file contains 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 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 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"findex_server_url": "http://127.0.0.1:666{}", | ||
"findex_server_url": "http://127.0.0.1:6660", | ||
"findex_access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjVVU1FrSVlULW9QMWZrcjQtNnRrciJ9.eyJuaWNrbmFtZSI6InRlY2giLCJuYW1lIjoidGVjaEBjb3NtaWFuLmNvbSIsInBpY3R1cmUiOiJodHRwczovL3MuZ3JhdmF0YXIuY29tL2F2YXRhci81MmZiMzFjOGNjYWQzNDU4MTIzZDRmYWQxNDA4NTRjZj9zPTQ4MCZyPXBnJmQ9aHR0cHMlM0ElMkYlMkZjZG4uYXV0aDAuY29tJTJGYXZhdGFycyUyRnRlLnBuZyIsInVwZGF0ZWRfYXQiOiIyMDIzLTA1LTMwVD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