fix e2e_test token validate

Signed-off-by: junxiang Mu <1948535941@qq.com>
This commit is contained in:
junxiang Mu
2024-10-12 09:05:53 +08:00
parent 8f14e0d024
commit adef6476ec
4 changed files with 1488 additions and 571 deletions
@@ -1,9 +1,10 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// @generated // @generated
use core::cmp::Ordering;
use core::mem; use core::mem;
use core::cmp::Ordering;
extern crate flatbuffers; extern crate flatbuffers;
use self::flatbuffers::{EndianScalar, Follow}; use self::flatbuffers::{EndianScalar, Follow};
@@ -11,8 +12,8 @@ use self::flatbuffers::{EndianScalar, Follow};
#[allow(unused_imports, dead_code)] #[allow(unused_imports, dead_code)]
pub mod models { pub mod models {
use core::cmp::Ordering;
use core::mem; use core::mem;
use core::cmp::Ordering;
extern crate flatbuffers; extern crate flatbuffers;
use self::flatbuffers::{EndianScalar, Follow}; use self::flatbuffers::{EndianScalar, Follow};
@@ -28,9 +29,7 @@ pub mod models {
type Inner = PingBody<'a>; type Inner = PingBody<'a>;
#[inline] #[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table::new(buf, loc) }
_tab: flatbuffers::Table::new(buf, loc),
}
} }
} }
@@ -48,30 +47,28 @@ pub mod models {
#[allow(unused_mut)] #[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
args: &'args PingBodyArgs<'args>, args: &'args PingBodyArgs<'args>
) -> flatbuffers::WIPOffset<PingBody<'bldr>> { ) -> flatbuffers::WIPOffset<PingBody<'bldr>> {
let mut builder = PingBodyBuilder::new(_fbb); let mut builder = PingBodyBuilder::new(_fbb);
if let Some(x) = args.payload { if let Some(x) = args.payload { builder.add_payload(x); }
builder.add_payload(x);
}
builder.finish() builder.finish()
} }
#[inline] #[inline]
pub fn payload(&self) -> Option<flatbuffers::Vector<'a, u8>> { pub fn payload(&self) -> Option<flatbuffers::Vector<'a, u8>> {
// Safety: // Safety:
// Created from valid Table for this object // Created from valid Table for this object
// which contains a valid value in this slot // which contains a valid value in this slot
unsafe { unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(PingBody::VT_PAYLOAD, None)}
self._tab
.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(PingBody::VT_PAYLOAD, None)
}
} }
} }
impl flatbuffers::Verifiable for PingBody<'_> { impl flatbuffers::Verifiable for PingBody<'_> {
#[inline] #[inline]
fn run_verifier(v: &mut flatbuffers::Verifier, pos: usize) -> Result<(), flatbuffers::InvalidFlatbuffer> { fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable; use self::flatbuffers::Verifiable;
v.visit_table(pos)? v.visit_table(pos)?
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, u8>>>("payload", Self::VT_PAYLOAD, false)? .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, u8>>>("payload", Self::VT_PAYLOAD, false)?
@@ -85,7 +82,9 @@ pub mod models {
impl<'a> Default for PingBodyArgs<'a> { impl<'a> Default for PingBodyArgs<'a> {
#[inline] #[inline]
fn default() -> Self { fn default() -> Self {
PingBodyArgs { payload: None } PingBodyArgs {
payload: None,
}
} }
} }
@@ -96,8 +95,7 @@ pub mod models {
impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> PingBodyBuilder<'a, 'b, A> { impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> PingBodyBuilder<'a, 'b, A> {
#[inline] #[inline]
pub fn add_payload(&mut self, payload: flatbuffers::WIPOffset<flatbuffers::Vector<'b , u8>>) { pub fn add_payload(&mut self, payload: flatbuffers::WIPOffset<flatbuffers::Vector<'b , u8>>) {
self.fbb_ self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(PingBody::VT_PAYLOAD, payload);
.push_slot_always::<flatbuffers::WIPOffset<_>>(PingBody::VT_PAYLOAD, payload);
} }
#[inline] #[inline]
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> PingBodyBuilder<'a, 'b, A> { pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> PingBodyBuilder<'a, 'b, A> {
@@ -122,3 +120,4 @@ pub mod models {
} }
} }
} // pub mod models } // pub mod models
File diff suppressed because it is too large Load Diff
+5 -42
View File
@@ -1,55 +1,18 @@
#![cfg(test)] #![cfg(test)]
use std::{collections::HashMap, error::Error, sync::Arc, time::Duration, vec}; use std::{error::Error, sync::Arc, time::Duration};
use lazy_static::lazy_static;
use lock::{ use lock::{
drwmutex::Options, drwmutex::Options,
lock_args::LockArgs, lock_args::LockArgs,
namespace_lock::{new_nslock, NsLockMap}, namespace_lock::{new_nslock, NsLockMap},
new_lock_api, new_lock_api,
}; };
use protos::proto_gen::node_service::{node_service_client::NodeServiceClient, GenerallyLockRequest}; use protos::{node_service_time_out_client, proto_gen::node_service::GenerallyLockRequest};
use tokio::sync::RwLock; use tokio::sync::RwLock;
use tonic::{ use tonic::Request;
metadata::MetadataValue,
service::interceptor::InterceptedService,
transport::{Channel, Endpoint},
Request, Status,
};
lazy_static! { const CLUSTER_ADDR: &str = "http://localhost:9000";
pub static ref GLOBAL_Conn_Map: RwLock<HashMap<String, Channel>> = RwLock::new(HashMap::new());
}
async fn get_client() -> Result<
NodeServiceClient<
InterceptedService<Channel, Box<dyn Fn(Request<()>) -> Result<Request<()>, Status> + Send + Sync + 'static>>,
>,
Box<dyn Error>,
> {
let token: MetadataValue<_> = "rustfs rpc".parse()?;
let channel = match GLOBAL_Conn_Map.read().await.get("local") {
Some(channel) => channel.clone(),
None => {
println!("get channel start");
let connector = Endpoint::from_static("http://localhost:9000").connect_timeout(Duration::from_secs(60));
let channel = connector.connect().await?;
// let channel = Channel::from_static("http://localhost:9000").connect().await?;
channel
}
};
GLOBAL_Conn_Map.write().await.insert("local".to_owned(), channel.clone());
// let timeout_channel = Timeout::new(channel, Duration::from_secs(60));
Ok(NodeServiceClient::with_interceptor(
channel,
Box::new(move |mut req: Request<()>| {
req.metadata_mut().insert("authorization", token.clone());
Ok(req)
}),
))
}
#[tokio::test] #[tokio::test]
async fn test_lock_unlock_rpc() -> Result<(), Box<dyn Error>> { async fn test_lock_unlock_rpc() -> Result<(), Box<dyn Error>> {
@@ -62,7 +25,7 @@ async fn test_lock_unlock_rpc() -> Result<(), Box<dyn Error>> {
}; };
let args = serde_json::to_string(&args)?; let args = serde_json::to_string(&args)?;
let mut client = get_client().await?; let mut client = node_service_time_out_client(&CLUSTER_ADDR.to_string()).await?;
println!("got client"); println!("got client");
let request = Request::new(GenerallyLockRequest { args: args.clone() }); let request = Request::new(GenerallyLockRequest { args: args.clone() });
+7 -11
View File
@@ -3,17 +3,13 @@
use ecstore::disk::VolumeInfo; use ecstore::disk::VolumeInfo;
use protos::{ use protos::{
models::{PingBody, PingBodyBuilder}, models::{PingBody, PingBodyBuilder},
proto_gen::node_service::{ node_service_time_out_client,
node_service_client::NodeServiceClient, ListVolumesRequest, MakeVolumeRequest, PingRequest, PingResponse, ReadAllRequest, proto_gen::node_service::{ListVolumesRequest, MakeVolumeRequest, PingRequest, PingResponse, ReadAllRequest},
},
}; };
use std::error::Error; use std::error::Error;
use tonic::Request; use tonic::Request;
async fn get_client() -> Result<NodeServiceClient<tonic::transport::Channel>, Box<dyn Error>> { const CLUSTER_ADDR: &str = "http://localhost:9000";
// Ok(NodeServiceClient::connect("http://220.181.1.138:9000").await?)
Ok(NodeServiceClient::connect("http://localhost:9000").await?)
}
#[tokio::test] #[tokio::test]
async fn ping() -> Result<(), Box<dyn Error>> { async fn ping() -> Result<(), Box<dyn Error>> {
@@ -31,7 +27,7 @@ async fn ping() -> Result<(), Box<dyn Error>> {
assert!(decoded_payload.is_ok()); assert!(decoded_payload.is_ok());
// 创建客户端 // 创建客户端
let mut client = get_client().await?; let mut client = node_service_time_out_client(&CLUSTER_ADDR.to_string()).await?;
// 构造 PingRequest // 构造 PingRequest
let request = Request::new(PingRequest { let request = Request::new(PingRequest {
@@ -55,7 +51,7 @@ async fn ping() -> Result<(), Box<dyn Error>> {
#[tokio::test] #[tokio::test]
async fn make_volume() -> Result<(), Box<dyn Error>> { async fn make_volume() -> Result<(), Box<dyn Error>> {
let mut client = get_client().await?; let mut client = node_service_time_out_client(&CLUSTER_ADDR.to_string()).await?;
let request = Request::new(MakeVolumeRequest { let request = Request::new(MakeVolumeRequest {
disk: "data".to_string(), disk: "data".to_string(),
volume: "dandan".to_string(), volume: "dandan".to_string(),
@@ -72,7 +68,7 @@ async fn make_volume() -> Result<(), Box<dyn Error>> {
#[tokio::test] #[tokio::test]
async fn list_volumes() -> Result<(), Box<dyn Error>> { async fn list_volumes() -> Result<(), Box<dyn Error>> {
let mut client = get_client().await?; let mut client = node_service_time_out_client(&CLUSTER_ADDR.to_string()).await?;
let request = Request::new(ListVolumesRequest { let request = Request::new(ListVolumesRequest {
disk: "data".to_string(), disk: "data".to_string(),
}); });
@@ -90,7 +86,7 @@ async fn list_volumes() -> Result<(), Box<dyn Error>> {
#[tokio::test] #[tokio::test]
async fn read_all() -> Result<(), Box<dyn Error>> { async fn read_all() -> Result<(), Box<dyn Error>> {
let mut client = get_client().await?; let mut client = node_service_time_out_client(&CLUSTER_ADDR.to_string()).await?;
let request = Request::new(ReadAllRequest { let request = Request::new(ReadAllRequest {
disk: "data".to_string(), disk: "data".to_string(),
volume: "ff".to_string(), volume: "ff".to_string(),