Skip to content

Commit

Permalink
- use feature flag to filter tests that require http server
Browse files Browse the repository at this point in the history
  • Loading branch information
tuta-sudipg committed Jan 31, 2025
1 parent 716bc00 commit b8d442a
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 93 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/rust-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ on:
branches:
- dev-*
- '*/dev'
env:
RUSTFLAGS: "--cfg ci" # turns off some integration tests that need a server to pass

jobs:
test:
Expand Down Expand Up @@ -41,4 +39,4 @@ jobs:
- name: rust warning check with clippy
run: cargo clippy --all --no-deps -- -Dwarnings # -Dwarnings changes warnings to errors so that the check fails
- name: rust tests
run: cargo test --all
run: cargo test --all # --features test-with-local-http-server
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
- '*/dev'
env:
emscripten_version: 3.1.59
RUSTFLAGS: "--cfg ci" # turns off some integration tests that need a server to pass

permissions:
actions: none
Expand Down
8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ publish = false
# these config should be configured in .cargo/config.toml

[workspace]
resolver = "2" # todo: can use resolver 3 after 1.84.0+
resolver = "2"
members = [
"tuta-sdk/rust/sdk",
"packages/node-mimimi",
Expand Down Expand Up @@ -52,8 +52,4 @@ manual_let_else = "warn"
must_use_candidate = "warn"
unused_async = "warn"
implicit_clone = "warn"
explicit_iter_loop = "warn"


[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] }
explicit_iter_loop = "warn"
1 change: 0 additions & 1 deletion ci/merge.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pipeline {
PATH = "${env.NODE_PATH}:${env.PATH}:/home/jenkins/emsdk/upstream/bin/:/home/jenkins/emsdk/:/home/jenkins/emsdk/upstream/emscripten"
ANDROID_SDK_ROOT = "/opt/android-sdk-linux"
ANDROID_HOME = "/opt/android-sdk-linux"
RUSTFLAGS = "--cfg ci"
}

