mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-26 17:03:43 +02:00
Rust tests
This commit is contained in:
parent
20b6f347c8
commit
d97643a390
4 changed files with 49 additions and 8 deletions
|
@ -562,7 +562,7 @@ Network::Network(const RuntimeEnvironment *renv, void *tPtr, uint64_t nwid, cons
|
|||
bool got = false;
|
||||
try {
|
||||
Dictionary dict;
|
||||
Vector< uint8_t > nconfData(RR->node->stateObjectGet(tPtr, ZT_STATE_OBJECT_NETWORK_CONFIG, tmp));
|
||||
Vector< uint8_t > nconfData(RR->node->stateObjectGet(tPtr, ZT_STATE_OBJECT_NETWORK_CONFIG, tmp, 1));
|
||||
if (nconfData.size() > 2) {
|
||||
nconfData.push_back(0);
|
||||
if (dict.decode(nconfData.data(), (unsigned int)nconfData.size())) {
|
||||
|
@ -579,7 +579,7 @@ Network::Network(const RuntimeEnvironment *renv, void *tPtr, uint64_t nwid, cons
|
|||
} catch (...) {}
|
||||
|
||||
if (!got)
|
||||
RR->node->stateObjectPut(tPtr, ZT_STATE_OBJECT_NETWORK_CONFIG, tmp, "\n", 1);
|
||||
RR->node->stateObjectPut(tPtr, ZT_STATE_OBJECT_NETWORK_CONFIG, tmp, 1, "\n", 1);
|
||||
}
|
||||
|
||||
if (!m_portInitialized) {
|
||||
|
@ -1068,7 +1068,7 @@ int Network::setConfiguration(void *tPtr, const NetworkConfig &nconf, bool saveT
|
|||
tmp[1] = 0;
|
||||
Vector< uint8_t > d2;
|
||||
d.encode(d2);
|
||||
RR->node->stateObjectPut(tPtr, ZT_STATE_OBJECT_NETWORK_CONFIG, tmp, d2.data(), (unsigned int)d2.size());
|
||||
RR->node->stateObjectPut(tPtr, ZT_STATE_OBJECT_NETWORK_CONFIG, tmp, 1, d2.data(), (unsigned int)d2.size());
|
||||
}
|
||||
} catch (...) {}
|
||||
}
|
||||
|
|
|
@ -764,4 +764,24 @@ mod tests {
|
|||
println!("certificate unique ID public: {}", hex::encode(uid.public).as_str());
|
||||
println!("certificate unique ID private: {}", hex::encode(uid.private).as_str());
|
||||
}
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn cert_encoding_decoding() {
|
||||
let mut cert = Certificate{
|
||||
serial_no: CertificateSerialNo::new(),
|
||||
flags: 1,
|
||||
timestamp: 2,
|
||||
validity: [ 3,4 ],
|
||||
subject: CertificateSubject::new(),
|
||||
issuer: None,
|
||||
issuer_name: CertificateName::new(),
|
||||
extended_attributes: Vec::new(),
|
||||
max_path_length: 123,
|
||||
signature: Vec::new()
|
||||
};
|
||||
cert.serial_no.0[1] = 2;
|
||||
cert.subject.certificates.push(CertificateSerialNo::new());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -204,3 +204,22 @@ impl<'de> serde::Deserialize<'de> for Identity {
|
|||
deserializer.deserialize_str(IdentityVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::*;
|
||||
|
||||
#[test]
|
||||
fn identity() {
|
||||
let test1 = Identity::new_generate(IdentityType::Curve25519);
|
||||
assert!(test1.is_ok());
|
||||
let test1 = test1.ok().unwrap();
|
||||
|
||||
let test2 = Identity::new_generate(IdentityType::NistP384);
|
||||
assert!(test2.is_ok());
|
||||
let test2 = test2.ok().unwrap();
|
||||
|
||||
println!("test type 0: {}", test1.to_secret_string());
|
||||
println!("test type 1: {}", test2.to_secret_string());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ extern "C" fn zt_event_callback<T: NodeEventHandler + 'static>(
|
|||
let ev2 = ev2.unwrap();
|
||||
let n = node_from_raw_ptr!(uptr);
|
||||
if data.is_null() {
|
||||
n.event_handler.event(ev2, &[u8; 0]);
|
||||
n.event_handler.event(ev2, &[0_u8; 0]);
|
||||
} else {
|
||||
let data2 = unsafe { &*slice_from_raw_parts(data.cast::<u8>(), data_size as usize) };
|
||||
n.event_handler.event(ev2, data2);
|
||||
|
@ -302,10 +302,12 @@ extern "C" fn zt_path_lookup_function<T: NodeEventHandler + 'static>(
|
|||
}
|
||||
let mut sock_family2: InetAddressFamily = InetAddressFamily::Nil;
|
||||
unsafe {
|
||||
match sock_family {
|
||||
ztcore::ZT_AF_INET => InetAddressFamily::IPv4,
|
||||
ztcore::ZT_AF_INET6 => InetAddressFamily::IPv6,
|
||||
_ => { return 0; }
|
||||
if sock_family == ztcore::ZT_AF_INET {
|
||||
sock_family2 = InetAddressFamily::IPv4;
|
||||
} else if sock_family == ztcore::ZT_AF_INET6 {
|
||||
sock_family2 = InetAddressFamily::IPv6;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue