Skip to content

Commit

Permalink
Enable first round of ignored tests (#27)
Browse files Browse the repository at this point in the history
* Fixing first round of ignored tests

* Bump IOS version

* Removing commented code

* Fixing build

* Removing unused imports
  • Loading branch information
sagojez authored May 14, 2024
1 parent db1f7d1 commit 2257388
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 282 deletions.
244 changes: 74 additions & 170 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ futures-util = "0.3.28"
handlebars = "4.4.0"
http = "1.1.0"
http-serde-ext = "1.0.2"
integrationos-domain = "3.1.0"
integrationos-domain = "4.0.0"
js-sandbox-ios = "0.1.0"
jsonpath_lib = "0.3.0"
jsonwebtoken = "8.3.0"
Expand Down
18 changes: 6 additions & 12 deletions api/src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ where
},
Err(e) => {
error!("Error reading from store: {e}");
println!("{:?}", e);
return Err(internal_server_error!());
}
};
Expand All @@ -231,7 +230,6 @@ where
.try_get_with(query.as_ref().map(|q| q.0.clone()), async {
let query = shape_mongo_filter(query, None, None);

println!("{:?}", query);
let store = T::get_store(state.app_stores.clone());
let count = store.count(query.filter.clone(), None);
let find = store.get_many(
Expand All @@ -243,16 +241,12 @@ where
);

let res = match try_join!(count, find) {
Ok((total, rows)) => {
println!("{:?}", total);

Arc::new(ReadResponse {
rows,
skip: query.skip,
limit: query.limit,
total,
})
}
Ok((total, rows)) => Arc::new(ReadResponse {
rows,
skip: query.skip,
limit: query.limit,
total,
}),
Err(e) => {
error!("Error reading from store: {e}");
return Err(internal_server_error!());
Expand Down
35 changes: 1 addition & 34 deletions api/tests/api_tests/auth_tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use super::test_server::{ApiResponse, TestServer, PUBLIC_PATHS};
use api::endpoints::event_access::CreateEventAccessPayloadWithOwnership;
use fake::{Fake, Faker};
use http::{
header::{AUTHORIZATION, CONTENT_TYPE},
Method, StatusCode,
};
use http::{Method, StatusCode};
use serde_json::{json, Value};

#[tokio::test]
Expand Down Expand Up @@ -50,31 +45,3 @@ async fn test_404() {
);
}
}

#[tokio::test]
async fn test_jwt() {
let server = TestServer::new(None).await;
let jwt_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NTc5ZDUxMGE2ZTQyMTAyMzM0NjI0ZjAiLCJlbWFpbCI6ImVtYWlsQHRlc3QuY29tIiwidXNlcm5hbWUiOiJ1c2VybmFtZSIsInVzZXJLZXkiOiJ1c2VyS2V5IiwiZmlyc3ROYW1lIjoiUGF1bCIsImxhc3ROYW1lIjoiSy4iLCJidWlsZGFibGVJZCI6ImJ1aWxkLTI2MTU4YWFlNzNjMDQ4YTU4YzdhNzU2NjcyNmU4OGY0IiwiY29udGFpbmVySWQiOiJjb250YWluZXItZDRmMGY4YjktMWE1Ni00ODQxLTg1OTctZmQzZDkwZGQ0OWI5IiwicG9pbnRlcnMiOlsiXzFfazFjbkI0Y1hGMzYtYUJJc2gtY1ZWTlZNZllGeE41MWlFTlQ1azlqcXFEbURWZlpJTjVVREhlN0JKRnJaUVJqTm54aEdaOUJNUGdlNjB6RVdVUnROaTUxdTIwdDJiYVJoQ3ZkYms5TkNIblNSV010WldhMmFlVW0wWUpreU1PNGNEUjdVUW5oVmNac3RqUEdfN0lfcV9ya015cjlwaFZoZ1VBa3BCaDVDTlQ2VDIwTDJGTFpoMFVtdldLVzloV3IzN0JWV19tb0hZODFZeUEiLCJfMV81WVU2Uk1kMHRwUVh3YnNvUWtHaUkzT1hPRlhrbms3TUVhaVdTQ1hoUWZKYzZ5N3RqZGROZGRjbXdWRjJmcTRSTktla0ZXRk80M0FMQWNJTVdIYkdYbW9IVVRaelV1eXhMalJ5MDI5Z0tGMlViRTFmTzZVRzR5QWhzbFBJMlpOZXNnT2NiakY1eUdwajdJbkdHNUFVck13NGY0bVdfR29FZVp1ZXBBd2E0WHhzNHB2TXd5d241djc1VzV0dFNJRGtLTHFqUlNUQlczaHpLUSJdLCJpc0J1aWxkYWJsZUNvcmUiOnRydWUsImlhdCI6MTcwMzEwODkwNCwiZXhwIjozMTU3NDYzMTA4OTA0LCJhdWQiOiJidWlsZGFibGUtdXNlcnMiLCJpc3MiOiJidWlsZGFibGUifQ.ecKXIGxXLWd6OearftRZVpGRhyDUVZFrYlwzhr-iG0A";
let event_access: CreateEventAccessPayloadWithOwnership = Faker.fake();
let event_access = serde_json::to_value(&event_access).unwrap();

let res = server
.send_request_with_headers::<Value, Value>(
"v1/public/event-access/default",
Method::POST,
None,
Some(&event_access),
Some(
vec![
(AUTHORIZATION.to_string(), format!("Bearer {jwt_token}")),
(CONTENT_TYPE.to_string(), "application/json".to_string()),
]
.into_iter()
.collect(),
),
)
.await
.unwrap();

assert_eq!(res.code, StatusCode::OK);
}
1 change: 0 additions & 1 deletion api/tests/api_tests/get_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ async fn test_get_events() {
}

#[tokio::test]
#[ignore = "Until we have a JWT token generated we can not test this"]
async fn test_get_expanded_common_model() {
let server = TestServer::new(None).await;

Expand Down
8 changes: 3 additions & 5 deletions api/tests/api_tests/passthrough_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use mockito::Server;
use serde_json::Value;

#[tokio::test]
#[ignore = "Until we have a JWT token generated we can not test this"]
async fn test_passthrough_api() {
let mut server = TestServer::new(None).await;
let (connection, conn_def) = server.create_connection(Environment::Live).await;
Expand All @@ -33,8 +32,7 @@ async fn test_passthrough_api() {
.expect(1)
.with_status(200)
.with_body(response_body.clone())
.create_async()
.await;
.create();

let create_model_definition_payload = CreateConnectionModelDefinitionRequest {
connection_platform: connection.platform.to_string(),
Expand All @@ -43,7 +41,7 @@ async fn test_passthrough_api() {
title: Faker.fake(),
name: Faker.fake(),
model_name: Faker.fake(),
action_name: Faker.fake::<CrudAction>(),
action_name: CrudAction::Create,
base_url: mock_server.url() + &url_path,
path: "customers".to_string(),
auth_method: AuthMethod::BearerToken {
Expand Down Expand Up @@ -103,7 +101,7 @@ async fn test_passthrough_api() {
),
)
.await
.unwrap();
.expect("Failed to call universal API");

// assert_eq!(call_universal_api.code, StatusCode::OK);
assert_eq!(
Expand Down
1 change: 0 additions & 1 deletion api/tests/api_tests/schema_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use http::{Method, StatusCode};
use serde_json::Value;

#[tokio::test]
#[ignore = "Until we have a JWT token generated we can not test this"]
async fn test_connection_oauth_definition_schema_api() {
let server = TestServer::new(None).await;
let res = server
Expand Down
7 changes: 3 additions & 4 deletions api/tests/api_tests/test_crud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,30 @@ macro_rules! crud {
}

crud!(
#[ignore = "Until we have a JWT token generated we can not test this"],
#[tokio::test],
test_connection_definitions_crud,
ConnectionDefinition,
connection_definition,
"v1/connection-definitions"
);

crud!(
#[ignore = "Until we have a JWT token generated we can not test this"],
#[tokio::test],
test_connection_model_definitions_crud,
ConnectionModelDefinition,
connection_model_definition,
"v1/connection-model-definitions"
);

crud!(
#[ignore = "Until we have a JWT token generated we can not test this"],
#[tokio::test],
test_connection_model_schema_crud,
ConnectionModelSchema,
connection_model_schema,
"v1/connection-model-schemas"
);

#[tokio::test]
#[ignore = "Until we have a JWT token generated we can not test this"]
async fn test_common_model_crud() {
let server = TestServer::new(None).await;

Expand Down
88 changes: 71 additions & 17 deletions api/tests/api_tests/test_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@ use fake::{Fake, Faker};
use http::StatusCode;
use http::{header::AUTHORIZATION, Method};
use integrationos_domain::{
access_key_data::AccessKeyData,
access_key_prefix::AccessKeyPrefix,
algebra::{CryptoExt, MongoStore, StoreExt},
api_model_config::{AuthMethod, SamplesInput, SchemasInput},
connection_definition::{ConnectionDefinition, ConnectionDefinitionType},
connection_model_definition::{
ConnectionModelDefinition, CrudAction, CrudMapping, PlatformInfo,
},
create_secret_response::{CreateSecretAuthor, CreateSecretResponse},
environment::Environment,
event_access::EventAccess,
event_type::EventType,
get_secret_request::GetSecretRequest,
IntegrationOSError,
{
access_key_data::AccessKeyData,
access_key_prefix::AccessKeyPrefix,
api_model_config::{AuthMethod, SamplesInput, SchemasInput},
connection_definition::{ConnectionDefinition, ConnectionDefinitionType},
connection_model_definition::{
ConnectionModelDefinition, CrudAction, CrudMapping, PlatformInfo,
},
environment::Environment,
event_access::EventAccess,
event_type::EventType,
AccessKey, Connection, Store,
},
AccessKey, Claims, Connection, IntegrationOSError, Store,
};
use jsonwebtoken::EncodingKey;
use mockito::{Matcher, Server as MockServer, ServerGuard};
use mongodb::Client;
use rand::Rng;
Expand Down Expand Up @@ -79,6 +77,7 @@ pub struct TestServer {
client: reqwest::Client,
pub mock_server: ServerGuard,
pub secrets_client: Arc<MockSecretsClient>,
pub token: String,
}

#[derive(Debug, Clone, Default)]
Expand Down Expand Up @@ -156,6 +155,7 @@ impl TestServer {

// Random database name
let db_name = db_name.unwrap_or_else(|| Uuid::new_v4().to_string());
let token_secret = "atveroeosetaccusamusetiustoodiodignissimosducimus".to_string();

let config = Config::init_from_hashmap(&HashMap::from([
("CONTROL_DATABASE_URL".to_string(), db.clone()),
Expand All @@ -172,6 +172,7 @@ impl TestServer {
("MOCK_LLM".to_string(), "true".to_string()),
("CACHE_SIZE".to_string(), "0".to_string()),
("REDIS_URL".to_string(), redis),
("JWT_SECRET".to_string(), token_secret.clone()),
]))
.unwrap();

Expand Down Expand Up @@ -244,6 +245,27 @@ impl TestServer {

tokio::time::sleep(Duration::from_millis(50)).await;

let token = jsonwebtoken::encode(
&jsonwebtoken::Header::default(),
&Claims {
id: "6579d510a6e42102334624f0".to_string(),
email: "[email protected]".to_string(),
username: "username".to_string(),
user_key: "userKey".to_string(),
first_name: "Paul".to_string(),
last_name: "K.".to_string(),
buildable_id: "buildable-26158aae73c048a58c7a7566726e88f4".to_string(),
container_id: "container-d4f0f8b9-1a56-4841-8597-fd3d90dd49b9".to_string(),
pointers: vec!["_1_k1cnB4cXF36-aBIsh-cVVNMYfXN51iENT5k9jqqDmDVfZIN5UDHe7BFrZQRjNnxgGZ9BMPg60zEWURtNi51u20t2baRhCvdbk9NCHnSRWMtZWa2aeUm0YKzyM4ScDR7UQnhVcsstjPG_7I_q_rMy5r9phVhgUAkPBh5CNT6T20L2FLZh0UmvWKW9hW37BVW_moHY81YyI".to_string()],
is_buildable_core: true,
iat: 1703108904,
exp: 3157463108904,
aud: "buildable-users".to_string(),
iss: "buildable".to_string(),
},
&EncodingKey::from_secret(token_secret.as_bytes()),
);

Self {
port,
config,
Expand All @@ -254,6 +276,7 @@ impl TestServer {
client: reqwest::Client::new(),
mock_server: MockServer::new_async().await,
secrets_client,
token: format!("Bearer {}", token.expect("Failed to encode token")),
}
}

Expand All @@ -264,8 +287,17 @@ impl TestServer {
key: Option<&str>,
payload: Option<&T>,
) -> Result<ApiResponse<U>> {
self.send_request_with_headers(path, method, key, payload, None)
.await
self.send_request_with_auth_headers(
path,
method,
key,
payload,
Some(BTreeMap::from_iter(vec![(
AUTHORIZATION.to_string(),
self.token.clone(),
)])),
)
.await
}

pub async fn send_request_with_headers<T: Serialize, U: DeserializeOwned>(
Expand Down Expand Up @@ -299,6 +331,28 @@ impl TestServer {
})
}

pub async fn send_request_with_auth_headers<T: Serialize, U: DeserializeOwned>(
&self,
path: &str,
method: http::Method,
key: Option<&str>,
payload: Option<&T>,
headers: Option<BTreeMap<String, String>>,
) -> Result<ApiResponse<U>> {
let headers = match headers {
Some(h) => h
.into_iter()
.chain(vec![(AUTHORIZATION.to_string(), self.token.clone())])
.collect(),
None => vec![(AUTHORIZATION.to_string(), self.token.clone())],
};

let headers = BTreeMap::from_iter(headers);

self.send_request_with_headers(path, method, key, payload, Some(headers))
.await
}

#[allow(dead_code)]
pub async fn create_connection(
&mut self,
Expand Down Expand Up @@ -338,7 +392,6 @@ impl TestServer {

let api_config = match test_connection.platform_info {
PlatformInfo::Api(ref mut api_config_data) => api_config_data.clone(),
_ => panic!(),
};

let mut mock = self
Expand All @@ -351,6 +404,7 @@ impl TestServer {
AUTHORIZATION.as_str(),
format!("Bearer {bearer_key}").as_str(),
);

if let Some(ref headers) = api_config.headers {
for k in headers.keys() {
let val: Vec<Matcher> = headers
Expand Down
10 changes: 3 additions & 7 deletions api/tests/api_tests/transaction_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::time::Duration;

use crate::test_server::{test_core::TestCore, test_gateway::TestGateway, TestServer};
use api::endpoints::{pipeline::CreatePipelineRequest, ReadResponse};
use fake::{Fake, Faker};
use http::{Method, StatusCode};
Expand All @@ -8,8 +7,7 @@ use integrationos_domain::{
Transaction,
};
use serde_json::{json, Value};

use crate::test_server::{test_core::TestCore, test_gateway::TestGateway, TestServer};
use std::time::Duration;

#[tokio::test(flavor = "multi_thread")]
#[ignore = "Prometheus GlobalRecorder conflicts with other tests. It passes when run individually."]
Expand All @@ -26,9 +24,7 @@ async fn test_event_core() {
pipeline.source.events = vec![event_name.clone()];
pipeline.middleware = vec![];
pipeline.destination = Faker.fake();
let PlatformInfo::Api(api_config) = conn_def.platform_info else {
panic!();
};
let PlatformInfo::Api(api_config) = conn_def.platform_info;
pipeline.destination.platform = connection.platform.clone();
pipeline.destination.connection_key = connection.key;
pipeline.destination.action = Action::Passthrough {
Expand Down
Loading

0 comments on commit 2257388

Please sign in to comment.