mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
feat(payments): 增加兑换码与支付适配框架 (#299)
* feat(payments): 增加兑换码与支付适配框架 * fix(ci): 对齐 Rust 1.95 lint 与格式要求 * fix(payments): harden redeem code wallet credits --------- Co-authored-by: fawney19 <elky0401@gmail.com>
This commit is contained in:
@@ -510,6 +510,93 @@ pub(super) fn classify_admin_basic_family_route(
|
||||
"admin:payments",
|
||||
false,
|
||||
))
|
||||
} else if method == http::Method::GET
|
||||
&& matches!(
|
||||
normalized_path,
|
||||
"/api/admin/payments/redeem-codes/batches"
|
||||
| "/api/admin/payments/redeem-codes/batches/"
|
||||
)
|
||||
{
|
||||
Some(classified(
|
||||
"admin_proxy",
|
||||
"payments_manage",
|
||||
"list_redeem_code_batches",
|
||||
"admin:payments",
|
||||
false,
|
||||
))
|
||||
} else if method == http::Method::POST
|
||||
&& matches!(
|
||||
normalized_path,
|
||||
"/api/admin/payments/redeem-codes/batches"
|
||||
| "/api/admin/payments/redeem-codes/batches/"
|
||||
)
|
||||
{
|
||||
Some(classified(
|
||||
"admin_proxy",
|
||||
"payments_manage",
|
||||
"create_redeem_code_batch",
|
||||
"admin:payments",
|
||||
false,
|
||||
))
|
||||
} else if method == http::Method::GET
|
||||
&& normalized_path_no_trailing.starts_with("/api/admin/payments/redeem-codes/batches/")
|
||||
&& normalized_path_no_trailing.matches('/').count() == 6
|
||||
{
|
||||
Some(classified(
|
||||
"admin_proxy",
|
||||
"payments_manage",
|
||||
"get_redeem_code_batch",
|
||||
"admin:payments",
|
||||
false,
|
||||
))
|
||||
} else if method == http::Method::GET
|
||||
&& normalized_path_no_trailing.starts_with("/api/admin/payments/redeem-codes/batches/")
|
||||
&& normalized_path_no_trailing.ends_with("/codes")
|
||||
&& normalized_path_no_trailing.matches('/').count() == 7
|
||||
{
|
||||
Some(classified(
|
||||
"admin_proxy",
|
||||
"payments_manage",
|
||||
"list_redeem_codes",
|
||||
"admin:payments",
|
||||
false,
|
||||
))
|
||||
} else if method == http::Method::POST
|
||||
&& normalized_path_no_trailing.starts_with("/api/admin/payments/redeem-codes/batches/")
|
||||
&& normalized_path_no_trailing.ends_with("/disable")
|
||||
&& normalized_path_no_trailing.matches('/').count() == 7
|
||||
{
|
||||
Some(classified(
|
||||
"admin_proxy",
|
||||
"payments_manage",
|
||||
"disable_redeem_code_batch",
|
||||
"admin:payments",
|
||||
false,
|
||||
))
|
||||
} else if method == http::Method::POST
|
||||
&& normalized_path_no_trailing.starts_with("/api/admin/payments/redeem-codes/batches/")
|
||||
&& normalized_path_no_trailing.ends_with("/delete")
|
||||
&& normalized_path_no_trailing.matches('/').count() == 7
|
||||
{
|
||||
Some(classified(
|
||||
"admin_proxy",
|
||||
"payments_manage",
|
||||
"delete_redeem_code_batch",
|
||||
"admin:payments",
|
||||
false,
|
||||
))
|
||||
} else if method == http::Method::POST
|
||||
&& normalized_path_no_trailing.starts_with("/api/admin/payments/redeem-codes/codes/")
|
||||
&& normalized_path_no_trailing.ends_with("/disable")
|
||||
&& normalized_path_no_trailing.matches('/').count() == 7
|
||||
{
|
||||
Some(classified(
|
||||
"admin_proxy",
|
||||
"payments_manage",
|
||||
"disable_redeem_code",
|
||||
"admin:payments",
|
||||
false,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -358,12 +358,13 @@ pub(super) fn classify_public_support_route(
|
||||
} else if method == http::Method::POST
|
||||
&& matches!(
|
||||
normalized_path,
|
||||
"/api/wallet/recharge" | "/api/wallet/refunds"
|
||||
"/api/wallet/recharge" | "/api/wallet/refunds" | "/api/wallet/redeem"
|
||||
)
|
||||
{
|
||||
let route_kind = match normalized_path {
|
||||
"/api/wallet/recharge" => "create_recharge_order",
|
||||
"/api/wallet/refunds" => "create_refund",
|
||||
"/api/wallet/redeem" => "redeem",
|
||||
_ => "create_recharge_order",
|
||||
};
|
||||
Some(classified(
|
||||
|
||||
@@ -136,3 +136,72 @@ fn classifies_admin_payments_callbacks_as_admin_proxy_route() {
|
||||
);
|
||||
assert!(!decision.is_execution_runtime_candidate());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classifies_admin_payments_redeem_code_routes_as_admin_proxy_route() {
|
||||
let headers = headers(&[]);
|
||||
|
||||
let list_batches_uri: Uri = "/api/admin/payments/redeem-codes/batches"
|
||||
.parse()
|
||||
.expect("uri should parse");
|
||||
let list_batches = classify_control_route(&http::Method::GET, &list_batches_uri, &headers)
|
||||
.expect("route should classify");
|
||||
assert_eq!(
|
||||
list_batches.route_family.as_deref(),
|
||||
Some("payments_manage")
|
||||
);
|
||||
assert_eq!(
|
||||
list_batches.route_kind.as_deref(),
|
||||
Some("list_redeem_code_batches")
|
||||
);
|
||||
|
||||
let create_batch_uri: Uri = "/api/admin/payments/redeem-codes/batches"
|
||||
.parse()
|
||||
.expect("uri should parse");
|
||||
let create_batch = classify_control_route(&http::Method::POST, &create_batch_uri, &headers)
|
||||
.expect("route should classify");
|
||||
assert_eq!(
|
||||
create_batch.route_family.as_deref(),
|
||||
Some("payments_manage")
|
||||
);
|
||||
assert_eq!(
|
||||
create_batch.route_kind.as_deref(),
|
||||
Some("create_redeem_code_batch")
|
||||
);
|
||||
|
||||
let list_codes_uri: Uri = "/api/admin/payments/redeem-codes/batches/batch-1/codes"
|
||||
.parse()
|
||||
.expect("uri should parse");
|
||||
let list_codes = classify_control_route(&http::Method::GET, &list_codes_uri, &headers)
|
||||
.expect("route should classify");
|
||||
assert_eq!(list_codes.route_family.as_deref(), Some("payments_manage"));
|
||||
assert_eq!(list_codes.route_kind.as_deref(), Some("list_redeem_codes"));
|
||||
|
||||
let disable_code_uri: Uri = "/api/admin/payments/redeem-codes/codes/code-1/disable"
|
||||
.parse()
|
||||
.expect("uri should parse");
|
||||
let disable_code = classify_control_route(&http::Method::POST, &disable_code_uri, &headers)
|
||||
.expect("route should classify");
|
||||
assert_eq!(
|
||||
disable_code.route_family.as_deref(),
|
||||
Some("payments_manage")
|
||||
);
|
||||
assert_eq!(
|
||||
disable_code.route_kind.as_deref(),
|
||||
Some("disable_redeem_code")
|
||||
);
|
||||
|
||||
let delete_batch_uri: Uri = "/api/admin/payments/redeem-codes/batches/batch-1/delete"
|
||||
.parse()
|
||||
.expect("uri should parse");
|
||||
let delete_batch = classify_control_route(&http::Method::POST, &delete_batch_uri, &headers)
|
||||
.expect("route should classify");
|
||||
assert_eq!(
|
||||
delete_batch.route_family.as_deref(),
|
||||
Some("payments_manage")
|
||||
);
|
||||
assert_eq!(
|
||||
delete_batch.route_kind.as_deref(),
|
||||
Some("delete_redeem_code_batch")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -211,6 +211,22 @@ fn classifies_user_monitoring_audit_logs_as_public_support_route() {
|
||||
assert!(!decision.is_execution_runtime_candidate());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classifies_wallet_redeem_as_public_support_route() {
|
||||
let headers = headers(&[("authorization", "Bearer sk-test")]);
|
||||
let uri: Uri = "/api/wallet/redeem".parse().expect("uri should parse");
|
||||
let decision =
|
||||
classify_control_route(&http::Method::POST, &uri, &headers).expect("route should classify");
|
||||
|
||||
assert_eq!(decision.route_class.as_deref(), Some("public_support"));
|
||||
assert_eq!(decision.route_family.as_deref(), Some("wallet"));
|
||||
assert_eq!(decision.route_kind.as_deref(), Some("redeem"));
|
||||
assert_eq!(
|
||||
decision.auth_endpoint_signature.as_deref(),
|
||||
Some("user:wallet")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classifies_announcement_unread_count_as_public_support_route() {
|
||||
let headers = headers(&[]);
|
||||
|
||||
Reference in New Issue
Block a user