Skip to content

Commit

Permalink
change Github rust workflow to run on project root
Browse files Browse the repository at this point in the history
  • Loading branch information
tuta-sudipg committed Jan 30, 2025
1 parent 1456042 commit 5abab26
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 58 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/tuta-sdk-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1
- uses: ./.github/shared/setup-rust
- name: sdk format
working-directory: tuta-sdk/rust
run: cargo fmt --check
- name: sdk warning check with clippy
working-directory: tuta-sdk/rust
run: cargo clippy --package tuta-sdk --no-deps -- -Dwarnings # -Dwarnings changes warnings to errors so that the check fails
run: cargo clippy --no-deps -- -Dwarnings # -Dwarnings changes warnings to errors so that the check fails
- name: sdk tests
working-directory: tuta-sdk/rust
run: cargo test
5 changes: 4 additions & 1 deletion packages/node-mimimi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
serde_json = { workspace = true }
serde = { workspace = true }
tuta-sdk = { path = "../../tuta-sdk/rust/sdk", features = ["net", "testing"] }
mail-builder = { version = "0.4.0" }
mail-builder = { version = "0.4.0" }

[lints]
workspace = true
3 changes: 1 addition & 2 deletions packages/node-mimimi/src/importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl ImportEssential {
Ok(unit_import_results)
}

