Skip to content

Commit de413a3

Browse files
committed
TMP: Try adding a unit test that fails
1 parent 4baba02 commit de413a3

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

mullvad-api/Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread", "ne
3333
tokio-rustls = { version = "0.26.0", features = ["logging", "tls12", "ring"], default-features = false}
3434
tokio-socks = "0.5.1"
3535
rustls-pemfile = "2.1.3"
36+
uuid = { version = "1.4.1", features = ["v4"] }
3637

3738
mullvad-encrypted-dns-proxy = { path = "../mullvad-encrypted-dns-proxy" }
3839
mullvad-fs = { path = "../mullvad-fs" }
@@ -49,9 +50,6 @@ tokio = { workspace = true, features = ["test-util", "time"] }
4950
[build-dependencies]
5051
cbindgen = { version = "0.24.3", default-features = false }
5152

52-
[target.'cfg(target_os = "ios")'.dependencies]
53-
uuid = { version = "1.4.1", features = ["v4"] }
54-
5553
[lib]
5654
crate-type = [ "rlib", "staticlib" ]
5755
bench = false

mullvad-api/src/address_cache.rs

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ impl AddressCache {
5252
Self::new_inner(address, None)
5353
}
5454

55+
// #[cfg(target_os = "ios")]
56+
// pub fn with_static_hostname_addr(address: SocketAddr, hostname: &str) -> {
57+
58+
// }
59+
5560
/// Initialize cache using `read_path`, and write changes to `write_path`.
5661
pub async fn from_file(read_path: &Path, write_path: Option<Box<Path>>) -> Result<Self, Error> {
5762
log::debug!("Loading API addresses from {}", read_path.display());

mullvad-api/src/ffi/error.rs

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub enum MullvadApiErrorKind {
1313

1414
/// MullvadApiErrorKind contains a description and an error kind. If the error kind is
1515
/// `MullvadApiErrorKind` is NoError, the pointer will be nil.
16+
#[derive(Debug)]
1617
#[repr(C)]
1718
pub struct MullvadApiError {
1819
description: *mut libc::c_char,
@@ -47,6 +48,14 @@ impl MullvadApiError {
4748
}
4849
}
4950

51+
#[cfg(test)]
52+
pub fn unwrap(&self) {
53+
if ! matches!(self.kind, MullvadApiErrorKind::NoError) {
54+
let desc = unsafe { std::ffi::CStr::from_ptr(self.description) };
55+
panic!("API ERROR - {:?} - {}", self.kind, desc.to_str().unwrap());
56+
}
57+
}
58+
5059
pub fn drop(self) {
5160
if self.description.is_null() {
5261
return;

mullvad-api/src/ffi/mod.rs

+40
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,43 @@ unsafe fn string_from_raw_ptr(ptr: *const libc::c_char) -> Result<String, Mullva
443443
})?
444444
.to_owned())
445445
}
446+
447+
#[cfg(test)]
448+
mod test {
449+
use std::mem::MaybeUninit;
450+
451+
use super::*;
452+
const STAGING_SOCK_ADDR: &[u8] = b"185.217.116.129:443\0";
453+
const STAGING_HOSTNAME: &[u8] = b"api-app.stagemole.eu\0";
454+
455+
#[test]
456+
fn test_initialization() {
457+
let _ = create_client();
458+
459+
}
460+
461+
fn create_client() -> MullvadApiClient {
462+
let mut client = MaybeUninit::<MullvadApiClient>::uninit();
463+
let _client = unsafe {
464+
mullvad_api_client_initialize(
465+
client.as_mut_ptr(),
466+
STAGING_SOCK_ADDR.as_ptr().cast(),
467+
STAGING_HOSTNAME.as_ptr().cast(),
468+
)
469+
.unwrap();
470+
};
471+
unsafe {
472+
client.assume_init()
473+
}
474+
}
475+
476+
#[test]
477+
fn test_create_delete_account() {
478+
let client = create_client();
479+
480+
let mut account_buf_ptr = ptr::null_mut();
481+
482+
483+
unsafe { mullvad_api_create_account(client, account_buf_ptr).unwrap() };
484+
}
485+
}

mullvad-api/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ mod address_cache;
3737
pub mod device;
3838
mod relay_list;
3939

40-
#[cfg(target_os = "ios")]
4140
pub mod ffi;
4241

4342
pub use address_cache::AddressCache;
@@ -371,7 +370,6 @@ impl Runtime {
371370
)
372371
}
373372

374-
#[cfg(target_os = "ios")]
375373
pub fn with_static_addr(handle: tokio::runtime::Handle, address: SocketAddr) -> Self {
376374
Runtime {
377375
handle,
@@ -582,7 +580,6 @@ impl AccountsProxy {
582580
}
583581
}
584582

585-
#[cfg(target_os = "ios")]
586583
pub fn delete_account(
587584
&self,
588585
account: AccountNumber,

0 commit comments

Comments
 (0)