mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 09:22:49 -05:00
fix(config): make runtime defaults explicit (#1389)
This commit is contained in:
1 parent
f01a680bff
commit
42669aaed9
12 files changed
+114
-13
No files matched your search
@@ -6,7 +6,10 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -26,4 +29,25 @@ class ApplicationDefaultsTest {
|
||||
"application.yml should enable CloudTrail by default");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void productionConfigUsesExpectedRequestSizeLimit() throws IOException {
|
||||
JsonNode config = new YAMLMapper().readTree(Path.of("src/main/resources/application.yml").toFile());
|
||||
|
||||
assertEquals(2048,
|
||||
config.path("floci").path("max-request-size").asInt(),
|
||||
"production application.yml should allow 2048 MB request bodies by default");
|
||||
}
|
||||
|
||||
@Test
|
||||
void productionConfigDoesNotSeedIamDeployerPrincipalByDefault() throws IOException {
|
||||
JsonNode config = new YAMLMapper().readTree(Path.of("src/main/resources/application.yml").toFile());
|
||||
|
||||
assertFalse(config.path("floci")
|
||||
.path("services")
|
||||
.path("iam")
|
||||
.path("seed-deployer-principal")
|
||||
.asBoolean(true),
|
||||
"production application.yml should not create default admin credentials unless enabled");
|
||||
}
|
||||
}
|
||||
@@ -237,7 +237,7 @@ class IamIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void stsGetCallerIdentityHonoursSeededFlociAccessKey() {
|
||||
void stsGetCallerIdentityFallsBackForUnseededFlociAccessKey() {
|
||||
given()
|
||||
.formParam("Action", "GetCallerIdentity")
|
||||
.header("Authorization",
|
||||
@@ -249,7 +249,7 @@ class IamIntegrationTest {
|
||||
.contentType("application/xml")
|
||||
.body("GetCallerIdentityResponse.GetCallerIdentityResult.Account", equalTo("000000000000"))
|
||||
.body("GetCallerIdentityResponse.GetCallerIdentityResult.Arn",
|
||||
equalTo("arn:aws:iam::000000000000:user/floci-deployer"));
|
||||
equalTo("arn:aws:iam::000000000000:root"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -431,7 +431,7 @@ class IamIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ListUsersResponse.ListUsersResult.Users.member.UserName",
|
||||
hasItem("test-user"));
|
||||
equalTo("test-user"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -25,15 +25,24 @@ class IamServiceTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
iamService = new IamService(
|
||||
iamService = iamService(false);
|
||||
}
|
||||
|
||||
private static IamService iamService(boolean seedDeployerPrincipal) {
|
||||
return iamService(seedDeployerPrincipal, new InMemoryStorage<>());
|
||||
}
|
||||
|
||||
private static IamService iamService(boolean seedDeployerPrincipal, InMemoryStorage<String, AccessKey> accessKeys) {
|
||||
return new IamService(
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
accessKeys,
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new RegionResolver("us-east-1", "000000000000")
|
||||
new RegionResolver("us-east-1", "000000000000"),
|
||||
seedDeployerPrincipal
|
||||
);
|
||||
}
|
||||
|
||||
@@ -507,7 +516,16 @@ class IamServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void seedDefaultsCreatesDefaultDeployerPrincipal() {
|
||||
void seedDefaultsDoesNotCreateDefaultDeployerPrincipalByDefault() {
|
||||
iamService.seedDefaults();
|
||||
|
||||
assertThrows(AwsException.class, () -> iamService.getUser("floci-deployer"));
|
||||
assertTrue(iamService.resolveCallerArn("floci").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void seedDefaultsCreatesConfiguredDefaultDeployerPrincipal() {
|
||||
iamService = iamService(true);
|
||||
iamService.seedDefaults();
|
||||
|
||||
IamUser user = iamService.getUser("floci-deployer");
|
||||
@@ -529,6 +547,21 @@ class IamServiceTest {
|
||||
assertEquals("PolicySourceArn must identify an IAM user or role.", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void seedDefaultsDoesNotReplaceExistingDeployerAccessKey() {
|
||||
InMemoryStorage<String, AccessKey> accessKeys = new InMemoryStorage<>();
|
||||
iamService = iamService(true, accessKeys);
|
||||
iamService.createUser("existing", "/");
|
||||
accessKeys.put("floci", new AccessKey("floci", "existing-secret", "existing"));
|
||||
|
||||
iamService.seedDefaults();
|
||||
|
||||
assertEquals(
|
||||
"arn:aws:iam::000000000000:user/existing",
|
||||
iamService.resolveCallerArn("floci").orElseThrow());
|
||||
assertEquals("existing-secret", iamService.findSecretKey("floci").orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
void attachManagedPolicyToRole() {
|
||||
iamService.seedAwsManagedPolicies();
|
||||
|
||||
Reference in new issue
Block a user