agent {
Expand Down
16 changes: 13 additions & 3 deletions doc/HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ contains most of the logic for server communication, encryption, indexing etc.
### Communication

Worker, main thread & apps communicate through the messages. Protocol is described in the
[RemoteMessageDispatcher](../src/common/api/common/threading/MessageDispatcher.ts). See [WorkerClient](../src/common/api/main/WorkerClient.ts)
[RemoteMessageDispatcher](../src/common/api/common/threading/MessageDispatcher.ts).
See [WorkerClient](../src/common/api/main/WorkerClient.ts)
and
[WorkerImpl](../src/common/api/worker/WorkerImpl.ts) for the client and server part.

Expand All @@ -67,7 +68,7 @@ Current preferred way looks roughly like that:

```typescript
// Defining
import {Component} from "mithril"
import { Component } from "mithril"

type Attrs = { param1: string, paramTwo?: number }

Expand All @@ -80,7 +81,7 @@ class MyComponent implements Component<Attrs> {
// Usage

// ...
m(MyComponent, {param1: "Mithril", param2: 1})
m(MyComponent, { param1: "Mithril", param2: 1 })
```

### Network
Expand Down Expand Up @@ -154,6 +155,15 @@ To show all test options:
npm:run test:app -- --help
```

To run cargo unit tests

```bash
# if you want to run tests that require running server in localhost
cargo test --all --features test-with-local-http-server
# if you do not have local server running
cargo test --all
```

## Chunking rules

- Don't import things statically which you don't want to be bundled together (e.g. importing settings from login will
Expand Down
2 changes: 2 additions & 0 deletions packages/node-mimimi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ crate-type = ["cdylib"]
default = ["javascript"]
# needed to turn off the autogenerated ffi when using the tests
javascript = ["dep:napi-derive"]
# some test require local http server running
test-with-local-http-server = ["tuta-sdk/net"]

[dependencies]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
Expand Down
25 changes: 24 additions & 1 deletion packages/node-mimimi/src/importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,12 +850,15 @@ impl From<ImportMailStateId> for IdTupleGenerated {
}

#[cfg(test)]
#[cfg(not(ci))]
pub mod tests {
use super::*;
use crate::test_utils::{init_file_importer, write_big_sample_email, CleanDir};

#[tokio::test]
#[cfg_attr(
not(feature = "test-with-local-http-server"),
ignore = "required feature: test-with-local-http-server"
)]
async fn can_import_single_eml_file_without_attachment() {
let importer = init_file_importer(vec!["sample.eml"]).await;
importer.start_stateful_import().await.unwrap();
Expand All @@ -867,6 +870,10 @@ pub mod tests {
}

#[tokio::test]
#[cfg_attr(
not(feature = "test-with-local-http-server"),
ignore = "required feature: test-with-local-http-server"
)]
async fn can_import_single_eml_file_with_attachment() {
let importer = init_file_importer(vec!["attachment_sample.eml"]).await;
importer.start_stateful_import().await.unwrap();
Expand Down Expand Up @@ -899,6 +906,10 @@ pub mod tests {
}

#[tokio::test]
#[cfg_attr(
not(feature = "test-with-local-http-server"),
ignore = "required feature: test-with-local-http-server"
)]
async fn importing_too_big_eml_should_fail() {
let whither = "/tmp/toobig.eml";
write_big_sample_email(whither);
Expand Down Expand Up @@ -956,6 +967,10 @@ pub mod tests {
}

#[tokio::test]
#[cfg_attr(
not(feature = "test-with-local-http-server"),
ignore = "required feature: test-with-local-http-server"
)]
async fn should_stop_if_on_stop_action() {
let importer = init_file_importer(vec!["sample.eml"; 1]).await;
importer
Expand All @@ -971,6 +986,10 @@ pub mod tests {
}

#[tokio::test]
#[cfg_attr(
not(feature = "test-with-local-http-server"),
ignore = "required feature: test-with-local-http-server"
)]
async fn should_pause_if_on_pause_action() {
let importer = init_file_importer(vec!["sample.eml"; 2]).await;
importer
Expand All @@ -987,6 +1006,10 @@ pub mod tests {
}

#[tokio::test]
#[cfg_attr(
not(feature = "test-with-local-http-server"),
ignore = "required feature: test-with-local-http-server"
)]
async fn should_continue_if_on_continue_action() {
let importer = init_file_importer(vec!["sample.eml"; 1]).await;
importer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,6 @@ Message
}

#[test]
#[ignore]
fn normalize_header_value() {
// already done by mail_parser
}
Expand Down
4 changes: 3 additions & 1 deletion tuta-sdk/rust/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ hkdf = "0.12.4"
argon2 = { version = "0.5.3", features = ["zeroize"] }
curve25519-dalek = "4.1.2"
pqcrypto-mlkem = { version = "0.1.0", default-features = false, features = [
"std",
"std",
] }
pqcrypto-traits = "0.3.5"
rsa = "0.9.6"
Expand Down Expand Up @@ -67,6 +67,8 @@ net = ["dep:hyper", "dep:hyper-util", "dep:http-body-util", "dep:hyper-rustls",
# turns on the simple_logger logger when the sdk is initialized.
logging = ["dep:simple_logger"]
testing = ["logging"]
# some test require local http server running,
test-with-local-http-server = ["net"]

[dev-dependencies]
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
Expand Down
9 changes: 8 additions & 1 deletion tuta-sdk/rust/sdk/tests/can_manipulate_remote_instances.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg(not(ci))]
use std::sync::Arc;
use tutasdk::crypto::aes::Iv;
use tutasdk::crypto::key::GenericAesKey;
Expand All @@ -10,6 +9,10 @@ use tutasdk::net::native_rest_client::NativeRestClient;
use tutasdk::{GeneratedId, IdTupleGenerated, ListLoadDirection, Sdk};

#[tokio::test]
#[cfg_attr(
not(feature = "test-with-local-http-server"),
ignore = "required feature: test-with-local-http-server"
)]
async fn can_create_remote_instance() {
let logged_in_sdk = Sdk::new(
"http://localhost:9000".to_string(),
Expand Down Expand Up @@ -89,6 +92,10 @@ async fn can_create_remote_instance() {
}

#[tokio::test]
#[cfg_attr(
not(feature = "test-with-local-http-server"),
ignore = "required feature: test-with-local-http-server"
)]
async fn can_update_remote_instance() {
let logged_in_sdk = Sdk::new(
"http://localhost:9000".to_string(),
Expand Down
8 changes: 6 additions & 2 deletions tuta-sdk/rust/sdk/tests/create_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ use std::sync::Arc;
use tutasdk::net::native_rest_client::NativeRestClient;
use tutasdk::Sdk;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
#[tokio::test]
#[cfg_attr(
not(feature = "test-with-local-http-server"),
ignore = "required feature: test-with-local-http-server"
)]
async fn can_create_new_session_in_sdk() -> Result<(), Box<dyn Error>> {
let rest_client = Arc::new(NativeRestClient::try_new().unwrap());

// this test expect local server with matching model versions to be live at: http://localhost:9000
Expand Down
127 changes: 62 additions & 65 deletions tuta-sdk/rust/sdk/tests/download_mail_test.rs
Original file line number Diff line number Diff line change
@@ -1,82 +1,79 @@
#[cfg(test)]
mod tests {
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use std::sync::Arc;
use tutasdk::bindings::rest_client::{HttpMethod, RestClient};
use tutasdk::bindings::test_rest_client::TestRestClient;
use tutasdk::login::{CredentialType, Credentials};
use tutasdk::GeneratedId;
use tutasdk::{IdTupleGenerated, Sdk};
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use std::sync::Arc;
use tutasdk::bindings::rest_client::{HttpMethod, RestClient};
use tutasdk::bindings::test_rest_client::TestRestClient;
use tutasdk::login::{CredentialType, Credentials};
use tutasdk::GeneratedId;
use tutasdk::{IdTupleGenerated, Sdk};

#[tokio::test]
async fn download_mail_with_logged_in_client() {
let rest_client = make_rest_client();
#[tokio::test]
async fn download_mail_with_logged_in_client() {
let rest_client = make_rest_client();

// password is qawsedrftgyh
let encrypted_passphrase_key = BASE64_STANDARD.decode("AZWEA/KTrHu0bW52CsctsBTTV4U3jrU51TadSxf6Nqs3xbEs3WfoOpPtxUDCNjHNppt6LHCfgTioejjGUJ2cCsXosZAysUiau5Nvyi8mtjLz").unwrap();
// password is qawsedrftgyh
let encrypted_passphrase_key = BASE64_STANDARD.decode("AZWEA/KTrHu0bW52CsctsBTTV4U3jrU51TadSxf6Nqs3xbEs3WfoOpPtxUDCNjHNppt6LHCfgTioejjGUJ2cCsXosZAysUiau5Nvyi8mtjLz").unwrap();

let credentials = Credentials {
login: "[email protected]".to_string(),
user_id: GeneratedId("O1qC700----0".to_owned()),
access_token: "ZC2NIBDACUABAdJhibIwclzaPU3fEu-NzQ".to_string(),
encrypted_passphrase_key,
credential_type: CredentialType::Internal,
};
let sdk = Sdk::new("http://localhost:9000".to_string(), rest_client);
let logged_in_sdk = sdk.login(credentials).await.unwrap();
let mail_facade = logged_in_sdk.mail_facade();
let mail = mail_facade
.load_email_by_id_encrypted(&IdTupleGenerated {
list_id: GeneratedId("O1qC705-17-0".to_string()),
element_id: GeneratedId("O1qC7an--3-0".to_string()),
})
.await
.unwrap();
let credentials = Credentials {
login: "[email protected]".to_string(),
user_id: GeneratedId("O1qC700----0".to_owned()),
access_token: "ZC2NIBDACUABAdJhibIwclzaPU3fEu-NzQ".to_string(),
encrypted_passphrase_key,
credential_type: CredentialType::Internal,
};
let sdk = Sdk::new("http://localhost:9000".to_string(), rest_client);
let logged_in_sdk = sdk.login(credentials).await.unwrap();
let mail_facade = logged_in_sdk.mail_facade();
let mail = mail_facade
.load_email_by_id_encrypted(&IdTupleGenerated {
list_id: GeneratedId("O1qC705-17-0".to_string()),
element_id: GeneratedId("O1qC7an--3-0".to_string()),
})
.await
.unwrap();

assert_eq!("Html email features", mail.subject);
assert_eq!(1, mail.recipientCount);
assert_eq!("[email protected]", mail.firstRecipient.unwrap().address);
assert_eq!("[email protected]", mail.sender.address);
assert_eq!("Matthias", mail.sender.name);
assert_eq!(1721043814832, mail.receivedDate.as_millis());
}
assert_eq!("Html email features", mail.subject);
assert_eq!(1, mail.recipientCount);
assert_eq!("[email protected]", mail.firstRecipient.unwrap().address);
assert_eq!("[email protected]", mail.sender.address);
assert_eq!("Matthias", mail.sender.name);
assert_eq!(1721043814832, mail.receivedDate.as_millis());
}

fn make_rest_client() -> Arc<dyn RestClient> {
let mut client = TestRestClient::default();
fn make_rest_client() -> Arc<dyn RestClient> {
let mut client = TestRestClient::default();

client.insert_response(
client.insert_response(
"http://localhost:9000/rest/sys/Session/O1qC702-1J-0/3u3i8Lr9_7TnDDdAVw7w3TypTD2k1L00vIUTMF0SIPY",
HttpMethod::GET,
200,
None,
Some(include_bytes!("download_mail_test/session.json"))
);

client.insert_response(
"http://localhost:9000/rest/sys/User/O1qC700----0",
HttpMethod::GET,
200,
None,
Some(include_bytes!("download_mail_test/session.json")),
);
client.insert_response(
"http://localhost:9000/rest/sys/User/O1qC700----0",
HttpMethod::GET,
200,
None,
Some(include_bytes!("download_mail_test/session.json")),
);

client.insert_response(
"http://localhost:9000/rest/sys/User/O1qC700----0",
HttpMethod::GET,
200,
None,
Some(include_bytes!("download_mail_test/user.json")),
);
client.insert_response(
"http://localhost:9000/rest/sys/User/O1qC700----0",
HttpMethod::GET,
200,
None,
Some(include_bytes!("download_mail_test/user.json")),
);

client.insert_response(
"http://localhost:9000/rest/tutanota/Mail/O1qC705-17-0/O1qC7an--3-0",
HttpMethod::GET,
200,
None,
Some(include_bytes!("download_mail_test/mail.json")),
);
client.insert_response(
"http://localhost:9000/rest/tutanota/Mail/O1qC705-17-0/O1qC7an--3-0",
HttpMethod::GET,
200,
None,
Some(include_bytes!("download_mail_test/mail.json")),
);

Arc::new(client)
}
Arc::new(client)
}
Loading

0 comments on commit b8d442a

Please sign in to comment.