async fn make_serialized_chunk(
fn make_serialized_chunk(
&self,
importable_chunk: Vec<KeyedImportMailData>,
) -> Result<ImportMailPostIn, MailImportErrorMessage> {
Expand Down Expand Up @@ -636,7 +636,6 @@ impl Importer {
.inspect_err(|_e| failed_count += import_count_in_this_chunk)?;
let importable_post_data = import_essentials
.make_serialized_chunk(unit_import_data)
.await
.inspect_err(|_e| failed_count += import_count_in_this_chunk)?;

import_essentials
Expand Down
2 changes: 2 additions & 0 deletions packages/node-mimimi/src/importer/file_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl FileImport {
}

impl FileImport {
#[must_use]
pub fn new(eml_sources: Vec<PathBuf>) -> Self {
let message_parser = MessageParser::default();
Self {
Expand Down Expand Up @@ -172,6 +173,7 @@ impl FileImport {
fs::remove_file(import_dir.join(STATE_ID_FILE_NAME))
}

#[must_use]
pub fn make_import_directory_path(config_directory: &str, mailbox_id: &str) -> PathBuf {
[
config_directory.to_string(),
Expand Down
4 changes: 3 additions & 1 deletion packages/node-mimimi/src/importer/importable_mail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub struct KeyedImportableMailAttachment {
}

impl ImportableMailAttachment {
#[must_use]
pub fn make_keyed_importable_mail_attachment(
self,
essentials: &ImportEssential,
Expand All @@ -96,6 +97,7 @@ impl ImportableMailAttachment {
}

impl ImportableMailAttachmentMetaData {
#[must_use]
pub fn make_import_attachment_data(
self,
essentials: &ImportEssential,
Expand Down Expand Up @@ -315,7 +317,7 @@ impl ImportableMail {
.unwrap_or_else(|| Self::default_content_type().make_string().into_owned())
.to_string();

let content = content.to_vec();
let content = content.clone();
let attachment = ImportableMailAttachment {
meta_data: ImportableMailAttachmentMetaData {
filename,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ Hello äöüß
assert_eq!(m.attachments.len(), 1);
let attachment = &m.attachments[0];
let attached = parse_mail(
String::from_utf8(attachment.content.to_vec())
String::from_utf8(attachment.content.clone())
.unwrap()
.as_str(),
);
Expand Down Expand Up @@ -516,21 +516,21 @@ c2Vjb25kIGF0dGFjaG1lbnQ=
assert_eq!("a1.txt", a1.meta_data.filename);
assert_eq!(
String::from_utf8(base64_decode(b"Zmlyc3QgYXR0YWNobWVudA==").unwrap()).unwrap(),
String::from_utf8(a1.content.to_vec()).unwrap()
String::from_utf8(a1.content.clone()).unwrap()
);
assert_eq!("application/octet-stream", a1.meta_data.content_type);

assert_eq!("a2.pdf", a2.meta_data.filename);
assert_eq!(
String::from_utf8(base64_decode(b"c2Vjb25kIGF0dGFjaG1lbnQ=").unwrap()).unwrap(),
String::from_utf8(a2.content.to_vec()).unwrap()
String::from_utf8(a2.content.clone()).unwrap()
);
assert_eq!("application/pdf", a2.meta_data.content_type);

assert_eq!("withoutContentType.pdf", a3.meta_data.filename);
assert_eq!(
String::from_utf8(base64_decode(b"c2Vjb25kIGF0dGFjaG1lbnQ=").unwrap()).unwrap(),
String::from_utf8(a3.content.to_vec()).unwrap()
String::from_utf8(a3.content.clone()).unwrap()
);
assert_eq!(
r#"text/plain;charset="us-ascii""#,
Expand Down Expand Up @@ -567,7 +567,7 @@ Zmlyc3QgYXR0YWNobWVudA==
assert_eq!("a1.png", a1.meta_data.filename);
assert_eq!(
String::from_utf8(base64_decode(b"Zmlyc3QgYXR0YWNobWVudA==").unwrap()).unwrap(),
String::from_utf8(a1.content.to_vec()).unwrap()
String::from_utf8(a1.content.clone()).unwrap()
);
assert_eq!("application/octet-stream", a1.meta_data.content_type);
assert_eq!(Some("[email protected]".to_string()), a1.meta_data.content_id);
Expand Down Expand Up @@ -617,7 +617,7 @@ Zmlyc3QgYXR0YWNobWVudA==
);
assert_eq!(
String::from_utf8(base64_decode(b"Zmlyc3QgYXR0YWNobWVudA==").unwrap()).unwrap(),
String::from_utf8(indirect_attachment.content.to_vec()).unwrap()
String::from_utf8(indirect_attachment.content.clone()).unwrap()
);
}

Expand Down Expand Up @@ -685,7 +685,7 @@ Content-Disposition: attachment; filename=a1.html;
let a1 = &m.attachments[0];
assert_eq!(a1.meta_data.filename, "a1.html");
assert_eq!(
String::from_utf8(a1.content.to_vec()).unwrap(),
String::from_utf8(a1.content.clone()).unwrap(),
"<html><body><b><small>Hello äöüß</small></b><br></body></html>"
);
}
Expand Down Expand Up @@ -839,7 +839,7 @@ Abc, die Katze lief im Schnee ! äöü?ß ! "#;
let a1 = &m.attachments[0];
assert_eq!(a1.meta_data.filename, "a1.txt");
assert_eq!(
String::from_utf8(a1.content.to_vec()).unwrap(),
String::from_utf8(a1.content.clone()).unwrap(),
"Abc, die Katze lief im Schnee ! äöü?ß ! "
);
}
Expand Down Expand Up @@ -887,7 +887,7 @@ Zmlyc3QgYXR0YWNobWVudA=="#;
);
assert_eq!(
String::from_utf8(base64_decode(b"Zmlyc3QgYXR0YWNobWVudA==").unwrap()).unwrap(),
String::from_utf8(indirect_attachment.content.to_vec()).unwrap()
String::from_utf8(indirect_attachment.content.clone()).unwrap()
);
}

Expand All @@ -912,7 +912,7 @@ Zmlyc3QgYXR0YWNobWVudA=="#;
assert_eq!("äö߀.txt", indirect_attachment.meta_data.filename);
assert_eq!(
String::from_utf8(base64_decode(b"Zmlyc3QgYXR0YWNobWVudA==").unwrap()).unwrap(),
String::from_utf8(indirect_attachment.content.to_vec()).unwrap()
String::from_utf8(indirect_attachment.content.clone()).unwrap()
);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/node-mimimi/src/importer/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl ImportErrorKind {
}

impl MailImportErrorMessage {
#[must_use]
pub fn sdk(action: &'static str, error: ApiCallError) -> Self {
log::error!("ImportError::SdkError: {action} ({error})");

Expand All @@ -184,6 +185,7 @@ impl MailImportErrorMessage {
Self { kind, path: None }
}

#[must_use]
pub fn with_path(kind: ImportErrorKind, path: PathBuf) -> Self {
Self {
kind,
Expand All @@ -199,13 +201,15 @@ impl From<ImportErrorKind> for MailImportErrorMessage {
}

impl MailImportMessage {
#[must_use]
pub fn ok(ok_message: ImportOkKind) -> Self {
Self {
ok_message: Some(ok_message),
error_message: None,
}
}

#[must_use]
pub fn err(err_message: MailImportErrorMessage) -> Self {
Self {
ok_message: None,
Expand Down
2 changes: 1 addition & 1 deletion packages/node-mimimi/src/importer_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl From<TutaCredentials> for Credentials {
login: tuta_credentials.login,
user_id: GeneratedId(tuta_credentials.user_id),
access_token: tuta_credentials.access_token,
encrypted_passphrase_key: tuta_credentials.encrypted_passphrase_key.clone().to_vec(),
encrypted_passphrase_key: tuta_credentials.encrypted_passphrase_key.clone().clone(),
credential_type,
}
}
Expand Down
2 changes: 2 additions & 0 deletions tuta-sdk/rust/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ mockall = { version = "0.13.0" }
mockall_double = { version = "0.3.1" }
rand = { workspace = true }

[lints]
workspace = true
46 changes: 19 additions & 27 deletions tuta-sdk/rust/sdk/src/blobs/blob_facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ mod tests {
}

fn make_blob_service_response(
expected_reference_tokens: &Vec<BlobReferenceTokenWrapper>,
expected_reference_tokens: Vec<BlobReferenceTokenWrapper>,
type_model_provider: &Arc<TypeModelProvider>,
) -> Vec<u8> {
let blob_service_response = BlobPostOut {
Expand Down Expand Up @@ -664,7 +664,7 @@ mod tests {

let type_model_provider = Arc::new(init_type_model_provider());
let response_binary =
make_blob_service_response(&expected_reference_tokens, &type_model_provider);
make_blob_service_response(expected_reference_tokens, &type_model_provider);

let mut rest_client = MockRestClient::default();
rest_client
Expand Down Expand Up @@ -703,19 +703,19 @@ mod tests {
.unwrap();
assert_eq!(
vec![first_attachment_token],
reference_tokens.get(0).unwrap().to_vec()
reference_tokens.first().unwrap().clone()
);
assert_eq!(
vec![second_attachment_token],
reference_tokens.get(1).unwrap().to_vec()
reference_tokens.get(1).unwrap().clone()
);
assert_eq!(
vec![third_attachment_token],
reference_tokens.get(2).unwrap().to_vec()
reference_tokens.get(2).unwrap().clone()
);
assert_eq!(
vec![fourth_attachment_token],
reference_tokens.get(3).unwrap().to_vec()
reference_tokens.get(3).unwrap().clone()
);
}

Expand All @@ -732,7 +732,7 @@ mod tests {
let first_attachment: Vec<u8> = vec![0; 12 * 1024 * 1024];
let second_attachment: Vec<u8> = vec![0; 2 * 1024 * 1024];
let third_attachment: Vec<u8> = vec![0; 2 * 1024 * 1024];
let fourth_attachment: Vec<u8> = vec![0; 1 * 1024 * 1024];
let fourth_attachment: Vec<u8> = vec![0; 1024 * 1024];

let randomizer_facade1 = RandomizerFacade::from_core(DeterministicRng(1));
let randomizer_facade2 = RandomizerFacade::from_core(DeterministicRng(2));
Expand Down Expand Up @@ -793,9 +793,9 @@ mod tests {

let type_model_provider = Arc::new(init_type_model_provider());
let binary1: Vec<u8> =
make_blob_service_response(&expected_reference_tokens1, &type_model_provider);
make_blob_service_response(expected_reference_tokens1, &type_model_provider);
let binary2: Vec<u8> =
make_blob_service_response(&expected_reference_tokens2, &type_model_provider);
make_blob_service_response(expected_reference_tokens2, &type_model_provider);

let mut rest_client = MockRestClient::default();
// first request
Expand All @@ -809,11 +809,7 @@ mod tests {
let RestClientOptions { body, .. } = options;
let body = body.clone().unwrap();
let new_blob_wrappers = deserialize_new_blobs(body).unwrap();
if new_blob_wrappers.len() == 1 {
true
} else {
false
}
new_blob_wrappers.len() == 1
})
.return_const(Ok(RestResponse {
status: 200,
Expand All @@ -832,11 +828,7 @@ mod tests {
let RestClientOptions { body, .. } = options;
let body = body.clone().unwrap();
let new_blob_wrappers = deserialize_new_blobs(body).unwrap();
if new_blob_wrappers.len() == 4 {
true
} else {
false
}
new_blob_wrappers.len() == 4
})
.return_const(Ok(RestResponse {
status: 200,
Expand All @@ -860,19 +852,19 @@ mod tests {
.unwrap();
assert_eq!(
vec![first_attachment_first_token, first_attachment_second_token],
reference_tokens.get(0).unwrap().to_vec()
reference_tokens.first().unwrap().clone()
);
assert_eq!(
vec![second_attachment_token,],
reference_tokens.get(1).unwrap().to_vec()
reference_tokens.get(1).unwrap().clone()
);
assert_eq!(
vec![third_attachment_token,],
reference_tokens.get(2).unwrap().to_vec()
reference_tokens.get(2).unwrap().clone()
);
assert_eq!(
vec![fourth_attachment_token,],
reference_tokens.get(3).unwrap().to_vec()
reference_tokens.get(3).unwrap().clone()
);
}

Expand Down Expand Up @@ -940,13 +932,13 @@ mod tests {

let type_model_provider = Arc::new(init_type_model_provider());
let binary1: Vec<u8> =
make_blob_service_response(&expected_reference_tokens1, &type_model_provider);
make_blob_service_response(expected_reference_tokens1, &type_model_provider);
let binary2: Vec<u8> =
make_blob_service_response(&expected_reference_tokens2, &type_model_provider);
make_blob_service_response(expected_reference_tokens2, &type_model_provider);
let binary3: Vec<u8> =
make_blob_service_response(&expected_reference_tokens3, &type_model_provider);
make_blob_service_response(expected_reference_tokens3, &type_model_provider);
let binary4: Vec<u8> =
make_blob_service_response(&expected_reference_tokens4, &type_model_provider);
make_blob_service_response(expected_reference_tokens4, &type_model_provider);

let mut rest_client = MockRestClient::default();

Expand Down
14 changes: 5 additions & 9 deletions tuta-sdk/rust/sdk/src/crypto/crypto_facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ mod test {
let sender_keypair = EccKeyPair::generate(&randomizer_facade);

let protocol_version = CryptoProtocolVersion::TutaCrypt;
let mut raw_mail = make_raw_mail(
let raw_mail = make_raw_mail(
&constants,
constants.pub_enc_bucket_key.clone(),
protocol_version.clone() as i64,
Expand Down Expand Up @@ -362,7 +362,7 @@ mod test {
);

let key = crypto_facade
.resolve_session_key(&mut raw_mail, &mail_type_model)
.resolve_session_key(&raw_mail, &mail_type_model)
.await
.expect("should not have errored")
.expect("where is the key");
Expand All @@ -379,7 +379,7 @@ mod test {

let constants = BucketKeyConstants::new(&randomizer_facade);
let crypto_protocol_version = CryptoProtocolVersion::Rsa;
let mut raw_mail = make_raw_mail(
let raw_mail = make_raw_mail(
&constants,
constants.pub_enc_bucket_key.clone(),
crypto_protocol_version.clone() as i64,
Expand Down Expand Up @@ -410,7 +410,7 @@ mod test {

let mail_type_model = get_mail_type_model();
let key = crypto_facade
.resolve_session_key(&mut raw_mail, &mail_type_model)
.resolve_session_key(&raw_mail, &mail_type_model)
.await
.expect("should not have errored")
.expect("where is the key");
Expand Down Expand Up @@ -522,11 +522,7 @@ mod test {
})
.once();

let asymmetric_crypto_facade = if let Some(asymmetric_crypto) = asymmetric_crypto_facade {
asymmetric_crypto
} else {
MockAsymmetricCryptoFacade::default()
};
let asymmetric_crypto_facade = asymmetric_crypto_facade.unwrap_or_default();

CryptoFacade {
key_loader_facade: Arc::new(key_loader),
Expand Down
Loading

0 comments on commit 5abab26

Please sign in to comment.