SES: Correct Exception format + Java tests (#7346)
This commit is contained in:
parent
a9cec5e780
commit
e6818c3f1d
@ -1,100 +1,82 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
from moto.core.exceptions import RESTError
|
from moto.core.exceptions import RESTError
|
||||||
|
|
||||||
|
|
||||||
class MessageRejectedError(RESTError):
|
class SesError(RESTError):
|
||||||
code = 400
|
code = 400
|
||||||
|
|
||||||
|
def __init__(self, error_type: str, message: str, *args: Any, **kwargs: Any):
|
||||||
|
kwargs.setdefault("template", "wrapped_single_error")
|
||||||
|
super().__init__(error_type, message, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class MessageRejectedError(SesError):
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("MessageRejected", message)
|
super().__init__("MessageRejected", message)
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationSetDoesNotExist(RESTError):
|
class ConfigurationSetDoesNotExist(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("ConfigurationSetDoesNotExist", message)
|
super().__init__("ConfigurationSetDoesNotExist", message)
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationSetAlreadyExists(RESTError):
|
class ConfigurationSetAlreadyExists(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("ConfigurationSetAlreadyExists", message)
|
super().__init__("ConfigurationSetAlreadyExists", message)
|
||||||
|
|
||||||
|
|
||||||
class EventDestinationAlreadyExists(RESTError):
|
class EventDestinationAlreadyExists(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("EventDestinationAlreadyExists", message)
|
super().__init__("EventDestinationAlreadyExists", message)
|
||||||
|
|
||||||
|
|
||||||
class TemplateNameAlreadyExists(RESTError):
|
class TemplateNameAlreadyExists(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("TemplateNameAlreadyExists", message)
|
super().__init__("TemplateNameAlreadyExists", message)
|
||||||
|
|
||||||
|
|
||||||
class ValidationError(RESTError):
|
class ValidationError(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("ValidationError", message)
|
super().__init__("ValidationError", message)
|
||||||
|
|
||||||
|
|
||||||
class InvalidParameterValue(RESTError):
|
class InvalidParameterValue(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("InvalidParameterValue", message)
|
super().__init__("InvalidParameterValue", message)
|
||||||
|
|
||||||
|
|
||||||
class InvalidRenderingParameterException(RESTError):
|
class InvalidRenderingParameterException(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("InvalidRenderingParameterException", message)
|
super().__init__("InvalidRenderingParameterException", message)
|
||||||
|
|
||||||
|
|
||||||
class TemplateDoesNotExist(RESTError):
|
class TemplateDoesNotExist(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("TemplateDoesNotExist", message)
|
super().__init__("TemplateDoesNotExist", message)
|
||||||
|
|
||||||
|
|
||||||
class RuleSetNameAlreadyExists(RESTError):
|
class RuleSetNameAlreadyExists(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("RuleSetNameAlreadyExists", message)
|
super().__init__("RuleSetNameAlreadyExists", message)
|
||||||
|
|
||||||
|
|
||||||
class RuleAlreadyExists(RESTError):
|
class RuleAlreadyExists(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("RuleAlreadyExists", message)
|
super().__init__("RuleAlreadyExists", message)
|
||||||
|
|
||||||
|
|
||||||
class RuleSetDoesNotExist(RESTError):
|
class RuleSetDoesNotExist(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("RuleSetDoesNotExist", message)
|
super().__init__("RuleSetDoesNotExist", message)
|
||||||
|
|
||||||
|
|
||||||
class RuleDoesNotExist(RESTError):
|
class RuleDoesNotExist(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("RuleDoesNotExist", message)
|
super().__init__("RuleDoesNotExist", message)
|
||||||
|
|
||||||
|
|
||||||
class MissingRenderingAttributeException(RESTError):
|
class MissingRenderingAttributeException(SesError):
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, var: str):
|
def __init__(self, var: str):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"MissingRenderingAttributeException",
|
"MissingRenderingAttributeException",
|
||||||
|
@ -40,6 +40,10 @@
|
|||||||
<groupId>software.amazon.awssdk</groupId>
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
<artifactId>dynamodb</artifactId>
|
<artifactId>dynamodb</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
|
<artifactId>ses</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>software.amazon.awssdk</groupId>
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
<artifactId>s3</artifactId>
|
<artifactId>s3</artifactId>
|
||||||
|
@ -6,6 +6,7 @@ import software.amazon.awssdk.http.apache.ApacheHttpClient;
|
|||||||
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
|
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
|
||||||
import software.amazon.awssdk.regions.Region;
|
import software.amazon.awssdk.regions.Region;
|
||||||
import software.amazon.awssdk.services.s3.S3Client;
|
import software.amazon.awssdk.services.s3.S3Client;
|
||||||
|
import software.amazon.awssdk.services.ses.SesClient;
|
||||||
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
|
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
|
||||||
import software.amazon.awssdk.utils.AttributeMap;
|
import software.amazon.awssdk.utils.AttributeMap;
|
||||||
|
|
||||||
@ -32,6 +33,14 @@ public class DependencyFactory {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SesClient sesClient() {
|
||||||
|
return SesClient.builder()
|
||||||
|
.region(Region.US_EAST_1)
|
||||||
|
.httpClientBuilder(ApacheHttpClient.builder())
|
||||||
|
.endpointOverride(MOTO_URI)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
public static DynamoDbClient dynamoClient() {
|
public static DynamoDbClient dynamoClient() {
|
||||||
final AttributeMap attributeMap = AttributeMap.builder()
|
final AttributeMap attributeMap = AttributeMap.builder()
|
||||||
.put(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, true)
|
.put(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, true)
|
||||||
|
45
other_langs/tests_java/src/test/java/moto/tests/SESTest.java
Normal file
45
other_langs/tests_java/src/test/java/moto/tests/SESTest.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package moto.tests;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import software.amazon.awssdk.services.ses.SesClient;
|
||||||
|
import software.amazon.awssdk.services.ses.model.Body;
|
||||||
|
import software.amazon.awssdk.services.ses.model.Content;
|
||||||
|
import software.amazon.awssdk.services.ses.model.Destination;
|
||||||
|
import software.amazon.awssdk.services.ses.model.Message;
|
||||||
|
import software.amazon.awssdk.services.ses.model.SendEmailRequest;
|
||||||
|
import software.amazon.awssdk.services.ses.model.SendEmailResponse;
|
||||||
|
import software.amazon.awssdk.services.ses.model.SesException;
|
||||||
|
|
||||||
|
public class SESTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnverifiedEmail() {
|
||||||
|
SesClient sesClient = DependencyFactory.sesClient();
|
||||||
|
|
||||||
|
Message message = Message
|
||||||
|
.builder()
|
||||||
|
.subject(Content.builder().charset("UTF-8").data("subject").build())
|
||||||
|
.body(Body.builder().text(Content.builder().charset("UTF-8").data("body").build()).build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
SendEmailRequest request = SendEmailRequest
|
||||||
|
.builder()
|
||||||
|
.source("noreply@thedomain.com")
|
||||||
|
.destination(Destination.builder().toAddresses(List.of("one@one.com")).build())
|
||||||
|
.message(message)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println("Attempting to send an email...");
|
||||||
|
sesClient.sendEmail(request);
|
||||||
|
|
||||||
|
} catch (SesException e) {
|
||||||
|
assertEquals(e.awsErrorDetails().errorMessage(), "Email address not verified noreply@thedomain.com");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user