mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(account): add alternate contact operations (#3118)
* feat(account): add alternate contact operations * fix(account): complete alternate contact contracts
This commit is contained in:
1 parent
6345c37bad
commit
d80734e6de
18 files changed
+509
-3
No files matched your search
+2
-2
@@ -23,9 +23,9 @@ class UnknownServiceScopeGuardIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountScopedRestRequestGetsUnknownOperation() {
|
||||
void unsupportedRestServiceScopeGetsUnknownOperation() {
|
||||
given()
|
||||
.header("Authorization", authorization("account"))
|
||||
.header("Authorization", authorization("support"))
|
||||
.contentType("application/json")
|
||||
.body("{}")
|
||||
.when()
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package io.github.hectorvent.floci.services.account;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class AccountAlternateContactIntegrationTest {
|
||||
private static final String AUTH = "AWS4-HMAC-SHA256 Credential=AKID/20260904/us-east-1/account/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() { RestAssuredJsonUtils.configureAwsContentTypes(); }
|
||||
|
||||
@Test
|
||||
void createsUpdatesReadsAndDeletesAlternateContact() {
|
||||
put("security@example.com").statusCode(200);
|
||||
get().statusCode(200).body("AlternateContact.EmailAddress", equalTo("security@example.com"));
|
||||
put("security-updated@example.com").statusCode(200);
|
||||
get().statusCode(200).body("AlternateContact.EmailAddress", equalTo("security-updated@example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsInvalidContactType() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"AlternateContactType\":\"OTHER\"}")
|
||||
.post("/getAlternateContact").then().statusCode(400).body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsNonStringAccountIdInsteadOfFallingBackToCaller() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"AccountId\":123456789012,\"AlternateContactType\":\"SECURITY\",\"Name\":\"Security\",\"Title\":\"Owner\",\"EmailAddress\":\"security@example.com\",\"PhoneNumber\":\"+12025550123\"}")
|
||||
.post("/putAlternateContact").then().statusCode(400).body("__type", equalTo("SerializationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void trailingJsonReturnsSerializationException() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"AlternateContactType\":\"SECURITY\"} {}")
|
||||
.post("/getAlternateContact").then().statusCode(400).body("__type", equalTo("SerializationException"));
|
||||
}
|
||||
|
||||
private static io.restassured.response.ValidatableResponse put(String email) {
|
||||
return given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"AlternateContactType\":\"SECURITY\",\"Name\":\"Security\",\"Title\":\"Owner\",\"EmailAddress\":\"" + email + "\",\"PhoneNumber\":\"+12025550123\"}")
|
||||
.post("/putAlternateContact").then();
|
||||
}
|
||||
|
||||
private static io.restassured.response.ValidatableResponse get() {
|
||||
return given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"AlternateContactType\":\"SECURITY\"}")
|
||||
.post("/getAlternateContact").then();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package io.github.hectorvent.floci.services.account;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.account.model.AlternateContact;
|
||||
import io.github.hectorvent.floci.services.organizations.OrganizationsService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class AccountServiceTest {
|
||||
private static final String ACCOUNT_ID = "123456789012";
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private AccountService service;
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void setUp() {
|
||||
StorageFactory storageFactory = mock(StorageFactory.class);
|
||||
AccountAwareStorageBackend<AlternateContact> store = AccountAwareStorageBackend.inMemory(ACCOUNT_ID);
|
||||
when(storageFactory.create(eq("account"), eq("account-alternate-contacts.json"), any(TypeReference.class)))
|
||||
.thenReturn((AccountAwareStorageBackend) store);
|
||||
service = new AccountService(storageFactory, mock(OrganizationsService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ownAccountPutAndGetRoundTrip() {
|
||||
ObjectNode request = contactRequest();
|
||||
service.putAlternateContact(ACCOUNT_ID, request);
|
||||
AlternateContact contact = service.getAlternateContact(ACCOUNT_ID, request);
|
||||
assertEquals("security@example.com", contact.getEmailAddress());
|
||||
assertEquals("SECURITY", contact.getAlternateContactType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonStringAccountIdReturnsSerializationException() {
|
||||
ObjectNode request = contactRequest();
|
||||
request.put("AccountId", 123456789012L);
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.putAlternateContact(ACCOUNT_ID, request));
|
||||
assertEquals("SerializationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearRemovesContacts() {
|
||||
ObjectNode request = contactRequest();
|
||||
service.putAlternateContact(ACCOUNT_ID, request);
|
||||
service.clear();
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.getAlternateContact(ACCOUNT_ID, request));
|
||||
assertEquals("ResourceNotFoundException", error.getErrorCode());
|
||||
}
|
||||
|
||||
private ObjectNode contactRequest() {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("AlternateContactType", "SECURITY");
|
||||
request.put("EmailAddress", "security@example.com");
|
||||
request.put("Name", "Security Team");
|
||||
request.put("PhoneNumber", "+1 555 0100");
|
||||
request.put("Title", "Security");
|
||||
return request;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user