添加sign的测试
This commit is contained in:
parent
028c5a0c72
commit
57c1dd78eb
@ -68,7 +68,6 @@ impl Cluster {
|
||||
.expect("Failed to disconnect");
|
||||
}
|
||||
|
||||
///
|
||||
/// public async requestCert(): Promise<void> {
|
||||
/// const cert = await new Promise<{cert: string; key: string}>((resolve, reject) => {
|
||||
/// this.socket?.emit('request-cert', ([err, cert]: [unknown, {cert: string; key: string}]) => {
|
||||
@ -98,6 +97,27 @@ impl Cluster {
|
||||
let key = &data["key"];
|
||||
let cert_file = tmp_dir.clone().join("cert.pem");
|
||||
let key_file = tmp_dir.clone().join("key.pem");
|
||||
if cert_file.exists() {
|
||||
if tokio::fs::remove_file(cert_file.clone()).await.is_err() {
|
||||
warn!("remove cert file error");
|
||||
}
|
||||
|
||||
} else {
|
||||
if let Some(parent) = cert_file.parent() {
|
||||
if !parent.exists() {
|
||||
if tokio::fs::create_dir_all(parent).await.is_err() {
|
||||
warn!("create cert file parent dir error");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if key_file.exists() {
|
||||
if tokio::fs::remove_file(key_file.clone()).await.is_err() {
|
||||
warn!("remove key file error");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
},
|
||||
_ => (),
|
||||
|
24
src/utils.rs
24
src/utils.rs
@ -8,6 +8,7 @@ use apache_avro::{from_avro_datum, from_value, types::Value};
|
||||
use base64::Engine;
|
||||
use md5::{Digest, Md5};
|
||||
use sha1::Sha1;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tracing::{info, warn};
|
||||
|
||||
/// import {join} from 'path'
|
||||
@ -132,6 +133,17 @@ pub fn avro_data_to_file_list(data: Vec<u8>) -> Option<Vec<SyncFile>> {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn safe_write_file(path: &PathBuf, data: &[u8]) -> Result<(), std::io::Error> {
|
||||
let mut file = tokio::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(path)
|
||||
.await?;
|
||||
file.write_all(data).await?;
|
||||
file.sync_all().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// FATAL 级 Log
|
||||
/// 这个宏会输出一条 error 级的日志, 并且 panic!
|
||||
/// 这个宏应当接收两个参数, 分别定义为 arg1 和 arg2, 其应当均为 String 类型
|
||||
@ -184,3 +196,15 @@ fn test_validate_file() {
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_sign() {
|
||||
let mut query = HashMap::new();
|
||||
// 使用 21000101 00:00:00 UTC+8 作为日期
|
||||
let long_long_after = 4102416000_i64;
|
||||
query.insert("s".to_string(), "QiMQm3c-nXiUKu0Cmmp14hXnVk0=".to_string());
|
||||
query.insert("e".to_string(), long_long_after.to_string());
|
||||
let secret = "abcd";
|
||||
let hash = "1234567890abcdef";
|
||||
assert!(check_sign(hash, secret, &query));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user