Merge remote-tracking branch 'gitee/master'
# Conflicts: # src/main/resources/application-dev.yml # src/main/resources/application-prod.yml
This commit is contained in:
commit
ff0232296f
78 files changed
+690
-395
No files matched your search
@@ -80,15 +80,12 @@ class ConfigurationDefaultsTest {
|
||||
var binder = Binder.get(context.getEnvironment());
|
||||
|
||||
var rateLimit = binder.bindOrCreate("rate-limit", RateLimitProperties.class);
|
||||
assertThat(rateLimit.getDefaultLimit()).isEqualTo(switch (profile) {
|
||||
assertThat(rateLimit.getLimit()).isEqualTo(switch (profile) {
|
||||
case "dev" -> 60;
|
||||
case "prod" -> 10;
|
||||
default -> 5;
|
||||
default -> 60;
|
||||
});
|
||||
assertThat(rateLimit.getDefaultWindow()).isEqualTo(Duration.ofSeconds(60));
|
||||
assertThat(rateLimit.getIp().isEnabled()).isTrue();
|
||||
assertThat(rateLimit.getIp().getLimit()).isEqualTo(1000);
|
||||
assertThat(rateLimit.getIp().getWindow()).isEqualTo(Duration.ofSeconds(60));
|
||||
assertThat(rateLimit.getWindow()).isEqualTo(Duration.ofSeconds(60));
|
||||
|
||||
var security = binder.bindOrCreate("security", SecurityProperties.class);
|
||||
assertThat(security.getToken().getAccessTokenTimeToLive()).isEqualTo(Duration.ofHours(2));
|
||||
@@ -119,6 +116,26 @@ class ConfigurationDefaultsTest {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 文档 UI 的开关与免登录路径按环境配置:开发与演示环境启用,生产环境关闭。
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"dev", "prod", "youlai"})
|
||||
void documentUiIsEnabledOutsideProduction(String profile) {
|
||||
contextRunner(profile).run(context -> {
|
||||
assertThat(context).hasNotFailed();
|
||||
assertThat(context.getEnvironment().getProperty("apidoc.enabled", Boolean.class, true))
|
||||
.as("文档 UI 应在生产环境关闭")
|
||||
.isEqualTo(!profile.equals("prod"));
|
||||
|
||||
var permitAllUrls = Binder.get(context.getEnvironment())
|
||||
.bindOrCreate("security", SecurityProperties.class).getPermitAllUrls();
|
||||
assertThat(permitAllUrls)
|
||||
.contains("/doc.html", "/apidoc/**")
|
||||
.allSatisfy(url -> assertThat(url).doesNotContain("${"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void multipartLimitsCanBeOverriddenIndependently() {
|
||||
contextRunner("dev")
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.youlai.boot.support.ai;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import com.youlai.boot.common.exception.BusinessException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.springframework.ai.chat.model.ChatModel;
|
||||
@@ -117,4 +118,33 @@ class AiConfigurationTest {
|
||||
server.stop(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void quotaExhaustedErrorIsTranslatedIntoReadableMessage() throws Exception {
|
||||
var server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
||||
server.createContext("/", exchange -> {
|
||||
byte[] response = """
|
||||
{"error":{"code":"AllocationQuota.FreeTierOnly",
|
||||
"message":"The free tier of the model has been exhausted.","type":"invalid_request_error"}}
|
||||
""".getBytes(StandardCharsets.UTF_8);
|
||||
exchange.getResponseHeaders().set("Content-Type", "application/json");
|
||||
exchange.sendResponseHeaders(403, response.length);
|
||||
try (var output = exchange.getResponseBody()) {
|
||||
output.write(response);
|
||||
}
|
||||
});
|
||||
server.start();
|
||||
try {
|
||||
runner.withPropertyValues("spring.profiles.active=dev",
|
||||
"spring.ai.model.chat=openai", "spring.ai.openai.api-key=test-key",
|
||||
"spring.ai.openai.base-url=http://127.0.0.1:" + server.getAddress().getPort()
|
||||
+ "/compatible-mode/v1")
|
||||
.run(context -> assertThatThrownBy(
|
||||
() -> context.getBean(AiChatService.class).chat("system", "test"))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessageContaining("额度"));
|
||||
} finally {
|
||||
server.stop(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user