Add basic JWT authentication for app API
This commit is contained in:
parent
7ad2ed8ff1
commit
3825263fa3
14 changed files with 289 additions and 40 deletions
10
tests/api.rs
10
tests/api.rs
|
@ -1,7 +1,7 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use tracing::{Level, debug};
|
||||
use ubisync::{Ubisync, config::Config, state::types::{ElementContent, Element, ElementId}};
|
||||
use ubisync::{Ubisync, config::Config, state::types::{ElementContent, Element, ElementId}, api::AppDescription};
|
||||
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
|
@ -15,9 +15,13 @@ async fn two_nodes_element_creation() {
|
|||
ubi1.add_peer_from_id(ubi2.get_destination().unwrap().into()).unwrap();
|
||||
|
||||
let http_client = reqwest::Client::new();
|
||||
let register_response = http_client.put("http://localhost:9981/v0/app/register").json(&AppDescription{name: "Test".to_string(), desc_text: "desc".to_string()}).send().await.unwrap();
|
||||
let jwt1 = register_response.text().await.expect("Couldn't fetch token from response");
|
||||
let register_response = http_client.put("http://localhost:9982/v0/app/register").json(&AppDescription{name: "Test".to_string(), desc_text: "desc".to_string()}).send().await.unwrap();
|
||||
let jwt2 = register_response.text().await.expect("Couldn't fetch token from response");
|
||||
|
||||
let test_element_content = ElementContent::Text("Text".to_string());
|
||||
let put_resp = http_client.put(&format!("http://localhost:9981/v0/element")).json(&test_element_content).send().await.unwrap();
|
||||
let put_resp = http_client.put(&format!("http://localhost:9981/v0/element")).json(&test_element_content).header("Authorization", &format!("Bearer {}", &jwt1)).send().await.unwrap();
|
||||
debug!("{:?}", &put_resp);
|
||||
let put_resp_text = put_resp.text().await.expect("No put response body");
|
||||
debug!("{}", put_resp_text);
|
||||
|
@ -25,7 +29,7 @@ async fn two_nodes_element_creation() {
|
|||
|
||||
tokio::time::sleep(Duration::from_millis(3000)).await;
|
||||
|
||||
let get_resp = http_client.get(&format!("http://localhost:9982/v0/element/{}", Into::<String>::into(&id))).send().await.expect("Get request failed");
|
||||
let get_resp = http_client.get(&format!("http://localhost:9982/v0/element/{}", Into::<String>::into(&id))).header("Authorization", &format!("Bearer {}", &jwt2)).send().await.expect("Get request failed");
|
||||
let get_resp_text = get_resp.text().await.expect("No get request body");
|
||||
debug!("{}", get_resp_text);
|
||||
let received_element = serde_json::from_str::<Element>(&get_resp_text).expect("Could not deserialize Element");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue