fix: select project secret Spring constructor

This commit is contained in:
WANG TAIRAN 2026-08-11 17:16:37 +08:00
parent 0bd022aeea
commit 2b6498ef56
2 changed files with 9 additions and 0 deletions

View file

@ -11,6 +11,7 @@ import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -27,6 +28,7 @@ public class ProjectSecretService {
private final byte[] masterKey; private final byte[] masterKey;
private final SecureRandom secureRandom; private final SecureRandom secureRandom;
@Autowired
public ProjectSecretService(@Value("${xiaozhi.secret.master-key:}") String encodedMasterKey) { public ProjectSecretService(@Value("${xiaozhi.secret.master-key:}") String encodedMasterKey) {
this(encodedMasterKey, new SecureRandom()); this(encodedMasterKey, new SecureRandom());
} }

View file

@ -2,6 +2,7 @@ package xiaozhi.modules.security.secret;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -9,8 +10,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Base64; import java.util.Base64;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
class ProjectSecretServiceTest { class ProjectSecretServiceTest {
@Test
void productionConstructorIsExplicitlyAutowired() throws Exception {
assertNotNull(ProjectSecretService.class.getConstructor(String.class).getAnnotation(Autowired.class));
}
private static final String MASTER_KEY = Base64.getEncoder().encodeToString(new byte[32]); private static final String MASTER_KEY = Base64.getEncoder().encodeToString(new byte[32]);
@Test @Test