1.PROXY\_ACCOUNT 租赁账户,首页中的租赁套餐 ,立即租赁按钮不可操作,帮我完成这个功能,点击立即租赁,跳出输入地址,apiKey,apiSecret,时长,对接地址,回调地址等,然后显示预计费用,然后调用租赁api 2. 帮我实现回调地址同步和异步验证的demo的controller
This commit is contained in:
1 parent
127d575a1c
commit
8dcb313454
9 files changed
+408
-3
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package com.ruoyi.system.rental;
|
||||
|
||||
import static com.ruoyi.system.rental.RentalValues.*;
|
||||
import static org.junit.Assert.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
import org.junit.Test;
|
||||
|
||||
/** 计费与回调签名协议的纯函数回归,不访问外部服务。 */
|
||||
public class RentalPricingTest {
|
||||
@Test
|
||||
public void durationScalesBothPricesWithoutChangingQuantityOrOriginal() {
|
||||
Map<String, Object> product = map("duration_seconds", 3600, "sale_amount", "3.000000",
|
||||
"supplier_amount", "2.000000", "resource_quantity", 65000);
|
||||
Map<String, Object> price = RentalPricing.price(product, map("duration_seconds", 7200));
|
||||
assertEquals(new BigDecimal("6.000000"), amount(price, "sale_amount"));
|
||||
assertEquals(new BigDecimal("4.000000"), amount(price, "supplier_amount"));
|
||||
assertEquals(65000, number(price, "resource_quantity"));
|
||||
assertEquals(3600, number(product, "duration_seconds"));
|
||||
for (long duration : new long[] {0, -1, 3601, 3600L * 721}) {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> RentalPricing.price(product, map("duration_seconds", duration)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void callbackRejectsWrongScopeTamperingPathAndExpiredTime() {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String key = "RKdemo", secret = "test-secret", nonce = "1234567890abcdef";
|
||||
String path = "/api/rental/v1/demo/callback/sync", body = "{\"event_no\":\"WH1\"}";
|
||||
String signature = RentalCrypto.sign(secret, "WEBHOOK", key, timestamp, nonce, "POST", path, body);
|
||||
RentalCallbackDemoController.verify(key, secret, key, timestamp, nonce, path, body, signature, timestamp);
|
||||
assertThrows(IllegalArgumentException.class, () -> RentalCallbackDemoController.verify(
|
||||
key, secret, key, timestamp, nonce, path, body + " ", signature, timestamp));
|
||||
assertThrows(IllegalArgumentException.class, () -> RentalCallbackDemoController.verify(
|
||||
key, secret, key, timestamp, nonce, path + "x", body, signature, timestamp));
|
||||
assertThrows(IllegalArgumentException.class, () -> RentalCallbackDemoController.verify(
|
||||
key, secret, key, timestamp, nonce, path, body, signature, timestamp + 61000));
|
||||
String apiSignature = RentalCrypto.sign(secret, "API", key, timestamp, nonce, "POST", path, body);
|
||||
assertThrows(IllegalArgumentException.class, () -> RentalCallbackDemoController.verify(
|
||||
key, secret, key, timestamp, nonce, path, body, apiSignature, timestamp));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user