From 1143c63637f806fba0255fc68faaee4abfb2cbe2 Mon Sep 17 00:00:00 2001 From: 4t145 Date: Mon, 13 May 2024 16:20:30 +0800 Subject: [PATCH] fix spi-conf tests (#727) --- Cargo.toml | 4 ++-- backend/gateways/spacegate-plugins/src/lib.rs | 4 ++-- .../spacegate-plugins/src/plugin/anti_replay.rs | 2 +- .../src/plugin/op_redis_publisher.rs | 3 +-- backend/services/spacegate/Cargo.toml | 2 +- backend/services/spacegate/src/main.rs | 11 +++-------- backend/spi/spi-conf/src/serv.rs | 5 ++++- .../spi/spi-conf/src/serv/pg/conf_pg_config_serv.rs | 2 +- backend/spi/spi-conf/tests/spi_conf_api_test.rs | 2 +- backend/spi/spi-conf/tests/spi_conf_listener_test.rs | 4 ++-- .../spi-conf/tests/spi_conf_nacos_compatible_test.rs | 8 ++++---- backend/spi/spi-conf/tests/spi_conf_test_common.rs | 6 ------ 12 files changed, 22 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1b0abad37..a98bbd7f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,10 +76,10 @@ tardis = { version = "0.1.0-rc.15" } # "ext-redis", # "ext-axum", # ] } -spacegate-shell = { git = "https://github.com/ideal-world/spacegate.git", branch = "master", features = [ +spacegate-shell = { git = "https://github.com/ideal-world/spacegate.git", branch = "dev", features = [ "cache", "k8s", # "ext-redis", ] } -spacegate-plugin = { git = "https://github.com/ideal-world/spacegate.git", branch = "master" } +spacegate-plugin = { git = "https://github.com/ideal-world/spacegate.git", branch = "dev" } diff --git a/backend/gateways/spacegate-plugins/src/lib.rs b/backend/gateways/spacegate-plugins/src/lib.rs index fc138af71..f959ba66f 100644 --- a/backend/gateways/spacegate-plugins/src/lib.rs +++ b/backend/gateways/spacegate-plugins/src/lib.rs @@ -9,8 +9,8 @@ mod plugin; pub const PACKAGE_NAME: &str = "spacegate_lib"; use plugin::op_redis_publisher; -use spacegate_shell::plugin::SgPluginRepository; -pub fn register_lib_plugins(repo: &SgPluginRepository) { +use spacegate_shell::plugin::PluginRepository; +pub fn register_lib_plugins(repo: &PluginRepository) { repo.register::(); repo.register::(); repo.register::(); diff --git a/backend/gateways/spacegate-plugins/src/plugin/anti_replay.rs b/backend/gateways/spacegate-plugins/src/plugin/anti_replay.rs index af3e5540d..a4d5eee02 100644 --- a/backend/gateways/spacegate-plugins/src/plugin/anti_replay.rs +++ b/backend/gateways/spacegate-plugins/src/plugin/anti_replay.rs @@ -6,7 +6,7 @@ use spacegate_shell::hyper::{Request, Response, StatusCode}; use spacegate_shell::kernel::extension::PeerAddr; use spacegate_shell::kernel::helper_layers::function::Inner; use spacegate_shell::plugin::{Plugin, PluginError}; -use spacegate_shell::spacegate_ext_redis::{redis::AsyncCommands, RedisClient}; +use spacegate_shell::ext_redis::{redis::AsyncCommands, RedisClient}; use spacegate_shell::{BoxError, SgBody, SgRequestExt, SgResponseExt}; use tardis::serde_json; diff --git a/backend/gateways/spacegate-plugins/src/plugin/op_redis_publisher.rs b/backend/gateways/spacegate-plugins/src/plugin/op_redis_publisher.rs index 770c13687..5024639e1 100644 --- a/backend/gateways/spacegate-plugins/src/plugin/op_redis_publisher.rs +++ b/backend/gateways/spacegate-plugins/src/plugin/op_redis_publisher.rs @@ -43,11 +43,10 @@ impl Plugin for RedisPublisherPlugin { const CODE: &'static str = "op_redis_publisher"; fn create(config: PluginConfig) -> Result { - let id = config.none_mono_id(); let layer_config = serde_json::from_value::(config.spec.clone())?; Ok(Self { - key: id.redis_prefix(), + key: config.id.redis_prefix(), jsonpath_inst: if let Ok(jsonpath_inst) = JsonPathInst::from_str(&layer_config.success_json_path).map_err(|e| log::error!("[Plugin.AuditLog] invalid json path:{e}")) { Some(jsonpath_inst) } else { diff --git a/backend/services/spacegate/Cargo.toml b/backend/services/spacegate/Cargo.toml index 881d235ab..d15eb5f8d 100644 --- a/backend/services/spacegate/Cargo.toml +++ b/backend/services/spacegate/Cargo.toml @@ -19,7 +19,7 @@ spacegate-shell = { workspace = true, features = [ "k8s", "plugin-all", "ext-redis", - # "ext-axum", + "ext-axum", "cache", ] } tardis = { workspace = true } diff --git a/backend/services/spacegate/src/main.rs b/backend/services/spacegate/src/main.rs index 4df476f3e..b1991025f 100644 --- a/backend/services/spacegate/src/main.rs +++ b/backend/services/spacegate/src/main.rs @@ -1,6 +1,6 @@ use serde::Deserialize; use spacegate_plugins::register_lib_plugins; -use spacegate_shell::plugin::SgPluginRepository; +use spacegate_shell::plugin::PluginRepository; use spacegate_shell::BoxError; use tardis::basic::tracing::TardisTracing; use tardis::tokio; @@ -25,14 +25,9 @@ fn main() -> Result<(), BoxError> { } let rt = builder.build().expect("fail to build runtime"); let namespaces = std::env::args().nth(1).or(config.spacegate_ns); - register_lib_plugins(SgPluginRepository::global()); + register_lib_plugins(PluginRepository::global()); rt.block_on(async move { let local_set = tokio::task::LocalSet::new(); - local_set - .run_until(async move { - let join_handle = spacegate_shell::startup_k8s(namespaces.as_deref()).await.expect("fail to start spacegate"); - join_handle.await.expect("join handle error") - }) - .await + local_set.run_until(async move { spacegate_shell::startup_k8s(namespaces.as_deref()).await }).await }) } diff --git a/backend/spi/spi-conf/src/serv.rs b/backend/spi/spi-conf/src/serv.rs index c5ee99c6f..760bbe2b7 100644 --- a/backend/spi/spi-conf/src/serv.rs +++ b/backend/spi/spi-conf/src/serv.rs @@ -166,7 +166,8 @@ pub async fn register(req: RegisterRequest, funs: &TardisFunsInst, ctx: &TardisC // add a cert let ext = json!({ "owner": ctx.owner, - "own_paths": ctx.own_paths + "own_paths": ctx.own_paths, + "ak": ctx.ak }) .to_string(); let mut add_cert_req = RbumCertAddReq { @@ -228,8 +229,10 @@ pub async fn auth(ak: &str, sk: &str, funs: &TardisFunsInst) -> TardisResult TardisResult<()> { let mut client = TestHttpClient::new("https://127.0.0.1:8080/spi-conf".to_string()); client.set_auth(&TardisContext { own_paths: "t1/app001".to_string(), - ak: "".to_string(), + ak: "app001".to_string(), roles: vec![], groups: vec![], owner: "app001".to_string(), diff --git a/backend/spi/spi-conf/tests/spi_conf_listener_test.rs b/backend/spi/spi-conf/tests/spi_conf_listener_test.rs index f74aa66cb..d1b7ba516 100644 --- a/backend/spi/spi-conf/tests/spi_conf_listener_test.rs +++ b/backend/spi/spi-conf/tests/spi_conf_listener_test.rs @@ -49,7 +49,7 @@ async fn spi_conf_namespace_test() -> TardisResult<()> { log::info!("username: {username}, password: {password}"); client.set_auth(&TardisContext { own_paths: "t1/app001".to_string(), - ak: "".to_string(), + ak: "app001".to_string(), roles: vec![], groups: vec![], owner: "app001".to_string(), @@ -119,7 +119,7 @@ pub async fn test_listener(client: &mut TestHttpClient) -> TardisResult<()> { let update_counter = Arc::new(AtomicUsize::new(0)); let ctx_raw = Arc::new(TardisContext { own_paths: "t1/app001".to_string(), - ak: "".to_string(), + ak: "app001".to_string(), roles: vec![], groups: vec![], owner: "app001".to_string(), diff --git a/backend/spi/spi-conf/tests/spi_conf_nacos_compatible_test.rs b/backend/spi/spi-conf/tests/spi_conf_nacos_compatible_test.rs index 2286ce516..13c0bed2f 100644 --- a/backend/spi/spi-conf/tests/spi_conf_nacos_compatible_test.rs +++ b/backend/spi/spi-conf/tests/spi_conf_nacos_compatible_test.rs @@ -22,7 +22,7 @@ const SCHEMA: &str = "https"; async fn spi_conf_namespace_test() -> TardisResult<()> { std::env::set_var( "RUST_LOG", - "info,tardis=debug,spi_conf_listener_test=debug,sqlx=off,sea_orm=off,bios_spi_conf=DEBUG,poem_grpc=TRACE,tonic=TRACE", + "info,tardis=debug,spi_conf_listener_test=debug,sqlx=off,sea_orm=debug,bios_spi_conf=DEBUG,poem_grpc=TRACE,tonic=TRACE", ); std::env::set_var("PROFILE", "nacos"); let docker = testcontainers::clients::Cli::default(); @@ -51,7 +51,7 @@ async fn spi_conf_namespace_test() -> TardisResult<()> { log::info!("username: {username}, password: {password}"); client.set_auth(&TardisContext { own_paths: "t1/app001".to_string(), - ak: "".to_string(), + ak: "app001".to_string(), roles: vec![], groups: vec![], owner: "app001".to_string(), @@ -71,7 +71,7 @@ async fn test_tardis_compatibility(_test_client: &TestHttpClient) -> TardisResul let config = TardisFuns::fw_config(); let ctx = TardisContext { own_paths: "t1/app001".to_string(), - ak: "".to_string(), + ak: "app001".to_string(), roles: vec![], groups: vec![], owner: "app001".to_string(), @@ -196,7 +196,7 @@ async fn test_tardis_compatibility(_test_client: &TestHttpClient) -> TardisResul let _resp = nacos_client .publish_config( &NacosConfigDescriptor::new("hc-db.yaml", "hc", &(Default::default())), - &mut std::fs::File::open("tests/config/test-prod.yaml").expect("fail to open"), + &mut std::fs::File::open("tests/config/conf-nacos.toml").expect("fail to open"), ) .await .expect("publish failed"); diff --git a/backend/spi/spi-conf/tests/spi_conf_test_common.rs b/backend/spi/spi-conf/tests/spi_conf_test_common.rs index 644796944..212e92d9e 100644 --- a/backend/spi/spi-conf/tests/spi_conf_test_common.rs +++ b/backend/spi/spi-conf/tests/spi_conf_test_common.rs @@ -14,7 +14,6 @@ use testcontainers_modules::redis::Redis; pub struct Holder<'d> { pub pg: Container<'d, GenericImage>, pub redis: Container<'d, Redis>, - pub mq: Container<'d, GenericImage>, } #[allow(dead_code)] @@ -27,14 +26,9 @@ pub async fn init_tardis(docker: &Cli) -> TardisResult { let port = redis_container.get_host_port_ipv4(6379); let url = format!("redis://127.0.0.1:{port}/0"); std::env::set_var("TARDIS_FW.CACHE.URL", url); - let mq_container = TardisTestContainer::rabbit_custom(docker); - let port = mq_container.get_host_port_ipv4(5672); - let url = format!("amqp://guest:guest@127.0.0.1:{port}/%2f"); - std::env::set_var("TARDIS_FW.MQ.URL", url); let holder = Holder { pg: reldb_container, redis: redis_container, - mq: mq_container, }; TardisFuns::init(Some("tests/config")).await?; bios_basic::rbum::rbum_initializer::init(DOMAIN_CODE, RbumConfig::default()).await?;