Skip to content

Commit

Permalink
spi-conf: Fix conf nacos password validation, create app's namespace …
Browse files Browse the repository at this point in the history
…after bundle register (#550)

* fix password validation

* create namespace after registered

* fix test
  • Loading branch information
4t145 authored Nov 28, 2023
1 parent cbef639 commit 30c3461
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
17 changes: 16 additions & 1 deletion spi/spi-conf/src/api/ci/conf_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ use tardis::{
};

use crate::{conf_constants::DOMAIN_CODE, serv::*};
use crate::{dto::conf_auth_dto::*, serv::placehodler::has_placeholder_auth};
use crate::{
dto::{conf_auth_dto::*, conf_namespace_dto::*},
serv::placehodler::has_placeholder_auth,
};

#[derive(Default, Clone, Copy, Debug)]

Expand Down Expand Up @@ -116,6 +119,18 @@ impl ConfCiAuthApi {
SpiBsServ::add_rel(&bs_id, app_tenant_id, &funs, &ctx).await?;
ctx.owner = app_tenant_id.to_string();
let resp = register(req.register_request, &funs, &ctx).await?;
if let Some((_, app)) = ctx.own_paths.split_once('/') {
create_namespace(
&mut NamespaceAttribute {
namespace: app.to_string(),
namespace_show_name: app.to_string(),
namespace_desc: None,
},
&funs,
&ctx,
)
.await?;
}
funs.commit().await?;
TardisResp::ok(resp)
}
Expand Down
6 changes: 3 additions & 3 deletions spi/spi-conf/src/dto/conf_auth_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ derive_into_nacos_auth! {
pub struct RegisterRequest {
#[oai(validator(pattern = r"^[a-zA-Z\d_]{5,16}$"))]
pub username: Option<TrimString>,
#[oai(validator(pattern = r"^[a-zA-Z\d~!@#$%^&*\(\)_+]{8,16}$"))]
#[oai(validator(pattern = r"^[a-zA-Z\d~!@#$%^&*\(\)_+\.]{8,16}$"))]
pub password: Option<TrimString>,
}

Expand Down Expand Up @@ -84,9 +84,9 @@ pub enum BackendServiceSource {
pub struct ChangePasswordRequest {
#[oai(validator(pattern = r"^[a-zA-Z\d_]{5,16}$"))]
pub username: TrimString,
#[oai(validator(pattern = r"^[a-zA-Z\d~!@#$%^&*\(\)_+]{8,16}$"))]
#[oai(validator(pattern = r"^[a-zA-Z\d~!@#$%^&*\(\)_+\.]{8,16}$"))]
pub old_password: TrimString,
#[oai(validator(pattern = r"^[a-zA-Z\d~!@#$%^&*\(\)_+]{8,16}$"))]
#[oai(validator(pattern = r"^[a-zA-Z\d~!@#$%^&*\(\)_+\.]{8,16}$"))]
pub password: Option<TrimString>,
}

Expand Down
20 changes: 10 additions & 10 deletions spi/spi-conf/tests/spi_conf_api_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ async fn spi_conf_namespace_test() -> TardisResult<()> {
start_web_server().await?;
let tardis_ctx = TardisContext::default();
let mut client = TestHttpClient::new("https://localhost:8080/spi-conf".to_string());
client.set_auth(&tardis_ctx)?;
client.set_auth(&TardisContext {
own_paths: "t1/app001".to_string(),
ak: "".to_string(),
roles: vec![],
groups: vec![],
owner: "app001".to_string(),
..Default::default()
})?;
let funs = TardisFuns::inst_with_db_conn(DOMAIN_CODE.to_string(), None);
let RegisterResponse { username, password } = client
.put(
Expand All @@ -49,14 +56,7 @@ async fn spi_conf_namespace_test() -> TardisResult<()> {
)
.await;
log::info!("username: {username}, password: {password}");
client.set_auth(&TardisContext {
own_paths: "t1/app001".to_string(),
ak: "".to_string(),
roles: vec![],
groups: vec![],
owner: "app001".to_string(),
..Default::default()
})?;

test_register(&mut client).await?;
test_curd(&mut client).await?;
test_tags(&mut client).await?;
Expand Down Expand Up @@ -123,7 +123,7 @@ pub async fn test_curd(client: &mut TestHttpClient) -> TardisResult<()> {
assert_eq!(_response.config_count, 1);
// 4.1 get namespace list
let _response = client.get::<Vec<NamespaceItem>>("/ci/namespace/list").await;
assert_eq!(_response.len(), 3);
assert_eq!(_response.len(), 4);
// since we have published a config, the config_count should be 1
// 5. delete config
client.delete("/ci/cs/config?namespace_id=public&group=DEFAULT-GROUP&data_id=conf-default").await;
Expand Down

0 comments on commit 30c3461

Please sign in to comment.