Add new tests
This commit is contained in:
parent
89d5282b0f
commit
675418f411
9 changed files with 1057 additions and 13 deletions
|
|
@ -1,11 +1,7 @@
|
|||
package ai.nomyo;
|
||||
|
||||
import ai.nomyo.errors.APIConnectionError;
|
||||
import ai.nomyo.errors.SecurityError;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* Entry point — loads RSA keys and validates key length.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package ai.nomyo;
|
|||
import ai.nomyo.errors.*;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -69,7 +68,7 @@ public class SecureChatCompletion {
|
|||
* @throws ServiceUnavailableError HTTP 503
|
||||
* @throws APIError other errors
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"JavadocDeclaration"})
|
||||
public Map<String, Object> create(String model, List<Map<String, Object>> messages, Map<String, Object> kwargs) {
|
||||
// Validate required parameters
|
||||
if (model == null || model.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import ai.nomyo.errors.*;
|
|||
import ai.nomyo.util.PEMConverter;
|
||||
import ai.nomyo.util.Pass2Key;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.GCMParameterSpec;
|
||||
|
|
@ -23,7 +22,6 @@ import java.nio.file.attribute.PosixFilePermissions;
|
|||
import java.security.*;
|
||||
import java.security.spec.*;
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
|
|
@ -172,8 +170,6 @@ public class SecureCompletionClient {
|
|||
this.privateKey = pair.getPrivate();
|
||||
this.publicPemKey = publicPem;
|
||||
|
||||
} catch (SecurityError e) {
|
||||
throw e;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new SecurityError("RSA algorithm not available: " + e.getMessage(), e);
|
||||
} catch (InvalidAlgorithmParameterException e) {
|
||||
|
|
@ -329,7 +325,7 @@ public class SecureCompletionClient {
|
|||
byte[] nonce = new byte[Constants.GCM_NONCE_SIZE];
|
||||
random.nextBytes(nonce);
|
||||
|
||||
Cipher cipher = null;
|
||||
Cipher cipher;
|
||||
try {
|
||||
cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(aesKey.getEncoded(), "AES"), new GCMParameterSpec(Constants.GCM_TAG_SIZE * Byte.SIZE, nonce));
|
||||
|
|
@ -356,7 +352,7 @@ public class SecureCompletionClient {
|
|||
} catch (ExecutionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof SecurityError) {
|
||||
throw new RuntimeException((SecurityError) cause);
|
||||
throw new RuntimeException(cause);
|
||||
}
|
||||
throw new RuntimeException(new SecurityError("Failed to fetch server public key: " + cause.getMessage(), cause));
|
||||
}
|
||||
|
|
@ -423,6 +419,7 @@ public class SecureCompletionClient {
|
|||
* @throws ServiceUnavailableError HTTP 503
|
||||
* @throws APIError other errors
|
||||
*/
|
||||
@SuppressWarnings("JavadocDeclaration")
|
||||
public CompletableFuture<Map<String, Object>> sendSecureRequest(Map<String, Object> payload, String payloadId, String apiKey, String securityTier) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
// Validate security tier if provided
|
||||
|
|
@ -447,7 +444,7 @@ public class SecureCompletionClient {
|
|||
} catch (ExecutionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof SecurityError) {
|
||||
throw new CompletionException((SecurityError) cause);
|
||||
throw new CompletionException(cause);
|
||||
}
|
||||
throw new CompletionException(new SecurityError("Encryption failed: " + cause.getMessage(), cause));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue