From 15f57114312246c2ceff84e243f84b23fc8bf297 Mon Sep 17 00:00:00 2001 From: Christian <37517470+Christian-Toney@users.noreply.github.com> Date: Wed, 25 Feb 2026 16:11:16 -0500 Subject: [PATCH 1/2] Add configurations on HTTP transaction expiration --- src/middleware.rs | 2 +- src/middleware/http_request_middleware.rs | 66 ----------- src/middleware/http_transaction_middleware.rs | 105 ++++++++++++++++++ src/predefinitions.rs | 16 ++- .../delete_expired_http_transaction_rows.sql | 1 + .../initialize_http_transactions_table.sql | 2 +- .../insert_http_transaction_row.sql | 2 +- src/resources/http_transaction/mod.rs | 90 +++++++++++++-- src/resources/http_transaction/tests.rs | 44 +++++++- src/routes/access-policies/mod.rs | 4 +- .../access-policies/{access_policy_id}/mod.rs | 4 +- .../{access_policy_id}/tests.rs | 14 +++ src/routes/action-log-entries/mod.rs | 4 +- .../access-policies/mod.rs | 4 +- .../{action_log_entry_id}/mod.rs | 4 +- src/routes/actions/mod.rs | 4 +- .../{action_id}/access-policies/mod.rs | 4 +- src/routes/actions/{action_id}/mod.rs | 4 +- src/routes/actions/{action_id}/tests.rs | 10 ++ .../app-authorization-credentials/mod.rs | 4 +- .../access-policies/mod.rs | 4 +- .../{app_authorization_credential_id}/mod.rs | 4 +- .../tests.rs | 7 ++ src/routes/app-authorizations/mod.rs | 4 +- .../access-policies/mod.rs | 4 +- .../{app_authorization_id}/mod.rs | 4 +- .../{app_authorization_id}/tests.rs | 7 ++ src/routes/app-credentials/mod.rs | 4 +- .../access-policies/mod.rs | 4 +- .../{app_credential_id}/mod.rs | 4 +- .../{app_credential_id}/tests.rs | 7 ++ src/routes/apps/mod.rs | 4 +- .../apps/{app_id}/access-policies/mod.rs | 4 +- src/routes/apps/{app_id}/actions/mod.rs | 4 +- src/routes/apps/{app_id}/actions/tests.rs | 2 + .../apps/{app_id}/app-credentials/mod.rs | 4 +- src/routes/apps/{app_id}/mod.rs | 4 +- src/routes/apps/{app_id}/tests.rs | 9 ++ src/routes/configurations/mod.rs | 4 +- .../{configuration_id}/access-policies/mod.rs | 4 +- .../configurations/{configuration_id}/mod.rs | 4 +- .../{configuration_id}/tests.rs | 10 ++ src/routes/delegation-policies/mod.rs | 4 +- .../access-policies/mod.rs | 4 +- .../{delegation_policy_id}/mod.rs | 4 +- .../{delegation_policy_id}/tests.rs | 10 ++ src/routes/field-choices/mod.rs | 4 +- .../{field_choice_id}/access-policies/mod.rs | 4 +- .../field-choices/{field_choice_id}/mod.rs | 4 +- .../field-choices/{field_choice_id}/tests.rs | 3 + src/routes/field-values/mod.rs | 4 +- .../{field_value_id}/access-policies/mod.rs | 4 +- .../field-values/{field_value_id}/mod.rs | 4 +- .../field-values/{field_value_id}/tests.rs | 3 + src/routes/fields/mod.rs | 4 +- .../fields/{field_id}/access-policies/mod.rs | 4 +- .../fields/{field_id}/field-choices/mod.rs | 4 +- src/routes/fields/{field_id}/mod.rs | 4 +- src/routes/groups/mod.rs | 4 +- .../groups/{group_id}/access-policies/mod.rs | 4 +- src/routes/groups/{group_id}/mod.rs | 4 +- src/routes/groups/{group_id}/tests.rs | 5 +- src/routes/http-transactions/mod.rs | 4 +- .../access-policies/mod.rs | 4 +- .../{http_transaction_id}/mod.rs | 4 +- .../{http_transaction_id}/tests.rs | 5 +- src/routes/item-connection-types/mod.rs | 4 +- .../{item_connection_type_id}/mod.rs | 4 +- .../{item_connection_type_id}/tests.rs | 5 +- src/routes/item-connections/mod.rs | 4 +- .../{item_connection_id}/mod.rs | 4 +- .../{item_connection_id}/tests.rs | 5 +- src/routes/items/mod.rs | 4 +- src/routes/items/{item_id}/mod.rs | 4 +- src/routes/items/{item_id}/tests.rs | 5 +- src/routes/memberships/mod.rs | 4 +- src/routes/memberships/{membership_id}/mod.rs | 4 +- .../memberships/{membership_id}/tests.rs | 5 +- src/routes/milestones/mod.rs | 4 +- src/routes/milestones/{milestone_id}/mod.rs | 4 +- src/routes/milestones/{milestone_id}/tests.rs | 5 +- src/routes/mod.rs | 4 +- src/routes/oauth-access-tokens/mod.rs | 4 +- src/routes/projects/mod.rs | 4 +- src/routes/projects/{project_id}/mod.rs | 4 +- src/routes/projects/{project_id}/tests.rs | 5 +- src/routes/roles/mod.rs | 4 +- src/routes/roles/{role_id}/mod.rs | 4 +- src/routes/roles/{role_id}/tests.rs | 5 +- src/routes/server-log-entries/mod.rs | 4 +- .../{server_log_entry_id}/mod.rs | 4 +- .../{server_log_entry_id}/tests.rs | 5 +- src/routes/sessions/mod.rs | 4 +- src/routes/sessions/{session_id}/mod.rs | 4 +- src/routes/users/{user_id}/mod.rs | 4 +- .../{user_id}/oauth-authorizations/mod.rs | 4 +- src/routes/users/{user_id}/tests.rs | 5 +- src/routes/views/mod.rs | 4 +- src/routes/views/{view_id}/mod.rs | 4 +- src/routes/views/{view_id}/tests.rs | 5 +- src/routes/workspaces/mod.rs | 4 +- src/routes/workspaces/{workspace_id}/mod.rs | 4 +- src/routes/workspaces/{workspace_id}/tests.rs | 5 +- src/tests.rs | 2 +- src/utilities/route_handler_utilities.rs | 4 +- 105 files changed, 520 insertions(+), 241 deletions(-) delete mode 100644 src/middleware/http_request_middleware.rs create mode 100644 src/middleware/http_transaction_middleware.rs create mode 100644 src/queries/http_transactions/delete_expired_http_transaction_rows.sql diff --git a/src/middleware.rs b/src/middleware.rs index 0838d81e..515a1c2a 100644 --- a/src/middleware.rs +++ b/src/middleware.rs @@ -1,2 +1,2 @@ pub mod authentication_middleware; -pub mod http_request_middleware; \ No newline at end of file +pub mod http_transaction_middleware; \ No newline at end of file diff --git a/src/middleware/http_request_middleware.rs b/src/middleware/http_request_middleware.rs deleted file mode 100644 index e6e2ee3a..00000000 --- a/src/middleware/http_request_middleware.rs +++ /dev/null @@ -1,66 +0,0 @@ -use std::{net::SocketAddr, sync::Arc}; -use axum::{body::Body, extract::{ConnectInfo, Request, State}, middleware::Next, response::{IntoResponse, Response}}; -use chrono::{Duration, Utc}; -use crate::{AppState, HTTPError, resources::{ResourceError, http_transaction::{HTTPTransaction, InitialHTTPTransactionProperties}, server_log_entry::ServerLogEntry}}; - -pub async fn create_http_request( - ConnectInfo(address): ConnectInfo, - State(state): State, - mut request: Request, - next: Next -) -> Result { - - // Remove sensitive headers from the stored request. - let client_ip = address.ip(); - let method = request.method().to_string(); - let url = request.uri().to_string(); - let mut safe_headers = request.headers().clone(); - safe_headers.remove("authorization"); - safe_headers.remove("cookie"); - let headers_json_string: serde_json::Value = format!("{:?}", safe_headers).into(); - - // Create the HTTP request and add it to the request extension. - let http_transaction = match HTTPTransaction::create(&InitialHTTPTransactionProperties { - method, - url, - ip_address: client_ip, - headers: headers_json_string.to_string(), - status_code: None, - expiration_date: Some(Utc::now() + Duration::days(30)) - }, &state.database_pool).await { - - Ok(http_request) => Arc::new(http_request), - - Err(error) => { - - let http_error = match error { - - ResourceError::PostgresError(postgres_error) => { - - match postgres_error.as_db_error() { - - Some(db_error) => HTTPError::InternalServerError(Some(format!("{:?}", db_error))), - - None => HTTPError::InternalServerError(Some(format!("{:?}", postgres_error))) - - } - - }, - - _ => HTTPError::InternalServerError(Some(error.to_string())) - - }; - ServerLogEntry::from_http_error(&http_error, None, &state.database_pool).await.ok(); - return Err(http_error.into_response()); - - } - - }; - - request.extensions_mut().insert(http_transaction.clone()); - - ServerLogEntry::info(&format!("HTTP request handling started."), Some(&http_transaction.id), &state.database_pool).await.ok(); - let response = next.run(request).await; - return Ok(response); - -} \ No newline at end of file diff --git a/src/middleware/http_transaction_middleware.rs b/src/middleware/http_transaction_middleware.rs new file mode 100644 index 00000000..65cf4be5 --- /dev/null +++ b/src/middleware/http_transaction_middleware.rs @@ -0,0 +1,105 @@ +use std::{net::SocketAddr, sync::Arc}; +use axum::{body::Body, extract::{ConnectInfo, Request, State}, middleware::Next, response::{IntoResponse, Response}}; +use chrono::{Duration, Utc}; +use rust_decimal::prelude::ToPrimitive; +use crate::{AppState, HTTPError, resources::{ResourceError, http_transaction::{EditableHTTPTransactionProperties, HTTPTransaction, InitialHTTPTransactionProperties}, server_log_entry::ServerLogEntry}, utilities::route_handler_utilities::get_configuration_by_name}; + +pub async fn create_http_transaction( + ConnectInfo(address): ConnectInfo, + State(state): State, + mut request: Request, + next: Next +) -> Result { + + // Remove sensitive headers from the stored request. + let client_ip = address.ip(); + let method = request.method().to_string(); + let url = request.uri().to_string(); + let mut safe_headers = request.headers().clone(); + safe_headers.remove("authorization"); + safe_headers.remove("cookie"); + let headers_json_string: serde_json::Value = format!("{:?}", safe_headers).into(); + + // Create the HTTP request and add it to the request extension. + let mut http_transaction = match HTTPTransaction::create(&InitialHTTPTransactionProperties { + method, + url, + ip_address: client_ip, + headers: headers_json_string.to_string(), + status_code: None, + expiration_timestamp: None + }, &state.database_pool).await { + + Ok(http_transaction) => Arc::new(http_transaction), + + Err(error) => { + + let http_error = match error { + + ResourceError::PostgresError(postgres_error) => { + + match postgres_error.as_db_error() { + + Some(db_error) => HTTPError::InternalServerError(Some(format!("{:?}", db_error))), + + None => HTTPError::InternalServerError(Some(format!("{:?}", postgres_error))) + + } + + }, + + _ => HTTPError::InternalServerError(Some(error.to_string())) + + }; + ServerLogEntry::from_http_error(&http_error, None, &state.database_pool).await.ok(); + return Err(http_error); + + } + + }; + + let should_http_transactions_expire_configuration = get_configuration_by_name("httpTransactions.shouldExpire", &http_transaction, &state.database_pool).await?; + let should_http_transactions_expire = should_http_transactions_expire_configuration.boolean_value.or(should_http_transactions_expire_configuration.default_boolean_value).unwrap_or(false); + if should_http_transactions_expire { + + let expiration_duration_milliseconds = match should_http_transactions_expire_configuration.number_value + .or(should_http_transactions_expire_configuration.default_number_value) + .and_then(|decimal| decimal.to_i64()) + { + + Some(milliseconds) => Some(Duration::milliseconds(milliseconds)), + + None => None + + }; + + if let Some(duration) = expiration_duration_milliseconds { + + http_transaction = match http_transaction.update(&EditableHTTPTransactionProperties { + expiration_timestamp: Some(Some(Utc::now() + duration)), + ..Default::default() + }, &state.database_pool).await { + + Ok(updated_http_transaction) => Arc::new(updated_http_transaction), + + Err(error) => { + + let http_error = HTTPError::InternalServerError(Some(format!("Failed to set HTTP transaction expiration timestamp: {:?}", error))); + ServerLogEntry::from_http_error(&http_error, Some(&http_transaction.id), &state.database_pool).await.ok(); + return Err(http_error); + + } + + } + + } + + } + + request.extensions_mut().insert(http_transaction.clone()); + + ServerLogEntry::info(&format!("HTTP request handling started."), Some(&http_transaction.id), &state.database_pool).await.ok(); + let response = next.run(request).await; + return Ok(response); + +} \ No newline at end of file diff --git a/src/predefinitions.rs b/src/predefinitions.rs index 73168808..410befdc 100644 --- a/src/predefinitions.rs +++ b/src/predefinitions.rs @@ -1006,7 +1006,21 @@ pub async fn initialize_predefined_configurations(database_pool: &deadpool_postg value_type: ConfigurationValueType::Number, default_number_value: Some(Decimal::from(256 as i64)), ..Default::default() - } + }, + InitialConfigurationProperties { + name: "httpTransactions.shouldExpire".to_string(), + description: Some("Whether HTTP transactions should expire after a certain amount of time. If true, HTTP transactions will expire after the amount of time specified in the \"httpTransactions.defaultMaximumLifetimeMilliseconds\" configuration.".to_string()), + value_type: ConfigurationValueType::Boolean, + default_boolean_value: Some(true), + ..Default::default() + }, + InitialConfigurationProperties { + name: "httpTransactions.defaultMaximumLifetimeMilliseconds".to_string(), + description: Some("The default maximum lifetime of HTTP transactions in milliseconds. This configuration only has an effect if the \"httpTransactions.shouldExpire\" configuration is set to true.".to_string()), + value_type: ConfigurationValueType::Number, + default_number_value: Some(Decimal::from(31536000000 as i64)), // 365 days in milliseconds + ..Default::default() + }, ]; let mut configurations: Vec = Vec::new(); diff --git a/src/queries/http_transactions/delete_expired_http_transaction_rows.sql b/src/queries/http_transactions/delete_expired_http_transaction_rows.sql new file mode 100644 index 00000000..5fa40ef0 --- /dev/null +++ b/src/queries/http_transactions/delete_expired_http_transaction_rows.sql @@ -0,0 +1 @@ +DELETE FROM http_transactions WHERE expiration_timestamp <= now(); \ No newline at end of file diff --git a/src/queries/http_transactions/initialize_http_transactions_table.sql b/src/queries/http_transactions/initialize_http_transactions_table.sql index d764a20d..2b1c6cd1 100644 --- a/src/queries/http_transactions/initialize_http_transactions_table.sql +++ b/src/queries/http_transactions/initialize_http_transactions_table.sql @@ -5,5 +5,5 @@ CREATE TABLE IF NOT EXISTS http_transactions ( ip_address INET NOT NULL, headers TEXT NOT NULL, status_code INTEGER, - expiration_date TIMESTAMPTZ NOT NULL DEFAULT NOW() + INTERVAL '14 days' -- TODO: Make this configurable through server policies. + expiration_timestamp TIMESTAMPTZ ); \ No newline at end of file diff --git a/src/queries/http_transactions/insert_http_transaction_row.sql b/src/queries/http_transactions/insert_http_transaction_row.sql index 831d782d..8c4275c2 100644 --- a/src/queries/http_transactions/insert_http_transaction_row.sql +++ b/src/queries/http_transactions/insert_http_transaction_row.sql @@ -4,7 +4,7 @@ INSERT INTO http_transactions ( ip_address, headers, status_code, - expiration_date + expiration_timestamp ) VALUES ( $1, $2, diff --git a/src/resources/http_transaction/mod.rs b/src/resources/http_transaction/mod.rs index aee19699..d026f8cf 100644 --- a/src/resources/http_transaction/mod.rs +++ b/src/resources/http_transaction/mod.rs @@ -17,7 +17,7 @@ pub const ALLOWED_QUERY_KEYS: &[&str] = &[ "ip_address", "headers", "status_code", - "expiration_date" + "expiration_timestamp" ]; pub const UUID_QUERY_KEYS: &[&str] = &[ "id" @@ -44,8 +44,31 @@ pub struct InitialHTTPTransactionProperties { /// The status code of the HTTP request. pub status_code: Option, - /// The expiration date of the HTTP request. - pub expiration_date: Option> + /// The expiration timestamp of the HTTP request. + pub expiration_timestamp: Option> + +} + +#[derive(Debug, Clone, ToSql, FromSql, Serialize, Deserialize, PartialEq, Eq, Default)] +pub struct EditableHTTPTransactionProperties { + + /// The HTTP method of the HTTP request. + pub method: Option, + + /// The URL of the HTTP request. + pub url: Option, + + /// The IP address of the HTTP request. + pub ip_address: Option, + + /// The headers of the HTTP request. + pub headers: Option, + + /// The status code of the HTTP request. + pub status_code: Option>, + + /// The expiration timestamp of the HTTP request. + pub expiration_timestamp: Option>> } @@ -70,8 +93,8 @@ pub struct HTTPTransaction { /// The status code of the HTTP request. pub status_code: Option, - /// The expiration date of the HTTP request. - pub expiration_date: Option> + /// The expiration timestamp of the HTTP request. + pub expiration_timestamp: Option> } @@ -80,6 +103,8 @@ impl HTTPTransaction { /// Counts the number of http_transactions based on a query. pub async fn count(query: &str, database_pool: &deadpool_postgres::Pool, individual_principal: Option<&IndividualPrincipal>) -> Result { + Self::delete_expired_http_transactions(database_pool).await?; + // Prepare the query. let sanitizer_options = SlashstepQLSanitizeFunctionOptions { filter: query.to_string(), @@ -102,10 +127,20 @@ impl HTTPTransaction { } + pub async fn delete_expired_http_transactions(database_pool: &deadpool_postgres::Pool) -> Result<(), ResourceError> { + + let database_client = database_pool.get().await?; + let query = include_str!("../../queries/http_transactions/delete_expired_http_transaction_rows.sql"); + database_client.execute(query, &[]).await?; + return Ok(()); + + } + /// Gets a field by its ID. pub async fn get_by_id(id: &Uuid, database_pool: &deadpool_postgres::Pool) -> Result { let database_client = database_pool.get().await?; + Self::delete_expired_http_transactions(database_pool).await?; let query = include_str!("../../queries/http_transactions/get_http_transaction_row_by_id.sql"); let row = match database_client.query_opt(query, &[&id]).await { @@ -113,7 +148,7 @@ impl HTTPTransaction { Some(row) => row, - None => return Err(ResourceError::NotFoundError(format!("A field value with the ID \"{}\" does not exist.", id))) + None => return Err(ResourceError::NotFoundError(format!("An HTTP transaction with the ID \"{}\" does not exist.", id))) }, @@ -121,9 +156,9 @@ impl HTTPTransaction { }; - let field = Self::convert_from_row(&row); + let http_transaction = Self::convert_from_row(&row); - return Ok(field); + return Ok(http_transaction); } @@ -137,7 +172,7 @@ impl HTTPTransaction { ip_address: row.get("ip_address"), headers: row.get("headers"), status_code: row.get("status_code"), - expiration_date: row.get("expiration_date") + expiration_timestamp: row.get("expiration_timestamp") }; } @@ -162,9 +197,10 @@ impl HTTPTransaction { &initial_properties.ip_address, &initial_properties.headers, &initial_properties.status_code, - &initial_properties.expiration_date + &initial_properties.expiration_timestamp ]; let database_client = database_pool.get().await?; + Self::delete_expired_http_transactions(database_pool).await?; let row = database_client.query_one(query, parameters).await.map_err(|error| { return ResourceError::PostgresError(error) @@ -199,6 +235,8 @@ impl HTTPTransaction { /// Returns a list of http_transactions based on a query. pub async fn list(query: &str, database_pool: &deadpool_postgres::Pool, individual_principal: Option<&IndividualPrincipal>) -> Result, ResourceError> { + Self::delete_expired_http_transactions(database_pool).await?; + // Prepare the query. let sanitizer_options = SlashstepQLSanitizeFunctionOptions { filter: query.to_string(), @@ -216,8 +254,35 @@ impl HTTPTransaction { // Execute the query. let database_client = database_pool.get().await?; let rows = database_client.query(&query, ¶meters).await?; - let actions = rows.iter().map(Self::convert_from_row).collect(); - return Ok(actions); + let http_transactions = rows.iter().map(Self::convert_from_row).collect(); + return Ok(http_transactions); + + } + + /// Updates this HTTP transaction and returns a new instance of the HTTP transaction. + pub async fn update(&self, properties: &EditableHTTPTransactionProperties, database_pool: &deadpool_postgres::Pool) -> Result { + + let query = String::from("UPDATE http_transactions SET "); + let parameter_boxes: Vec> = Vec::new(); + let database_client = database_pool.get().await?; + + database_client.query("BEGIN;", &[]).await?; + let (parameter_boxes, query) = slashstepql::add_parameter_to_query(parameter_boxes, query, "method", properties.method.as_ref()); + let (parameter_boxes, query) = slashstepql::add_parameter_to_query(parameter_boxes, query, "url", properties.url.as_ref()); + let (parameter_boxes, query) = slashstepql::add_parameter_to_query(parameter_boxes, query, "ip_address", properties.ip_address.as_ref()); + let (parameter_boxes, query) = slashstepql::add_parameter_to_query(parameter_boxes, query, "headers", properties.headers.as_ref()); + let (parameter_boxes, query) = slashstepql::add_parameter_to_query(parameter_boxes, query, "status_code", properties.status_code.as_ref()); + let (parameter_boxes, query) = slashstepql::add_parameter_to_query(parameter_boxes, query, "expiration_timestamp", properties.expiration_timestamp.as_ref()); + let (mut parameter_boxes, mut query) = (parameter_boxes, query); + + query.push_str(format!(" WHERE id = ${} RETURNING *;", parameter_boxes.len() + 1).as_str()); + parameter_boxes.push(Box::new(&self.id)); + let parameters: Vec<&(dyn ToSql + Sync)> = parameter_boxes.iter().map(|parameter| parameter.as_ref() as &(dyn ToSql + Sync)).collect(); + let row = database_client.query_one(&query, ¶meters).await?; + database_client.query("COMMIT;", &[]).await?; + + let http_transaction = Self::convert_from_row(&row); + return Ok(http_transaction); } @@ -229,6 +294,7 @@ impl DeletableResource for HTTPTransaction { async fn delete(&self, database_pool: &deadpool_postgres::Pool) -> Result<(), ResourceError> { let database_client = database_pool.get().await?; + Self::delete_expired_http_transactions(database_pool).await?; let query = include_str!("../../queries/http_transactions/delete_http_transaction_row_by_id.sql"); database_client.execute(query, &[&self.id]).await?; return Ok(()); diff --git a/src/resources/http_transaction/tests.rs b/src/resources/http_transaction/tests.rs index 14a1e43d..7c083776 100644 --- a/src/resources/http_transaction/tests.rs +++ b/src/resources/http_transaction/tests.rs @@ -19,7 +19,7 @@ fn assert_http_transactions_are_equal(http_transaction_1: &HTTPTransaction, http assert_eq!(http_transaction_1.ip_address, http_transaction_2.ip_address); assert_eq!(http_transaction_1.headers, http_transaction_2.headers); assert_eq!(http_transaction_1.status_code, http_transaction_2.status_code); - assert_eq!(http_transaction_1.expiration_date.and_then(|expiration_date| DateTime::from_timestamp_millis(expiration_date.timestamp_millis())), http_transaction_2.expiration_date.and_then(|expiration_date| DateTime::from_timestamp_millis(expiration_date.timestamp_millis()))); + assert_eq!(http_transaction_1.expiration_timestamp.and_then(|expiration_timestamp| DateTime::from_timestamp_millis(expiration_timestamp.timestamp_millis())), http_transaction_2.expiration_timestamp.and_then(|expiration_timestamp| DateTime::from_timestamp_millis(expiration_timestamp.timestamp_millis()))); } @@ -30,7 +30,7 @@ fn assert_http_transaction_is_equal_to_initial_properties(http_transaction: &HTT assert_eq!(http_transaction.ip_address, initial_properties.ip_address); assert_eq!(http_transaction.headers, initial_properties.headers); assert_eq!(http_transaction.status_code, initial_properties.status_code); - assert_eq!(http_transaction.expiration_date.and_then(|expiration_date| DateTime::from_timestamp_millis(expiration_date.timestamp_millis())), initial_properties.expiration_date.and_then(|expiration_date| DateTime::from_timestamp_millis(expiration_date.timestamp_millis()))); + assert_eq!(http_transaction.expiration_timestamp.and_then(|expiration_timestamp| DateTime::from_timestamp_millis(expiration_timestamp.timestamp_millis())), initial_properties.expiration_timestamp.and_then(|expiration_timestamp| DateTime::from_timestamp_millis(expiration_timestamp.timestamp_millis()))); } @@ -68,7 +68,7 @@ async fn verify_creation() -> Result<(), TestSlashstepServerError> { ip_address: local_ip()?, headers: Uuid::now_v7().to_string(), status_code: Some(200), - expiration_date: Some(Utc::now() + Duration::days(30)) + expiration_timestamp: Some(Utc::now() + Duration::days(30)) }; let http_transaction = HTTPTransaction::create(&http_transaction_properties, &test_environment.database_pool).await?; assert_http_transaction_is_equal_to_initial_properties(&http_transaction, &http_transaction_properties); @@ -279,3 +279,41 @@ async fn verify_list_resources_without_query_and_filter_based_on_requestor_permi return Ok(()); } + +/// Verifies that the struct can delete HTTP transactions that have expired. +#[tokio::test] +async fn verify_deletion_of_expired_http_transactions() -> Result<(), TestSlashstepServerError> { + + // Create the access policy. + let test_environment = TestEnvironment::new().await?; + initialize_required_tables(&test_environment.database_pool).await?; + + let created_http_transaction = HTTPTransaction::create(&InitialHTTPTransactionProperties { + method: "GET".to_string(), + url: Uuid::now_v7().to_string(), + ip_address: local_ip()?, + headers: Uuid::now_v7().to_string(), + status_code: None, + expiration_timestamp: Some(Utc::now()) + }, &test_environment.database_pool).await?; + + HTTPTransaction::delete_expired_http_transactions(&test_environment.database_pool).await?; + + // Ensure that the access policy is no longer in the database. + match HTTPTransaction::get_by_id(&created_http_transaction.id, &test_environment.database_pool).await { + + Ok(_) => panic!("Expected an HTTP transaction not found error."), + + Err(error) => match error { + + ResourceError::NotFoundError(_) => {}, + + error => return Err(TestSlashstepServerError::ResourceError(error)) + + } + + } + + return Ok(()); + +} diff --git a/src/routes/access-policies/mod.rs b/src/routes/access-policies/mod.rs index 6dd902fd..93dc004d 100644 --- a/src/routes/access-policies/mod.rs +++ b/src/routes/access-policies/mod.rs @@ -13,7 +13,7 @@ use std::sync::Arc; use axum::{Extension, Json, Router, extract::{Query, State, rejection::JsonRejection}}; use axum_extra::response::ErasedJson; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{resource_hierarchy::ResourceHierarchy, reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_request_body_without_json_rejection, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{resource_hierarchy::ResourceHierarchy, reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_request_body_without_json_rejection, verify_delegate_permissions, verify_principal_permissions}}}; #[path = "./{access_policy_id}/mod.rs"] mod access_policy_id; @@ -135,7 +135,7 @@ pub fn get_router(state: AppState) -> Router { .route("/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policy_id::get_router(state.clone())); return router; diff --git a/src/routes/access-policies/{access_policy_id}/mod.rs b/src/routes/access-policies/{access_policy_id}/mod.rs index 82046d92..737ff8e3 100644 --- a/src/routes/access-policies/{access_policy_id}/mod.rs +++ b/src/routes/access-policies/{access_policy_id}/mod.rs @@ -13,7 +13,7 @@ use std::sync::Arc; use axum::{Extension, Json, Router, extract::{Path, State, rejection::JsonRejection}}; use reqwest::StatusCode; use uuid::Uuid; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{DeletableResource, ResourceError, access_policy::{AccessPolicy, ActionPermissionLevel, EditableAccessPolicyProperties, ResourceHierarchy}, action::Action, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{resource_hierarchy::{self, ResourceHierarchyError}, reusable_route_handlers::delete_resource, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_request_body_without_json_rejection, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{DeletableResource, ResourceError, access_policy::{AccessPolicy, ActionPermissionLevel, EditableAccessPolicyProperties, ResourceHierarchy}, action::Action, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{resource_hierarchy::{self, ResourceHierarchyError}, reusable_route_handlers::delete_resource, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_request_body_without_json_rejection, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; async fn get_resource_hierarchy(access_policy: &AccessPolicy, http_transaction: &HTTPTransaction, database_pool: &deadpool_postgres::Pool) -> Result { @@ -278,7 +278,7 @@ pub fn get_router(state: AppState) -> Router { .route("/access-policies/{access_policy_id}", axum::routing::delete(handle_delete_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/access-policies/{access_policy_id}/tests.rs b/src/routes/access-policies/{access_policy_id}/tests.rs index 107e9822..ec6cba58 100644 --- a/src/routes/access-policies/{access_policy_id}/tests.rs +++ b/src/routes/access-policies/{access_policy_id}/tests.rs @@ -36,6 +36,7 @@ async fn verify_returned_access_policy_by_id() -> Result<(), TestSlashstepServer initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -100,6 +101,7 @@ async fn verify_uuid_when_getting_access_policy_by_id() -> Result<(), TestSlashs initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -126,6 +128,7 @@ async fn verify_authentication_when_getting_access_policy_by_id() -> Result<(), initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -155,6 +158,7 @@ async fn verify_permission_when_getting_access_policy_by_id() -> Result<(), Test initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -186,6 +190,10 @@ async fn verify_not_found_when_getting_access_policy_by_id() -> Result<(), TestS let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -324,6 +332,7 @@ async fn verify_permission_when_deleting_access_policy_by_id() -> Result<(), Tes initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -354,6 +363,10 @@ async fn verify_access_policy_exists_when_deleting_access_policy_by_id() -> Resu let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -386,6 +399,7 @@ async fn verify_successful_patch_access_policy_by_id() -> Result<(), TestSlashst initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; diff --git a/src/routes/action-log-entries/mod.rs b/src/routes/action-log-entries/mod.rs index 091f0def..7f75ac41 100644 --- a/src/routes/action-log-entries/mod.rs +++ b/src/routes/action-log-entries/mod.rs @@ -13,7 +13,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; use serde::{Deserialize, Serialize}; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{ResourceError, access_policy::{AccessPolicyResourceType, ActionPermissionLevel, ResourceHierarchy}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, DEFAULT_MAXIMUM_ACTION_LOG_ENTRY_LIST_LIMIT, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_individual_principal_from_authenticated_principal, match_db_error, match_slashstepql_error, verify_delegate_permissions, verify_principal_permissions}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{ResourceError, access_policy::{AccessPolicyResourceType, ActionPermissionLevel, ResourceHierarchy}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, DEFAULT_MAXIMUM_ACTION_LOG_ENTRY_LIST_LIMIT, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_individual_principal_from_authenticated_principal, match_db_error, match_slashstepql_error, verify_delegate_permissions, verify_principal_permissions}}; #[path = "./{action_log_entry_id}/mod.rs"] mod action_log_entry_id; @@ -122,7 +122,7 @@ pub fn get_router(state: AppState) -> Router { .route("/action-log-entries", axum::routing::get(handle_list_action_log_entries_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(action_log_entry_id::get_router(state.clone())); return router; diff --git a/src/routes/action-log-entries/{action_log_entry_id}/access-policies/mod.rs b/src/routes/action-log-entries/{action_log_entry_id}/access-policies/mod.rs index 9d5416bb..6cc58f84 100644 --- a/src/routes/action-log-entries/{action_log_entry_id}/access-policies/mod.rs +++ b/src/routes/action-log-entries/{action_log_entry_id}/access-policies/mod.rs @@ -14,7 +14,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, routes::action_log_entries::action_log_entry_id::get_action_log_entry_by_id, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_request_body_without_json_rejection, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, routes::action_log_entries::action_log_entry_id::get_action_log_entry_by_id, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_request_body_without_json_rejection, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; #[cfg(test)] mod tests; @@ -153,7 +153,7 @@ pub fn get_router(state: AppState) -> Router { .route("/action-log-entries/{action_log_entry_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } \ No newline at end of file diff --git a/src/routes/action-log-entries/{action_log_entry_id}/mod.rs b/src/routes/action-log-entries/{action_log_entry_id}/mod.rs index 16d72119..4f47ae62 100644 --- a/src/routes/action-log-entries/{action_log_entry_id}/mod.rs +++ b/src/routes/action-log-entries/{action_log_entry_id}/mod.rs @@ -13,7 +13,7 @@ use std::sync::Arc; use axum::{Extension, Json, Router, extract::{Path, State}}; use reqwest::{StatusCode}; use uuid::Uuid; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{ResourceError, access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::delete_resource, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{ResourceError, access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::delete_resource, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; #[path = "./access-policies/mod.rs"] mod access_policies; @@ -151,7 +151,7 @@ pub fn get_router(state: AppState) -> Router { .route("/action-log-entries/{action_log_entry_id}", axum::routing::delete(handle_delete_action_log_entry_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())); return router; diff --git a/src/routes/actions/mod.rs b/src/routes/actions/mod.rs index 8ff19a22..c27b70d3 100644 --- a/src/routes/actions/mod.rs +++ b/src/routes/actions/mod.rs @@ -15,7 +15,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action::{Action, DEFAULT_MAXIMUM_ACTION_LIST_LIMIT}, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action::{Action, DEFAULT_MAXIMUM_ACTION_LIST_LIMIT}, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{action_id}/mod.rs"] pub mod action_id; @@ -62,7 +62,7 @@ pub fn get_router(state: AppState) -> Router { .route("/actions", axum::routing::get(handle_list_actions_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(action_id::get_router(state.clone())); return router; diff --git a/src/routes/actions/{action_id}/access-policies/mod.rs b/src/routes/actions/{action_id}/access-policies/mod.rs index a9d306ba..141318e8 100644 --- a/src/routes/actions/{action_id}/access-policies/mod.rs +++ b/src/routes/actions/{action_id}/access-policies/mod.rs @@ -14,7 +14,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_request_body_without_json_rejection, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_request_body_without_json_rejection, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; /// GET /actions/{action_id}/access-policies /// @@ -150,7 +150,7 @@ pub fn get_router(state: AppState) -> Router { .route("/actions/{action_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/actions/{action_id}/mod.rs b/src/routes/actions/{action_id}/mod.rs index 313b18a8..cd02c148 100644 --- a/src/routes/actions/{action_id}/mod.rs +++ b/src/routes/actions/{action_id}/mod.rs @@ -15,7 +15,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action::{ Action, @@ -177,7 +177,7 @@ pub fn get_router(state: AppState) -> Router { .route("/actions/{action_id}", axum::routing::delete(handle_delete_action_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())); return router; diff --git a/src/routes/actions/{action_id}/tests.rs b/src/routes/actions/{action_id}/tests.rs index d8f7f0e2..465ba597 100644 --- a/src/routes/actions/{action_id}/tests.rs +++ b/src/routes/actions/{action_id}/tests.rs @@ -178,6 +178,9 @@ async fn verify_not_found_when_getting_action_by_id() -> Result<(), TestSlashste let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; @@ -267,6 +270,7 @@ async fn verify_uuid_when_deleting_action_by_id() -> Result<(), TestSlashstepSer initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -357,6 +361,9 @@ async fn verify_action_exists_when_deleting_action_by_id() -> Result<(), TestSla let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; @@ -707,6 +714,7 @@ async fn verify_display_name_is_under_maximum_length() -> Result<(), TestSlashst let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; // Give the user access to the "actions.update" action. @@ -752,6 +760,7 @@ async fn verify_action_name_matches_regex() -> Result<(), TestSlashstepServerErr let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; // Give the user access to the "actions.create" action. @@ -799,6 +808,7 @@ async fn verify_action_display_name_matches_regex() -> Result<(), TestSlashstepS let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; // Give the user access to the "actions.create" action. diff --git a/src/routes/app-authorization-credentials/mod.rs b/src/routes/app-authorization-credentials/mod.rs index ae33407e..71fdaaee 100644 --- a/src/routes/app-authorization-credentials/mod.rs +++ b/src/routes/app-authorization-credentials/mod.rs @@ -18,7 +18,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, app_authorization_credential::{AppAuthorizationCredential, DEFAULT_MAXIMUM_APP_AUTHORIZATION_CREDENTIAL_LIST_LIMIT}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, app_authorization_credential::{AppAuthorizationCredential, DEFAULT_MAXIMUM_APP_AUTHORIZATION_CREDENTIAL_LIST_LIMIT}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; /// GET /app-authorization-credentials /// @@ -62,7 +62,7 @@ pub fn get_router(state: AppState) -> Router { .route("/app-authorization-credentials", axum::routing::get(handle_list_app_authorization_credentials_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(app_authorization_credential_id::get_router(state.clone())); return router; diff --git a/src/routes/app-authorization-credentials/{app_authorization_credential_id}/access-policies/mod.rs b/src/routes/app-authorization-credentials/{app_authorization_credential_id}/access-policies/mod.rs index 18c5e0fe..e9927e05 100644 --- a/src/routes/app-authorization-credentials/{app_authorization_credential_id}/access-policies/mod.rs +++ b/src/routes/app-authorization-credentials/{app_authorization_credential_id}/access-policies/mod.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::JsonRejection}}; use axum_extra::response::ErasedJson; use pg_escape::quote_literal; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_authorization_credential_by_id, get_authenticated_principal, get_request_body_without_json_rejection, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_authorization_credential_by_id, get_authenticated_principal, get_request_body_without_json_rejection, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; /// GET /app-authorization-credentials/{app_authorization_credential_id}/access-policies /// @@ -152,7 +152,7 @@ pub fn get_router(state: AppState) -> Router { .route("/app-authorization-credentials/{app_authorization_credential_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/app-authorization-credentials/{app_authorization_credential_id}/mod.rs b/src/routes/app-authorization-credentials/{app_authorization_credential_id}/mod.rs index 3f9c37b3..33520874 100644 --- a/src/routes/app-authorization-credentials/{app_authorization_credential_id}/mod.rs +++ b/src/routes/app-authorization-credentials/{app_authorization_credential_id}/mod.rs @@ -20,7 +20,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, app_authorization_credential::AppAuthorizationCredential, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, @@ -107,7 +107,7 @@ pub fn get_router(state: AppState) -> Router { .route("/app-authorization-credentials/{app_authorization_credential_id}", axum::routing::delete(handle_delete_app_authorization_credential_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())); return router; diff --git a/src/routes/app-authorization-credentials/{app_authorization_credential_id}/tests.rs b/src/routes/app-authorization-credentials/{app_authorization_credential_id}/tests.rs index 0c2a4219..00e919b7 100644 --- a/src/routes/app-authorization-credentials/{app_authorization_credential_id}/tests.rs +++ b/src/routes/app-authorization-credentials/{app_authorization_credential_id}/tests.rs @@ -33,6 +33,7 @@ async fn verify_returned_resource_by_id() -> Result<(), TestSlashstepServerError initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -78,6 +79,7 @@ async fn verify_uuid_when_getting_resource_by_id() -> Result<(), TestSlashstepSe initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -104,6 +106,7 @@ async fn verify_authentication_when_getting_resource_by_id() -> Result<(), TestS initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -243,6 +246,7 @@ async fn verify_uuid_when_deleting_resource_by_id() -> Result<(), TestSlashstepS initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -333,6 +337,9 @@ async fn verify_resource_exists_when_deleting_resource_by_id() -> Result<(), Tes let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; diff --git a/src/routes/app-authorizations/mod.rs b/src/routes/app-authorizations/mod.rs index d135e8e6..62527f9f 100644 --- a/src/routes/app-authorizations/mod.rs +++ b/src/routes/app-authorizations/mod.rs @@ -17,7 +17,7 @@ mod tests; use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::{AppAuthorization, DEFAULT_MAXIMUM_APP_AUTHORIZATION_LIST_LIMIT}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::{AppAuthorization, DEFAULT_MAXIMUM_APP_AUTHORIZATION_LIST_LIMIT}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; /// GET /app-authorizations /// @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { .route("/app-authorizations", axum::routing::get(handle_list_app_authorizations_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(app_authorization_id::get_router(state.clone())); return router; diff --git a/src/routes/app-authorizations/{app_authorization_id}/access-policies/mod.rs b/src/routes/app-authorizations/{app_authorization_id}/access-policies/mod.rs index e3ffeb2a..2f064048 100644 --- a/src/routes/app-authorizations/{app_authorization_id}/access-policies/mod.rs +++ b/src/routes/app-authorizations/{app_authorization_id}/access-policies/mod.rs @@ -17,7 +17,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_authorization_by_id, get_authenticated_principal, get_request_body_without_json_rejection, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_authorization_by_id, get_authenticated_principal, get_request_body_without_json_rejection, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; /// GET /app-authorizations/{app_authorization_id}/access-policies /// @@ -153,7 +153,7 @@ pub fn get_router(state: AppState) -> Router { .route("/app-authorizations/{app_authorization_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/app-authorizations/{app_authorization_id}/mod.rs b/src/routes/app-authorizations/{app_authorization_id}/mod.rs index 3b0a9a3c..9be11ce9 100644 --- a/src/routes/app-authorizations/{app_authorization_id}/mod.rs +++ b/src/routes/app-authorizations/{app_authorization_id}/mod.rs @@ -18,7 +18,7 @@ use std::sync::Arc; use axum::{Extension, Json, Router, extract::{Path, State}}; use reqwest::StatusCode; use crate::{ - AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{ + AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, utilities::{reusable_route_handlers::delete_resource, route_handler_utilities::{ AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_authorization_by_id, get_authenticated_principal, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions @@ -103,7 +103,7 @@ pub fn get_router(state: AppState) -> Router { .route("/app-authorizations/{app_authorization_id}", axum::routing::delete(handle_delete_app_authorization_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())); return router; diff --git a/src/routes/app-authorizations/{app_authorization_id}/tests.rs b/src/routes/app-authorizations/{app_authorization_id}/tests.rs index 006b6e71..9037aaf5 100644 --- a/src/routes/app-authorizations/{app_authorization_id}/tests.rs +++ b/src/routes/app-authorizations/{app_authorization_id}/tests.rs @@ -33,6 +33,7 @@ async fn verify_returned_resource_by_id() -> Result<(), TestSlashstepServerError initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -79,6 +80,7 @@ async fn verify_uuid_when_getting_resource_by_id() -> Result<(), TestSlashstepSe initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -105,6 +107,7 @@ async fn verify_authentication_when_getting_resource_by_id() -> Result<(), TestS initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -244,6 +247,7 @@ async fn verify_uuid_when_deleting_resource_by_id() -> Result<(), TestSlashstepS initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -334,6 +338,9 @@ async fn verify_resource_exists_when_deleting_resource_by_id() -> Result<(), Tes let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; diff --git a/src/routes/app-credentials/mod.rs b/src/routes/app-credentials/mod.rs index 4fec2784..3e33a525 100644 --- a/src/routes/app-credentials/mod.rs +++ b/src/routes/app-credentials/mod.rs @@ -17,7 +17,7 @@ mod tests; use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, app_credential::{AppCredential, DEFAULT_MAXIMUM_APP_CREDENTIAL_LIST_LIMIT}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, app_credential::{AppCredential, DEFAULT_MAXIMUM_APP_CREDENTIAL_LIST_LIMIT}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; /// GET /app-credentials /// @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { .route("/app-credentials", axum::routing::get(handle_list_app_credentials_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(app_credential_id::get_router(state.clone())); return router; diff --git a/src/routes/app-credentials/{app_credential_id}/access-policies/mod.rs b/src/routes/app-credentials/{app_credential_id}/access-policies/mod.rs index 06330e7d..9da5550a 100644 --- a/src/routes/app-credentials/{app_credential_id}/access-policies/mod.rs +++ b/src/routes/app-credentials/{app_credential_id}/access-policies/mod.rs @@ -17,7 +17,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_credential_by_id, get_authenticated_principal, get_request_body_without_json_rejection, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_credential_by_id, get_authenticated_principal, get_request_body_without_json_rejection, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; /// GET /app-credentials/{app_credential_id}/access-policies /// @@ -153,7 +153,7 @@ pub fn get_router(state: AppState) -> Router { .route("/app-credentials/{app_credential_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/app-credentials/{app_credential_id}/mod.rs b/src/routes/app-credentials/{app_credential_id}/mod.rs index 38649419..8ddafc27 100644 --- a/src/routes/app-credentials/{app_credential_id}/mod.rs +++ b/src/routes/app-credentials/{app_credential_id}/mod.rs @@ -18,7 +18,7 @@ use std::sync::Arc; use axum::{Extension, Json, Router, extract::{Path, State}}; use reqwest::StatusCode; use crate::{ - AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{ + AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, app_credential::AppCredential, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, utilities::{reusable_route_handlers::delete_resource, route_handler_utilities::{ AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_credential_by_id, get_authenticated_principal, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions @@ -103,7 +103,7 @@ pub fn get_router(state: AppState) -> Router { .route("/app-credentials/{app_credential_id}", axum::routing::delete(handle_delete_app_credential_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())); return router; diff --git a/src/routes/app-credentials/{app_credential_id}/tests.rs b/src/routes/app-credentials/{app_credential_id}/tests.rs index adff5331..35edb7e2 100644 --- a/src/routes/app-credentials/{app_credential_id}/tests.rs +++ b/src/routes/app-credentials/{app_credential_id}/tests.rs @@ -33,6 +33,7 @@ async fn verify_returned_resource_by_id() -> Result<(), TestSlashstepServerError initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -79,6 +80,7 @@ async fn verify_uuid_when_getting_resource_by_id() -> Result<(), TestSlashstepSe initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -105,6 +107,7 @@ async fn verify_authentication_when_getting_resource_by_id() -> Result<(), TestS initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -244,6 +247,7 @@ async fn verify_uuid_when_deleting_resource_by_id() -> Result<(), TestSlashstepS initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -334,6 +338,9 @@ async fn verify_resource_exists_when_deleting_resource_by_id() -> Result<(), Tes let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; diff --git a/src/routes/apps/mod.rs b/src/routes/apps/mod.rs index 4be48eac..a9d109bc 100644 --- a/src/routes/apps/mod.rs +++ b/src/routes/apps/mod.rs @@ -22,7 +22,7 @@ use rand::{RngExt, distr::Alphanumeric}; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; use uuid::Uuid; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicyResourceType, ActionPermissionLevel, ResourceHierarchy}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App, AppClientType, AppParentResourceType, DEFAULT_MAXIMUM_APP_LIST_LIMIT, InitialAppProperties}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_configuration_by_name, get_request_body_without_json_rejection, validate_field_length, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicyResourceType, ActionPermissionLevel, ResourceHierarchy}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App, AppClientType, AppParentResourceType, DEFAULT_MAXIMUM_APP_LIST_LIMIT, InitialAppProperties}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_configuration_by_name, get_request_body_without_json_rejection, validate_field_length, verify_delegate_permissions, verify_principal_permissions}}}; #[derive(Debug, Serialize, Deserialize, Default)] pub struct InitialAppPropertiesWithoutClientSecretHash { @@ -283,7 +283,7 @@ pub fn get_router(state: AppState) -> Router { .route("/apps", axum::routing::post(handle_create_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(app_id::get_router(state.clone())); return router; diff --git a/src/routes/apps/{app_id}/access-policies/mod.rs b/src/routes/apps/{app_id}/access-policies/mod.rs index 1d3cb10c..9fc074b7 100644 --- a/src/routes/apps/{app_id}/access-policies/mod.rs +++ b/src/routes/apps/{app_id}/access-policies/mod.rs @@ -14,7 +14,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_by_id, get_authenticated_principal, get_request_body_without_json_rejection, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_by_id, get_authenticated_principal, get_request_body_without_json_rejection, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; #[cfg(test)] mod tests; @@ -153,7 +153,7 @@ pub fn get_router(state: AppState) -> Router { .route("/apps/{app_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } \ No newline at end of file diff --git a/src/routes/apps/{app_id}/actions/mod.rs b/src/routes/apps/{app_id}/actions/mod.rs index c398ddaf..c3a89f0d 100644 --- a/src/routes/apps/{app_id}/actions/mod.rs +++ b/src/routes/apps/{app_id}/actions/mod.rs @@ -14,7 +14,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action::{Action, ActionParentResourceType, DEFAULT_MAXIMUM_ACTION_LIST_LIMIT, InitialActionProperties, InitialActionPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_app_by_id, get_authenticated_principal, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action::{Action, ActionParentResourceType, DEFAULT_MAXIMUM_ACTION_LIST_LIMIT, InitialActionProperties, InitialActionPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_app_by_id, get_authenticated_principal, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; #[axum::debug_handler] async fn handle_list_actions_request( @@ -156,7 +156,7 @@ pub fn get_router(state: AppState) -> Router { .route("/apps/{app_id}/actions", axum::routing::post(handle_create_action_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/apps/{app_id}/actions/tests.rs b/src/routes/apps/{app_id}/actions/tests.rs index 7b8e82b6..d9253425 100644 --- a/src/routes/apps/{app_id}/actions/tests.rs +++ b/src/routes/apps/{app_id}/actions/tests.rs @@ -25,6 +25,8 @@ async fn verify_successful_creation() -> Result<(), TestSlashstepServerError> { let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Give the user access to the "apps.create" action. let user = test_environment.create_random_user().await?; diff --git a/src/routes/apps/{app_id}/app-credentials/mod.rs b/src/routes/apps/{app_id}/app-credentials/mod.rs index d60e0b8d..9d3f2193 100644 --- a/src/routes/apps/{app_id}/app-credentials/mod.rs +++ b/src/routes/apps/{app_id}/app-credentials/mod.rs @@ -21,7 +21,7 @@ use pg_escape::quote_literal; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; use uuid::Uuid; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, app_credential::{AppCredential, DEFAULT_MAXIMUM_APP_CREDENTIAL_LIST_LIMIT, InitialAppCredentialProperties, InitialAppCredentialPropertiesForPredefinedScope}, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_by_id, get_authenticated_principal, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, app_credential::{AppCredential, DEFAULT_MAXIMUM_APP_CREDENTIAL_LIST_LIMIT, InitialAppCredentialProperties, InitialAppCredentialPropertiesForPredefinedScope}, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_by_id, get_authenticated_principal, get_resource_hierarchy, verify_delegate_permissions, verify_principal_permissions}}}; #[derive(Debug, Serialize, Deserialize)] pub struct CreateAppCredentialResponseBody { @@ -224,7 +224,7 @@ pub fn get_router(state: AppState) -> Router { .route("/apps/{app_id}/app-credentials", axum::routing::post(handle_create_app_credential_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/apps/{app_id}/mod.rs b/src/routes/apps/{app_id}/mod.rs index 75e7b7fb..72315799 100644 --- a/src/routes/apps/{app_id}/mod.rs +++ b/src/routes/apps/{app_id}/mod.rs @@ -15,7 +15,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App, EditableAppProperties}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, @@ -176,7 +176,7 @@ pub fn get_router(state: AppState) -> Router { .route("/apps/{app_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(actions::get_router(state.clone())) .merge(access_policies::get_router(state.clone())) .merge(app_credentials::get_router(state.clone())); diff --git a/src/routes/apps/{app_id}/tests.rs b/src/routes/apps/{app_id}/tests.rs index 6535135f..403f1d2d 100644 --- a/src/routes/apps/{app_id}/tests.rs +++ b/src/routes/apps/{app_id}/tests.rs @@ -36,6 +36,7 @@ async fn verify_returned_app_by_id() -> Result<(), TestSlashstepServerError> { initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -91,6 +92,7 @@ async fn verify_uuid_when_getting_app_by_id() -> Result<(), TestSlashstepServerE initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -117,6 +119,7 @@ async fn verify_authentication_when_getting_app_by_id() -> Result<(), TestSlashs initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -179,6 +182,9 @@ async fn verify_not_found_when_getting_app_by_id() -> Result<(), TestSlashstepSe let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; @@ -358,6 +364,9 @@ async fn verify_resource_exists_when_deleting_by_id() -> Result<(), TestSlashste let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; diff --git a/src/routes/configurations/mod.rs b/src/routes/configurations/mod.rs index 65b95a35..ba9b6358 100644 --- a/src/routes/configurations/mod.rs +++ b/src/routes/configurations/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, configuration::{self, Configuration}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, configuration::{self, Configuration}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{configuration_id}/mod.rs"] mod configuration_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { .route("/configurations", axum::routing::get(handle_list_configurations_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(configuration_id::get_router(state.clone())); return router; diff --git a/src/routes/configurations/{configuration_id}/access-policies/mod.rs b/src/routes/configurations/{configuration_id}/access-policies/mod.rs index 2a21be38..cfa3ec5e 100644 --- a/src/routes/configurations/{configuration_id}/access-policies/mod.rs +++ b/src/routes/configurations/{configuration_id}/access-policies/mod.rs @@ -17,7 +17,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_configuration_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_configuration_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; /// GET /configurations/{configuration_id}/access-policies /// @@ -155,7 +155,7 @@ pub fn get_router(state: AppState) -> Router { .route("/configurations/{configuration_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/configurations/{configuration_id}/mod.rs b/src/routes/configurations/{configuration_id}/mod.rs index 77263493..13efdd85 100644 --- a/src/routes/configurations/{configuration_id}/mod.rs +++ b/src/routes/configurations/{configuration_id}/mod.rs @@ -15,7 +15,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, configuration::{Configuration, EditableConfigurationProperties}, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, @@ -192,7 +192,7 @@ pub fn get_router(state: AppState) -> Router { .route("/configurations/{configuration_id}", axum::routing::patch(handle_patch_configuration_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())); return router; diff --git a/src/routes/configurations/{configuration_id}/tests.rs b/src/routes/configurations/{configuration_id}/tests.rs index 0fae0b1b..426503f1 100644 --- a/src/routes/configurations/{configuration_id}/tests.rs +++ b/src/routes/configurations/{configuration_id}/tests.rs @@ -35,6 +35,7 @@ async fn verify_returned_resource_by_id() -> Result<(), TestSlashstepServerError initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -77,6 +78,7 @@ async fn verify_uuid_when_getting_resource_by_id() -> Result<(), TestSlashstepSe initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -103,6 +105,7 @@ async fn verify_authentication_when_getting_resource_by_id() -> Result<(), TestS initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -165,6 +168,9 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; @@ -246,6 +252,7 @@ async fn verify_uuid_when_deleting_by_id() -> Result<(), TestSlashstepServerErro initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -336,6 +343,9 @@ async fn verify_resource_exists_when_deleting_by_id() -> Result<(), TestSlashste let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; diff --git a/src/routes/delegation-policies/mod.rs b/src/routes/delegation-policies/mod.rs index a724cf5f..c208f08a 100644 --- a/src/routes/delegation-policies/mod.rs +++ b/src/routes/delegation-policies/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, delegation_policy::{DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, DelegationPolicy}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, delegation_policy::{DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, DelegationPolicy}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{delegation_policy_id}/mod.rs"] mod delegation_policy_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { .route("/delegation-policies", axum::routing::get(handle_list_delegation_policies_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(delegation_policy_id::get_router(state.clone())); return router; diff --git a/src/routes/delegation-policies/{delegation_policy_id}/access-policies/mod.rs b/src/routes/delegation-policies/{delegation_policy_id}/access-policies/mod.rs index 71ce22c3..bc5ab026 100644 --- a/src/routes/delegation-policies/{delegation_policy_id}/access-policies/mod.rs +++ b/src/routes/delegation-policies/{delegation_policy_id}/access-policies/mod.rs @@ -17,7 +17,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_delegation_policy_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_delegation_policy_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; /// GET /delegation-policies/{delegation_policy_id}/access-policies /// @@ -155,7 +155,7 @@ pub fn get_router(state: AppState) -> Router { .route("/delegation-policies/{delegation_policy_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/delegation-policies/{delegation_policy_id}/mod.rs b/src/routes/delegation-policies/{delegation_policy_id}/mod.rs index e3f03382..474325e4 100644 --- a/src/routes/delegation-policies/{delegation_policy_id}/mod.rs +++ b/src/routes/delegation-policies/{delegation_policy_id}/mod.rs @@ -15,7 +15,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App}, app_authorization::AppAuthorization, delegation_policy::{DelegationPolicy, EditableDelegationPolicyProperties}, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, @@ -162,7 +162,7 @@ pub fn get_router(state: AppState) -> Router { .route("/delegation-policies/{delegation_policy_id}", axum::routing::patch(handle_patch_delegation_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())); return router; diff --git a/src/routes/delegation-policies/{delegation_policy_id}/tests.rs b/src/routes/delegation-policies/{delegation_policy_id}/tests.rs index d498fd9d..4bb7fde8 100644 --- a/src/routes/delegation-policies/{delegation_policy_id}/tests.rs +++ b/src/routes/delegation-policies/{delegation_policy_id}/tests.rs @@ -35,6 +35,7 @@ async fn verify_returned_resource_by_id() -> Result<(), TestSlashstepServerError initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -106,6 +107,7 @@ async fn verify_authentication_when_getting_resource_by_id() -> Result<(), TestS initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -168,6 +170,9 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; @@ -515,6 +520,8 @@ async fn verify_uuid_when_patching_by_id() -> Result<(), TestSlashstepServerErro initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -542,6 +549,7 @@ async fn verify_authentication_when_patching_by_id() -> Result<(), TestSlashstep initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Set up the server and send the request. let delegation_policy = test_environment.create_random_delegation_policy().await?; @@ -572,6 +580,7 @@ async fn verify_permission_when_patching() -> Result<(), TestSlashstepServerErro initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; @@ -610,6 +619,7 @@ async fn verify_resource_exists_when_patching() -> Result<(), TestSlashstepServe initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Set up the server and send the request. let state = AppState { diff --git a/src/routes/field-choices/mod.rs b/src/routes/field-choices/mod.rs index 38d32aa5..f869a958 100644 --- a/src/routes/field-choices/mod.rs +++ b/src/routes/field-choices/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, field_choice::{DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, FieldChoice}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, field_choice::{DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, FieldChoice}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{field_choice_id}/mod.rs"] mod field_choice_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { .route("/field-choices", axum::routing::get(handle_list_field_choices_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(field_choice_id::get_router(state.clone())); return router; diff --git a/src/routes/field-choices/{field_choice_id}/access-policies/mod.rs b/src/routes/field-choices/{field_choice_id}/access-policies/mod.rs index ad524cea..aab8bda1 100644 --- a/src/routes/field-choices/{field_choice_id}/access-policies/mod.rs +++ b/src/routes/field-choices/{field_choice_id}/access-policies/mod.rs @@ -17,7 +17,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_field_choice_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_field_choice_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; /// GET /field-choices/{field_choice_id}/access-policies /// @@ -155,7 +155,7 @@ pub fn get_router(state: AppState) -> Router { .route("/field-choices/{field_choice_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/field-choices/{field_choice_id}/mod.rs b/src/routes/field-choices/{field_choice_id}/mod.rs index c3d0762d..10b8e11d 100644 --- a/src/routes/field-choices/{field_choice_id}/mod.rs +++ b/src/routes/field-choices/{field_choice_id}/mod.rs @@ -20,7 +20,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App}, app_authorization::AppAuthorization, field_choice::{EditableFieldChoiceProperties, FieldChoice}, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, @@ -162,7 +162,7 @@ pub fn get_router(state: AppState) -> Router { .route("/field-choices/{field_choice_id}", axum::routing::patch(handle_patch_field_choice_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())); return router; diff --git a/src/routes/field-choices/{field_choice_id}/tests.rs b/src/routes/field-choices/{field_choice_id}/tests.rs index 4561bb4a..7e5b3246 100644 --- a/src/routes/field-choices/{field_choice_id}/tests.rs +++ b/src/routes/field-choices/{field_choice_id}/tests.rs @@ -170,6 +170,9 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; diff --git a/src/routes/field-values/mod.rs b/src/routes/field-values/mod.rs index 9b7bcce5..1d8efd38 100644 --- a/src/routes/field-values/mod.rs +++ b/src/routes/field-values/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App}, app_authorization::AppAuthorization, field_value::{DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, FieldValue}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App}, app_authorization::AppAuthorization, field_value::{DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, FieldValue}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{field_value_id}/mod.rs"] mod field_value_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { .route("/field-values", axum::routing::get(handle_list_field_values_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(field_value_id::get_router(state.clone())); return router; diff --git a/src/routes/field-values/{field_value_id}/access-policies/mod.rs b/src/routes/field-values/{field_value_id}/access-policies/mod.rs index f43adf0c..6b5cc625 100644 --- a/src/routes/field-values/{field_value_id}/access-policies/mod.rs +++ b/src/routes/field-values/{field_value_id}/access-policies/mod.rs @@ -17,7 +17,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_field_value_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_field_value_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; /// GET /field-values/{field_value_id}/access-policies /// @@ -155,7 +155,7 @@ pub fn get_router(state: AppState) -> Router { .route("/field-values/{field_value_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/field-values/{field_value_id}/mod.rs b/src/routes/field-values/{field_value_id}/mod.rs index 35b4ef56..11fd9698 100644 --- a/src/routes/field-values/{field_value_id}/mod.rs +++ b/src/routes/field-values/{field_value_id}/mod.rs @@ -15,7 +15,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App, EditableAppProperties}, app_authorization::AppAuthorization, field_value::FieldValue, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, @@ -189,7 +189,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/field-values/{field_value_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())); return router; diff --git a/src/routes/field-values/{field_value_id}/tests.rs b/src/routes/field-values/{field_value_id}/tests.rs index 840a7070..fd2f97c8 100644 --- a/src/routes/field-values/{field_value_id}/tests.rs +++ b/src/routes/field-values/{field_value_id}/tests.rs @@ -171,6 +171,9 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; diff --git a/src/routes/fields/mod.rs b/src/routes/fields/mod.rs index c73fe4c0..56d84914 100644 --- a/src/routes/fields/mod.rs +++ b/src/routes/fields/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, delegation_policy::DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, field::Field, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::App, app_authorization::AppAuthorization, delegation_policy::DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, field::Field, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{field_id}/mod.rs"] mod field_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { .route("/fields", axum::routing::get(handle_list_fields_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(field_id::get_router(state.clone())); return router; diff --git a/src/routes/fields/{field_id}/access-policies/mod.rs b/src/routes/fields/{field_id}/access-policies/mod.rs index 19ec317f..6456f782 100644 --- a/src/routes/fields/{field_id}/access-policies/mod.rs +++ b/src/routes/fields/{field_id}/access-policies/mod.rs @@ -17,7 +17,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_field_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_field_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; /// GET /fields/{field_id}/access-policies /// @@ -155,7 +155,7 @@ pub fn get_router(state: AppState) -> Router { .route("/fields/{field_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/fields/{field_id}/field-choices/mod.rs b/src/routes/fields/{field_id}/field-choices/mod.rs index ed8f2ef1..86c5668f 100644 --- a/src/routes/fields/{field_id}/field-choices/mod.rs +++ b/src/routes/fields/{field_id}/field-choices/mod.rs @@ -22,7 +22,7 @@ use reqwest::StatusCode; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use uuid::Uuid; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{StakeholderType, access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, field_choice::{DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, FieldChoice, FieldChoiceType, InitialFieldChoiceProperties}, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_by_id, get_authenticated_principal, get_field_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{StakeholderType, access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, field_choice::{DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, FieldChoice, FieldChoiceType, InitialFieldChoiceProperties}, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_by_id, get_authenticated_principal, get_field_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct InitialFieldChoicePropertiesWithPredefinedFieldID { @@ -185,7 +185,7 @@ pub fn get_router(state: AppState) -> Router { .route("/fields/{field_id}/field-choices", axum::routing::post(handle_create_field_choice_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/fields/{field_id}/mod.rs b/src/routes/fields/{field_id}/mod.rs index 158661b7..61b3e442 100644 --- a/src/routes/fields/{field_id}/mod.rs +++ b/src/routes/fields/{field_id}/mod.rs @@ -22,7 +22,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, field::{EditableFieldProperties, Field}, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, @@ -177,7 +177,7 @@ pub fn get_router(state: AppState) -> Router { .route("/fields/{field_id}", axum::routing::patch(handle_patch_field_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())); return router; diff --git a/src/routes/groups/mod.rs b/src/routes/groups/mod.rs index a9063ffa..257fc28c 100644 --- a/src/routes/groups/mod.rs +++ b/src/routes/groups/mod.rs @@ -17,7 +17,7 @@ mod tests; use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App}, app_authorization::AppAuthorization, group::{DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, Group}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App}, app_authorization::AppAuthorization, group::{DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, Group}, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; /// GET /groups /// @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { .route("/groups", axum::routing::get(handle_list_groups_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(group_id::get_router(state.clone())); return router; diff --git a/src/routes/groups/{group_id}/access-policies/mod.rs b/src/routes/groups/{group_id}/access-policies/mod.rs index 7e568b03..cb6691a4 100644 --- a/src/routes/groups/{group_id}/access-policies/mod.rs +++ b/src/routes/groups/{group_id}/access-policies/mod.rs @@ -17,7 +17,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_group_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_group_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; /// GET /groups/{group_id}/access-policies /// @@ -155,7 +155,7 @@ pub fn get_router(state: AppState) -> Router { .route("/groups/{group_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/groups/{group_id}/mod.rs b/src/routes/groups/{group_id}/mod.rs index 8999365e..b6affe35 100644 --- a/src/routes/groups/{group_id}/mod.rs +++ b/src/routes/groups/{group_id}/mod.rs @@ -15,7 +15,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, group::Group, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, @@ -189,7 +189,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/groups/{group_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())); return router; diff --git a/src/routes/groups/{group_id}/tests.rs b/src/routes/groups/{group_id}/tests.rs index 7474f0e5..b5f8f49d 100644 --- a/src/routes/groups/{group_id}/tests.rs +++ b/src/routes/groups/{group_id}/tests.rs @@ -168,7 +168,10 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; - + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Create the user and the session. let user = test_environment.create_random_user().await?; let session = test_environment.create_random_session(Some(&user.id)).await?; diff --git a/src/routes/http-transactions/mod.rs b/src/routes/http-transactions/mod.rs index f370c028..b5d60fc5 100644 --- a/src/routes/http-transactions/mod.rs +++ b/src/routes/http-transactions/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App}, app_authorization::AppAuthorization, http_transaction::{DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, HTTPTransaction}, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App}, app_authorization::AppAuthorization, http_transaction::{DEFAULT_MAXIMUM_RESOURCE_LIST_LIMIT, HTTPTransaction}, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{http_transaction_id}/mod.rs"] mod http_transaction_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { .route("/http-transactions", axum::routing::get(handle_list_http_transactions_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(http_transaction_id::get_router(state.clone())); return router; diff --git a/src/routes/http-transactions/{http_transaction_id}/access-policies/mod.rs b/src/routes/http-transactions/{http_transaction_id}/access-policies/mod.rs index 1ee87c14..91508bea 100644 --- a/src/routes/http-transactions/{http_transaction_id}/access-policies/mod.rs +++ b/src/routes/http-transactions/{http_transaction_id}/access-policies/mod.rs @@ -17,7 +17,7 @@ use axum::{Extension, Json, Router, extract::{Path, Query, State, rejection::Jso use axum_extra::response::ErasedJson; use pg_escape::quote_literal; use reqwest::StatusCode; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_http_transaction_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicy, AccessPolicyResourceType, ActionPermissionLevel, DEFAULT_MAXIMUM_ACCESS_POLICY_LIST_LIMIT, InitialAccessPolicyProperties, InitialAccessPolicyPropertiesForPredefinedScope}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User}, utilities::{reusable_route_handlers::{ResourceListQueryParameters, list_resources}, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_http_transaction_by_id, get_request_body_without_json_rejection, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}}; /// GET /http-transactions/{http_transaction_id}/access-policies /// @@ -155,7 +155,7 @@ pub fn get_router(state: AppState) -> Router { .route("/http-transactions/{http_transaction_id}/access-policies", axum::routing::post(handle_create_access_policy_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/http-transactions/{http_transaction_id}/mod.rs b/src/routes/http-transactions/{http_transaction_id}/mod.rs index 1241a0c9..ed099a0f 100644 --- a/src/routes/http-transactions/{http_transaction_id}/mod.rs +++ b/src/routes/http-transactions/{http_transaction_id}/mod.rs @@ -24,7 +24,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, @@ -193,7 +193,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/http-transactions/{http_transaction_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())); return router; diff --git a/src/routes/http-transactions/{http_transaction_id}/tests.rs b/src/routes/http-transactions/{http_transaction_id}/tests.rs index e470803b..2e4cdd57 100644 --- a/src/routes/http-transactions/{http_transaction_id}/tests.rs +++ b/src/routes/http-transactions/{http_transaction_id}/tests.rs @@ -67,7 +67,7 @@ async fn verify_returned_resource_by_id() -> Result<(), TestSlashstepServerError assert_eq!(response_http_transaction.ip_address, http_transaction.ip_address); assert_eq!(response_http_transaction.headers, http_transaction.headers); assert_eq!(response_http_transaction.status_code, http_transaction.status_code); - assert_eq!(response_http_transaction.expiration_date.and_then(|expiration_date| DateTime::from_timestamp_millis(expiration_date.timestamp_millis())), http_transaction.expiration_date.and_then(|expiration_date| DateTime::from_timestamp_millis(expiration_date.timestamp_millis()))); + assert_eq!(response_http_transaction.expiration_timestamp.and_then(|expiration_timestamp| DateTime::from_timestamp_millis(expiration_timestamp.timestamp_millis())), http_transaction.expiration_timestamp.and_then(|expiration_timestamp| DateTime::from_timestamp_millis(expiration_timestamp.timestamp_millis()))); return Ok(()); @@ -170,6 +170,9 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; diff --git a/src/routes/item-connection-types/mod.rs b/src/routes/item-connection-types/mod.rs index 577dd310..4def7b34 100644 --- a/src/routes/item-connection-types/mod.rs +++ b/src/routes/item-connection-types/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{item_connection_type_id}/mod.rs"] mod item_connection_type_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/item-connection-types", axum::routing::get(handle_list_apps_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(item_connection_type_id::get_router(state.clone())); return router; diff --git a/src/routes/item-connection-types/{item_connection_type_id}/mod.rs b/src/routes/item-connection-types/{item_connection_type_id}/mod.rs index 915f920c..ffc64d9e 100644 --- a/src/routes/item-connection-types/{item_connection_type_id}/mod.rs +++ b/src/routes/item-connection-types/{item_connection_type_id}/mod.rs @@ -14,7 +14,7 @@ use axum::{Extension, Json, Router, extract::{Path, State}}; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, item_connection_type::ItemConnectionType, server_log_entry::ServerLogEntry, user::User }, @@ -188,7 +188,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/item-connection-types/{item_connection_type_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/item-connection-types/{item_connection_type_id}/tests.rs b/src/routes/item-connection-types/{item_connection_type_id}/tests.rs index a972fd75..57243b5d 100644 --- a/src/routes/item-connection-types/{item_connection_type_id}/tests.rs +++ b/src/routes/item-connection-types/{item_connection_type_id}/tests.rs @@ -167,7 +167,10 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; - + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Create the user and the session. let user = test_environment.create_random_user().await?; let session = test_environment.create_random_session(Some(&user.id)).await?; diff --git a/src/routes/item-connections/mod.rs b/src/routes/item-connections/mod.rs index f2ea3ad3..eccd8458 100644 --- a/src/routes/item-connections/mod.rs +++ b/src/routes/item-connections/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{item_connection_id}/mod.rs"] mod item_connection_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/item-connections", axum::routing::get(handle_list_apps_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(item_connection_id::get_router(state.clone())); return router; diff --git a/src/routes/item-connections/{item_connection_id}/mod.rs b/src/routes/item-connections/{item_connection_id}/mod.rs index 38c22571..35bdf139 100644 --- a/src/routes/item-connections/{item_connection_id}/mod.rs +++ b/src/routes/item-connections/{item_connection_id}/mod.rs @@ -14,7 +14,7 @@ use axum::{Extension, Json, Router, extract::{Path, State}}; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, item_connection::ItemConnection, server_log_entry::ServerLogEntry, user::User }, @@ -210,7 +210,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/item-connections/{item_connection_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/item-connections/{item_connection_id}/tests.rs b/src/routes/item-connections/{item_connection_id}/tests.rs index b3b7a4fe..a938bdf7 100644 --- a/src/routes/item-connections/{item_connection_id}/tests.rs +++ b/src/routes/item-connections/{item_connection_id}/tests.rs @@ -164,7 +164,10 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; - + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Create the user and the session. let user = test_environment.create_random_user().await?; let session = test_environment.create_random_session(Some(&user.id)).await?; diff --git a/src/routes/items/mod.rs b/src/routes/items/mod.rs index e51a818a..2d621d77 100644 --- a/src/routes/items/mod.rs +++ b/src/routes/items/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{item_id}/mod.rs"] mod item_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/items", axum::routing::get(handle_list_apps_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(item_id::get_router(state.clone())); return router; diff --git a/src/routes/items/{item_id}/mod.rs b/src/routes/items/{item_id}/mod.rs index de6db83e..8fcae035 100644 --- a/src/routes/items/{item_id}/mod.rs +++ b/src/routes/items/{item_id}/mod.rs @@ -15,7 +15,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App, EditableAppProperties}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, item::Item, server_log_entry::ServerLogEntry, user::User }, @@ -189,7 +189,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/items/{item_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/items/{item_id}/tests.rs b/src/routes/items/{item_id}/tests.rs index 83bef076..4f6d3e6a 100644 --- a/src/routes/items/{item_id}/tests.rs +++ b/src/routes/items/{item_id}/tests.rs @@ -169,7 +169,10 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; - + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Create the user and the session. let user = test_environment.create_random_user().await?; let session = test_environment.create_random_session(Some(&user.id)).await?; diff --git a/src/routes/memberships/mod.rs b/src/routes/memberships/mod.rs index cd2a40ae..fb9fabae 100644 --- a/src/routes/memberships/mod.rs +++ b/src/routes/memberships/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{membership_id}/mod.rs"] mod membership_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/memberships", axum::routing::get(handle_list_apps_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(membership_id::get_router(state.clone())); return router; diff --git a/src/routes/memberships/{membership_id}/mod.rs b/src/routes/memberships/{membership_id}/mod.rs index 79753b52..195498f9 100644 --- a/src/routes/memberships/{membership_id}/mod.rs +++ b/src/routes/memberships/{membership_id}/mod.rs @@ -14,7 +14,7 @@ use axum::{Extension, Json, Router, extract::{Path, State}}; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, membership::Membership, server_log_entry::ServerLogEntry, user::User }, @@ -188,7 +188,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/memberships/{membership_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/memberships/{membership_id}/tests.rs b/src/routes/memberships/{membership_id}/tests.rs index eee2019e..fa389dc4 100644 --- a/src/routes/memberships/{membership_id}/tests.rs +++ b/src/routes/memberships/{membership_id}/tests.rs @@ -170,7 +170,10 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; - + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Create the user and the session. let user = test_environment.create_random_user().await?; let session = test_environment.create_random_session(Some(&user.id)).await?; diff --git a/src/routes/milestones/mod.rs b/src/routes/milestones/mod.rs index 4d639207..43687bf9 100644 --- a/src/routes/milestones/mod.rs +++ b/src/routes/milestones/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{milestone_id}/mod.rs"] mod milestone_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/milestones", axum::routing::get(handle_list_apps_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(milestone_id::get_router(state.clone())); return router; diff --git a/src/routes/milestones/{milestone_id}/mod.rs b/src/routes/milestones/{milestone_id}/mod.rs index fec16fdb..7ca398ff 100644 --- a/src/routes/milestones/{milestone_id}/mod.rs +++ b/src/routes/milestones/{milestone_id}/mod.rs @@ -15,7 +15,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App, EditableAppProperties}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, milestone::Milestone, server_log_entry::ServerLogEntry, user::User }, @@ -189,7 +189,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/milestones/{milestone_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/milestones/{milestone_id}/tests.rs b/src/routes/milestones/{milestone_id}/tests.rs index 5f3760e6..e5c549b9 100644 --- a/src/routes/milestones/{milestone_id}/tests.rs +++ b/src/routes/milestones/{milestone_id}/tests.rs @@ -173,7 +173,10 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; - + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Create the user and the session. let user = test_environment.create_random_user().await?; let session = test_environment.create_random_session(Some(&user.id)).await?; diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 70601edf..bbbc2581 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -41,7 +41,7 @@ mod views; mod workspaces; use axum::{Router, response::IntoResponse}; -use crate::{AppState, HTTPError, middleware::http_request_middleware}; +use crate::{AppState, HTTPError, middleware::http_transaction_middleware}; async fn fallback() -> impl IntoResponse { @@ -52,7 +52,7 @@ async fn fallback() -> impl IntoResponse { pub fn get_router(state: AppState) -> Router { let router = Router::::new() - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(access_policies::get_router(state.clone())) .merge(actions::get_router(state.clone())) .merge(action_log_entries::get_router(state.clone())) diff --git a/src/routes/oauth-access-tokens/mod.rs b/src/routes/oauth-access-tokens/mod.rs index 4c1ddfa8..fa2c0ede 100644 --- a/src/routes/oauth-access-tokens/mod.rs +++ b/src/routes/oauth-access-tokens/mod.rs @@ -23,7 +23,7 @@ use rust_decimal::prelude::ToPrimitive; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use uuid::Uuid; -use crate::{AppState, HTTPError, middleware::{authentication_middleware::get_decoding_key, http_request_middleware}, resources::{DeletableResource, ResourceError, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App, AppClientType}, app_authorization::{AppAuthorization, AppAuthorizationAuthorizingResourceType, InitialAppAuthorizationProperties}, app_authorization_credential::{AppAuthorizationCredential, AppAuthorizationCredentialClaims, InitialAppAuthorizationCredentialProperties}, configuration::Configuration, http_transaction::HTTPTransaction, oauth_authorization::{EditableOAuthAuthorizationProperties, OAuthAuthorization, OAuthAuthorizationClaims}, server_log_entry::ServerLogEntry}, utilities::route_handler_utilities::{get_action_by_name, get_action_log_entry_expiration_timestamp, get_json_web_token_private_key, get_json_web_token_public_key}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware::get_decoding_key, http_transaction_middleware}, resources::{DeletableResource, ResourceError, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App, AppClientType}, app_authorization::{AppAuthorization, AppAuthorizationAuthorizingResourceType, InitialAppAuthorizationProperties}, app_authorization_credential::{AppAuthorizationCredential, AppAuthorizationCredentialClaims, InitialAppAuthorizationCredentialProperties}, configuration::Configuration, http_transaction::HTTPTransaction, oauth_authorization::{EditableOAuthAuthorizationProperties, OAuthAuthorization, OAuthAuthorizationClaims}, server_log_entry::ServerLogEntry}, utilities::route_handler_utilities::{get_action_by_name, get_action_log_entry_expiration_timestamp, get_json_web_token_private_key, get_json_web_token_public_key}}; #[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct CreateOAuthAccessTokenQueryParameters { @@ -1105,7 +1105,7 @@ pub fn get_router(state: AppState) -> Router { let router = Router::::new() .route("/oauth-access-tokens", axum::routing::post(handle_create_oauth_access_token_request)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } \ No newline at end of file diff --git a/src/routes/projects/mod.rs b/src/routes/projects/mod.rs index 67792e3d..b59644c1 100644 --- a/src/routes/projects/mod.rs +++ b/src/routes/projects/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{project_id}/mod.rs"] mod project_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/projects", axum::routing::get(handle_list_apps_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(project_id::get_router(state.clone())); return router; diff --git a/src/routes/projects/{project_id}/mod.rs b/src/routes/projects/{project_id}/mod.rs index 8689b260..dfbd442b 100644 --- a/src/routes/projects/{project_id}/mod.rs +++ b/src/routes/projects/{project_id}/mod.rs @@ -15,7 +15,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App, EditableAppProperties}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, project::Project, server_log_entry::ServerLogEntry, user::User }, @@ -189,7 +189,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/projects/{project_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/projects/{project_id}/tests.rs b/src/routes/projects/{project_id}/tests.rs index 6584cf54..004f7971 100644 --- a/src/routes/projects/{project_id}/tests.rs +++ b/src/routes/projects/{project_id}/tests.rs @@ -170,7 +170,10 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; - + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Create the user and the session. let user = test_environment.create_random_user().await?; let session = test_environment.create_random_session(Some(&user.id)).await?; diff --git a/src/routes/roles/mod.rs b/src/routes/roles/mod.rs index 765cc69a..63c0caad 100644 --- a/src/routes/roles/mod.rs +++ b/src/routes/roles/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{role_id}/mod.rs"] mod role_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/roles", axum::routing::get(handle_list_apps_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(role_id::get_router(state.clone())); return router; diff --git a/src/routes/roles/{role_id}/mod.rs b/src/routes/roles/{role_id}/mod.rs index 01faf082..2e8447e4 100644 --- a/src/routes/roles/{role_id}/mod.rs +++ b/src/routes/roles/{role_id}/mod.rs @@ -14,7 +14,7 @@ use axum::{Extension, Json, Router, extract::{Path, State}}; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, role::Role, server_log_entry::ServerLogEntry, user::User }, @@ -188,7 +188,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/roles/{role_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/roles/{role_id}/tests.rs b/src/routes/roles/{role_id}/tests.rs index ba8f3868..70a7567b 100644 --- a/src/routes/roles/{role_id}/tests.rs +++ b/src/routes/roles/{role_id}/tests.rs @@ -170,7 +170,10 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; - + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Create the user and the session. let user = test_environment.create_random_user().await?; let session = test_environment.create_random_session(Some(&user.id)).await?; diff --git a/src/routes/server-log-entries/mod.rs b/src/routes/server-log-entries/mod.rs index c7c7612c..7298243b 100644 --- a/src/routes/server-log-entries/mod.rs +++ b/src/routes/server-log-entries/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{server_log_entry_id}/mod.rs"] mod server_log_entry_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/server-log-entries", axum::routing::get(handle_list_apps_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(server_log_entry_id::get_router(state.clone())); return router; diff --git a/src/routes/server-log-entries/{server_log_entry_id}/mod.rs b/src/routes/server-log-entries/{server_log_entry_id}/mod.rs index 2bfb9bf4..28a08d14 100644 --- a/src/routes/server-log-entries/{server_log_entry_id}/mod.rs +++ b/src/routes/server-log-entries/{server_log_entry_id}/mod.rs @@ -14,7 +14,7 @@ use axum::{Extension, Json, Router, extract::{Path, State}}; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, @@ -189,7 +189,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/server-log-entries/{server_log_entry_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/server-log-entries/{server_log_entry_id}/tests.rs b/src/routes/server-log-entries/{server_log_entry_id}/tests.rs index 4f4938c6..6b78adba 100644 --- a/src/routes/server-log-entries/{server_log_entry_id}/tests.rs +++ b/src/routes/server-log-entries/{server_log_entry_id}/tests.rs @@ -164,7 +164,10 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; - + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Create the user and the session. let user = test_environment.create_random_user().await?; let session = test_environment.create_random_session(Some(&user.id)).await?; diff --git a/src/routes/sessions/mod.rs b/src/routes/sessions/mod.rs index ce508489..0a6a1672 100644 --- a/src/routes/sessions/mod.rs +++ b/src/routes/sessions/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{session_id}/mod.rs"] mod session_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/sessions", axum::routing::get(handle_list_apps_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(session_id::get_router(state.clone())); return router; diff --git a/src/routes/sessions/{session_id}/mod.rs b/src/routes/sessions/{session_id}/mod.rs index 2e9d1cd7..52d75125 100644 --- a/src/routes/sessions/{session_id}/mod.rs +++ b/src/routes/sessions/{session_id}/mod.rs @@ -14,7 +14,7 @@ use axum::{Extension, Json, Router, extract::{Path, State}}; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, session::Session, user::User }, @@ -189,7 +189,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/sessions/{session_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/users/{user_id}/mod.rs b/src/routes/users/{user_id}/mod.rs index a9a69e53..4c76979e 100644 --- a/src/routes/users/{user_id}/mod.rs +++ b/src/routes/users/{user_id}/mod.rs @@ -8,7 +8,7 @@ use axum::{Extension, Json, Router, extract::{Path, State}}; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User }, @@ -178,7 +178,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/users/{user_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(oauth_authorizations::get_router(state.clone())); return router; diff --git a/src/routes/users/{user_id}/oauth-authorizations/mod.rs b/src/routes/users/{user_id}/oauth-authorizations/mod.rs index f0e6b5cc..5512de7d 100644 --- a/src/routes/users/{user_id}/oauth-authorizations/mod.rs +++ b/src/routes/users/{user_id}/oauth-authorizations/mod.rs @@ -19,7 +19,7 @@ use reqwest::StatusCode; use serde::{Deserialize, Serialize}; use uuid::Uuid; use std::str::FromStr; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, oauth_authorization::{InitialOAuthAuthorizationProperties, InitialOAuthAuthorizationPropertiesForPredefinedAuthorizer, OAuthAuthorization}, server_log_entry::ServerLogEntry, user::User}, utilities::route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_by_id, get_authenticated_principal, get_json_web_token_private_key, get_resource_hierarchy, get_user_by_id, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, oauth_authorization::{InitialOAuthAuthorizationProperties, InitialOAuthAuthorizationPropertiesForPredefinedAuthorizer, OAuthAuthorization}, server_log_entry::ServerLogEntry, user::User}, utilities::route_handler_utilities::{AuthenticatedPrincipal, get_action_by_id, get_action_by_name, get_action_log_entry_expiration_timestamp, get_app_by_id, get_authenticated_principal, get_json_web_token_private_key, get_resource_hierarchy, get_user_by_id, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}; // /// GET /apps @@ -299,7 +299,7 @@ pub fn get_router(state: AppState) -> Router { .route("/users/{user_id}/oauth-authorizations", axum::routing::post(handle_create_oauth_authorization_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } \ No newline at end of file diff --git a/src/routes/users/{user_id}/tests.rs b/src/routes/users/{user_id}/tests.rs index eecf28b8..f32c25cf 100644 --- a/src/routes/users/{user_id}/tests.rs +++ b/src/routes/users/{user_id}/tests.rs @@ -165,7 +165,10 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; - + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Create the user and the session. let user = test_environment.create_random_user().await?; let session = test_environment.create_random_session(Some(&user.id)).await?; diff --git a/src/routes/views/mod.rs b/src/routes/views/mod.rs index fde6416b..28584817 100644 --- a/src/routes/views/mod.rs +++ b/src/routes/views/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{view_id}/mod.rs"] mod view_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/views", axum::routing::get(handle_list_apps_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(view_id::get_router(state.clone())); return router; diff --git a/src/routes/views/{view_id}/mod.rs b/src/routes/views/{view_id}/mod.rs index 9b3b6414..e5571407 100644 --- a/src/routes/views/{view_id}/mod.rs +++ b/src/routes/views/{view_id}/mod.rs @@ -15,7 +15,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App, EditableAppProperties}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User, view::View }, @@ -189,7 +189,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/views/{view_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/views/{view_id}/tests.rs b/src/routes/views/{view_id}/tests.rs index cd682c95..832a71bd 100644 --- a/src/routes/views/{view_id}/tests.rs +++ b/src/routes/views/{view_id}/tests.rs @@ -171,7 +171,10 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; - + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Create the user and the session. let user = test_environment.create_random_user().await?; let session = test_environment.create_random_session(Some(&user.id)).await?; diff --git a/src/routes/workspaces/mod.rs b/src/routes/workspaces/mod.rs index c9de0242..958642e1 100644 --- a/src/routes/workspaces/mod.rs +++ b/src/routes/workspaces/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use axum::{Extension, Router, extract::{Query, State}}; use axum_extra::response::ErasedJson; -use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_request_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; +use crate::{AppState, HTTPError, middleware::{authentication_middleware, http_transaction_middleware}, resources::{access_policy::AccessPolicyResourceType, action_log_entry::ActionLogEntryTargetResourceType, app::{App, DEFAULT_MAXIMUM_APP_LIST_LIMIT}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, user::User}, utilities::reusable_route_handlers::{ResourceListQueryParameters, list_resources}}; #[path = "./{workspace_id}/mod.rs"] mod workspace_id; @@ -61,7 +61,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/workspaces", axum::routing::get(handle_list_apps_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)) + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)) .merge(workspace_id::get_router(state.clone())); return router; diff --git a/src/routes/workspaces/{workspace_id}/mod.rs b/src/routes/workspaces/{workspace_id}/mod.rs index 6fd29126..9026d8ad 100644 --- a/src/routes/workspaces/{workspace_id}/mod.rs +++ b/src/routes/workspaces/{workspace_id}/mod.rs @@ -15,7 +15,7 @@ use reqwest::StatusCode; use crate::{ AppState, HTTPError, - middleware::{authentication_middleware, http_request_middleware}, + middleware::{authentication_middleware, http_transaction_middleware}, resources::{ access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::{App, EditableAppProperties}, app_authorization::AppAuthorization, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User, workspace::Workspace }, @@ -189,7 +189,7 @@ pub fn get_router(state: AppState) -> Router { // .route("/workspaces/{workspace_id}", axum::routing::patch(handle_patch_app_request)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user)) .layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app)) - .layer(axum::middleware::from_fn_with_state(state.clone(), http_request_middleware::create_http_request)); + .layer(axum::middleware::from_fn_with_state(state.clone(), http_transaction_middleware::create_http_transaction)); return router; } diff --git a/src/routes/workspaces/{workspace_id}/tests.rs b/src/routes/workspaces/{workspace_id}/tests.rs index e9400af8..a2cc36e7 100644 --- a/src/routes/workspaces/{workspace_id}/tests.rs +++ b/src/routes/workspaces/{workspace_id}/tests.rs @@ -167,7 +167,10 @@ async fn verify_not_found_when_getting_resource_by_id() -> Result<(), TestSlashs let test_environment = TestEnvironment::new().await?; initialize_required_tables(&test_environment.database_pool).await?; - + initialize_predefined_actions(&test_environment.database_pool).await?; + initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Create the user and the session. let user = test_environment.create_random_user().await?; let session = test_environment.create_random_session(Some(&user.id)).await?; diff --git a/src/tests.rs b/src/tests.rs index a5053944..4a1e33fe 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -339,7 +339,7 @@ impl TestEnvironment { ip_address: local_ip()?, headers: Uuid::now_v7().to_string(), status_code: Some(200), - expiration_date: Some(Utc::now() + Duration::days(30)), + expiration_timestamp: Some(Utc::now() + Duration::days(30)), }; let http_transaction = HTTPTransaction::create(&http_transaction_properties, &self.database_pool).await?; diff --git a/src/utilities/route_handler_utilities.rs b/src/utilities/route_handler_utilities.rs index 4a872e47..496127b2 100644 --- a/src/utilities/route_handler_utilities.rs +++ b/src/utilities/route_handler_utilities.rs @@ -37,8 +37,8 @@ pub async fn get_action_log_entry_expiration_timestamp(http_transaction: &HTTPTr }; - let should_action_log_entries_expire = should_action_log_entries_expire_configuration.boolean_value.or(should_action_log_entries_expire_configuration.default_boolean_value); - if should_action_log_entries_expire.is_none_or(|value| value == false) { + let should_action_log_entries_expire = should_action_log_entries_expire_configuration.boolean_value.or(should_action_log_entries_expire_configuration.default_boolean_value).unwrap_or(false); + if !should_action_log_entries_expire { return Ok(None); From abfacf611ac6b78303a93c037913935f99bc277f Mon Sep 17 00:00:00 2001 From: Christian <37517470+Christian-Toney@users.noreply.github.com> Date: Wed, 25 Feb 2026 16:31:18 -0500 Subject: [PATCH 2/2] Add predefined configurations --- src/routes/field-values/{field_value_id}/tests.rs | 8 ++++++++ src/routes/groups/{group_id}/tests.rs | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/routes/field-values/{field_value_id}/tests.rs b/src/routes/field-values/{field_value_id}/tests.rs index bf55e156..16b18c30 100644 --- a/src/routes/field-values/{field_value_id}/tests.rs +++ b/src/routes/field-values/{field_value_id}/tests.rs @@ -35,6 +35,7 @@ async fn verify_returned_resource_by_id() -> Result<(), TestSlashstepServerError initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -84,6 +85,7 @@ async fn verify_uuid_when_getting_resource_by_id() -> Result<(), TestSlashstepSe initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -110,6 +112,7 @@ async fn verify_authentication_when_getting_resource_by_id() -> Result<(), TestS initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -532,6 +535,8 @@ async fn verify_uuid_when_patching_by_id() -> Result<(), TestSlashstepServerErro initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -559,6 +564,7 @@ async fn verify_authentication_when_patching_by_id() -> Result<(), TestSlashstep initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Set up the server and send the request. let field_value = test_environment.create_random_field_value().await?; @@ -589,6 +595,7 @@ async fn verify_permission_when_patching() -> Result<(), TestSlashstepServerErro initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; @@ -627,6 +634,7 @@ async fn verify_resource_exists_when_patching() -> Result<(), TestSlashstepServe initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Set up the server and send the request. let state = AppState { diff --git a/src/routes/groups/{group_id}/tests.rs b/src/routes/groups/{group_id}/tests.rs index 72e0e11a..4bf39aeb 100644 --- a/src/routes/groups/{group_id}/tests.rs +++ b/src/routes/groups/{group_id}/tests.rs @@ -79,6 +79,7 @@ async fn verify_uuid_when_getting_resource_by_id() -> Result<(), TestSlashstepSe initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -518,6 +519,8 @@ async fn verify_uuid_when_patching_by_id() -> Result<(), TestSlashstepServerErro initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; + let state = AppState { database_pool: test_environment.database_pool.clone(), }; @@ -543,7 +546,8 @@ async fn verify_authentication_when_patching_by_id() -> Result<(), TestSlashstep initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; - + initialize_predefined_configurations(&test_environment.database_pool).await?; + // Set up the server and send the request. let group = test_environment.create_random_group().await?; let state = AppState { @@ -571,6 +575,7 @@ async fn verify_permission_when_patching() -> Result<(), TestSlashstepServerErro initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Create the user and the session. let user = test_environment.create_random_user().await?; @@ -607,6 +612,7 @@ async fn verify_resource_exists_when_patching() -> Result<(), TestSlashstepServe initialize_required_tables(&test_environment.database_pool).await?; initialize_predefined_actions(&test_environment.database_pool).await?; initialize_predefined_roles(&test_environment.database_pool).await?; + initialize_predefined_configurations(&test_environment.database_pool).await?; // Set up the server and send the request. let state = AppState {