mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(cloudformation): provision signing profiles and code signing configs (#7546)
This commit is contained in:
1 parent
ee038af772
commit
b35e51374c
22 files changed
+1173
-35
No files matched your search
+8
@@ -35,6 +35,14 @@ class CfnCreateOnlyPropertiesTest {
|
||||
assertTrue(CfnCreateOnlyProperties.isCreateOnly("AWS::IoT::Authorizer", "SigningDisabled"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void signingProfileReplacesForEverythingButTags() {
|
||||
assertTrue(CfnCreateOnlyProperties.isCreateOnly("AWS::Signer::SigningProfile", "ProfileName"));
|
||||
assertTrue(CfnCreateOnlyProperties.isCreateOnly("AWS::Signer::SigningProfile", "PlatformId"));
|
||||
assertTrue(CfnCreateOnlyProperties.isCreateOnly("AWS::Signer::SigningProfile", "SignatureValidityPeriod"));
|
||||
assertFalse(CfnCreateOnlyProperties.isCreateOnly("AWS::Signer::SigningProfile", "Tags"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isCreateOnly_returnsFalseForMutableProperties() {
|
||||
assertFalse(CfnCreateOnlyProperties.isCreateOnly("AWS::SQS::Queue", "VisibilityTimeout"));
|
||||
|
||||
+14
@@ -90,6 +90,7 @@ import io.github.hectorvent.floci.services.cloudformation.provisioners.KinesisCf
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.KmsCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.LambdaAddressingCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.LambdaCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.LambdaCodeSigningConfigCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.LambdaEventInvokeConfigCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.LambdaEventSourceMappingCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.LambdaMicrovmsCfnProvisioner;
|
||||
@@ -113,6 +114,7 @@ import io.github.hectorvent.floci.services.cloudformation.provisioners.SecretTar
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.SecretsManagerCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.SesCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.SesReceiptRuleCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.SignerCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.SnsCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.SqsCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.SsmCfnProvisioner;
|
||||
@@ -152,6 +154,7 @@ import io.github.hectorvent.floci.services.iot.IotDomainConfigurationService;
|
||||
import io.github.hectorvent.floci.services.iot.IotService;
|
||||
import io.github.hectorvent.floci.services.kinesis.KinesisService;
|
||||
import io.github.hectorvent.floci.services.kms.KmsService;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaCodeSigningConfigService;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaLayerService;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaService;
|
||||
import io.github.hectorvent.floci.services.lambdamicrovms.LambdaMicrovmsService;
|
||||
@@ -213,6 +216,7 @@ final class CfnProvisionerFixture {
|
||||
private SesIdentityService sesIdentityService;
|
||||
private DynamoDbService dynamoDbService;
|
||||
private LambdaService lambdaService;
|
||||
private LambdaCodeSigningConfigService lambdaCodeSigningConfigService;
|
||||
private AppSyncService appSyncService;
|
||||
private AppConfigService appConfigService;
|
||||
private IamService iamService;
|
||||
@@ -315,6 +319,7 @@ final class CfnProvisionerFixture {
|
||||
ensureDynamicReferences();
|
||||
List<CfnResourceProvisioner> discovered = new ArrayList<>();
|
||||
discovered.add(new CdkMetadataCfnProvisioner());
|
||||
discovered.add(new SignerCfnProvisioner());
|
||||
if (stepFunctionsService != null) {
|
||||
discovered.add(new StepFunctionsCfnProvisioner(stepFunctionsService, s3Service, objectMapper));
|
||||
}
|
||||
@@ -440,6 +445,10 @@ final class CfnProvisionerFixture {
|
||||
discovered.add(new LambdaEventInvokeConfigCfnProvisioner(lambdaService));
|
||||
discovered.add(new LambdaVersionAliasCfnProvisioner(lambdaService));
|
||||
discovered.add(new LambdaEventSourceMappingCfnProvisioner(lambdaService));
|
||||
if (lambdaCodeSigningConfigService != null) {
|
||||
discovered.add(new LambdaCodeSigningConfigCfnProvisioner(lambdaCodeSigningConfigService,
|
||||
lambdaService));
|
||||
}
|
||||
}
|
||||
if (flowLogService != null) {
|
||||
discovered.add(new Ec2FlowLogCfnProvisioner(flowLogService, ec2Service));
|
||||
@@ -588,6 +597,11 @@ final class CfnProvisionerFixture {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder lambdaCodeSigningConfig(LambdaCodeSigningConfigService v) {
|
||||
this.lambdaCodeSigningConfigService = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder appSync(AppSyncService v) {
|
||||
this.appSyncService = v;
|
||||
return this;
|
||||
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaService;
|
||||
import io.github.hectorvent.floci.testing.CfnStackWaits;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.CfnRequests.cfn;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.matchesPattern;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* {@code AWS::Signer::SigningProfile} and {@code AWS::Lambda::CodeSigningConfig} through CloudFormation,
|
||||
* and a function that attaches the config, drops it and attaches it again, with the identifiers AWS returns.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationLambdaCodeSigningIntegrationTest {
|
||||
|
||||
private static final String MISSING_CSC_ARN =
|
||||
"arn:aws:lambda:us-east-1:000000000000:code-signing-config:csc-00000000000000000";
|
||||
|
||||
@Inject
|
||||
LambdaService lambdaService;
|
||||
|
||||
@Test
|
||||
void signingProfileAndCodeSigningConfigAreProvisionedAttachedDetachedAndReattached() {
|
||||
String stackName = "cfn-lambda-csc-" + Long.toString(System.nanoTime(), 36);
|
||||
String signed = template("\"CodeSigningConfigArn\": {\"Ref\": \"Csc\"}");
|
||||
|
||||
cfn("CreateStack", stackName).formParam("TemplateBody", signed).when().post("/").then().statusCode(200);
|
||||
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
|
||||
XmlPath stack = describe(stackName);
|
||||
String profileArn = output(stack, "ProfileArn");
|
||||
String version = output(stack, "ProfileVersion");
|
||||
String cscArn = output(stack, "CscArn");
|
||||
String function = output(stack, "Name");
|
||||
|
||||
assertEquals(profileArn, output(stack, "ProfileRef"));
|
||||
assertThat(output(stack, "ProfileName"), matchesPattern("Profile_[A-Za-z0-9]{12}"));
|
||||
assertEquals("arn:aws:signer:us-east-1:000000000000:/signing-profiles/" + output(stack, "ProfileName"),
|
||||
profileArn);
|
||||
assertThat(version, matchesPattern("[A-Za-z0-9]{10}"));
|
||||
assertEquals(profileArn + "/" + version, output(stack, "ProfileVersionArn"));
|
||||
assertEquals(cscArn, output(stack, "CscRef"));
|
||||
assertEquals(cscArn, "arn:aws:lambda:us-east-1:000000000000:code-signing-config:" + output(stack, "CscId"));
|
||||
given()
|
||||
.when()
|
||||
.get("/2020-04-22/code-signing-configs/" + cscArn)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CodeSigningConfig.Description", equalTo("signed"))
|
||||
.body("CodeSigningConfig.AllowedPublishers.SigningProfileVersionArns",
|
||||
contains(profileArn + "/" + version))
|
||||
.body("CodeSigningConfig.CodeSigningPolicies.UntrustedArtifactOnDeployment", equalTo("Enforce"));
|
||||
assertCodeSigningConfig(function, cscArn);
|
||||
|
||||
for (String rejected : List.of(MISSING_CSC_ARN, cscArn.replace(":000000000000:", ":111111111111:"))) {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> lambdaService.attachFunctionCodeSigningConfig("us-east-1", function, rejected));
|
||||
assertEquals("CodeSigningConfigNotFoundException", error.getErrorCode());
|
||||
}
|
||||
assertCodeSigningConfig(function, cscArn);
|
||||
|
||||
cfn("UpdateStack", stackName).formParam("TemplateBody", template("\"Description\": \"unsigned\""))
|
||||
.when().post("/").then().statusCode(200);
|
||||
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
|
||||
assertEquals(function, output(describe(stackName), "Name"), "dropping the config updates the function in place");
|
||||
assertCodeSigningConfig(function, "");
|
||||
|
||||
cfn("UpdateStack", stackName).formParam("TemplateBody", signed).when().post("/").then().statusCode(200);
|
||||
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
|
||||
assertEquals(function, output(describe(stackName), "Name"), "adding the config updates the function in place");
|
||||
assertCodeSigningConfig(function, cscArn);
|
||||
|
||||
CfnStackWaits.deleteStack(stackName);
|
||||
CfnStackWaits.awaitStackDeleted(stackName);
|
||||
given()
|
||||
.when()
|
||||
.get("/2020-04-22/code-signing-configs/" + cscArn)
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
private static String template(String functionProperty) {
|
||||
return """
|
||||
{
|
||||
"Resources": {
|
||||
"Profile": {
|
||||
"Type": "AWS::Signer::SigningProfile",
|
||||
"Properties": {"PlatformId": "AWSLambda-SHA384-ECDSA"}
|
||||
},
|
||||
"Csc": {
|
||||
"Type": "AWS::Lambda::CodeSigningConfig",
|
||||
"Properties": {
|
||||
"Description": "signed",
|
||||
"AllowedPublishers": {
|
||||
"SigningProfileVersionArns": [{"Fn::GetAtt": ["Profile", "ProfileVersionArn"]}]
|
||||
},
|
||||
"CodeSigningPolicies": {"UntrustedArtifactOnDeployment": "Enforce"}
|
||||
}
|
||||
},
|
||||
"Fn": {
|
||||
"Type": "AWS::Lambda::Function",
|
||||
"Properties": {
|
||||
"Runtime": "python3.14",
|
||||
"Handler": "index.handler",
|
||||
"Role": "arn:aws:iam::000000000000:role/lambda-role",
|
||||
"Code": {"ZipFile": "def handler(e, c): return 'ok'"},
|
||||
%s
|
||||
}
|
||||
}
|
||||
},
|
||||
"Outputs": {
|
||||
"ProfileRef": {"Value": {"Ref": "Profile"}},
|
||||
"ProfileArn": {"Value": {"Fn::GetAtt": ["Profile", "Arn"]}},
|
||||
"ProfileName": {"Value": {"Fn::GetAtt": ["Profile", "ProfileName"]}},
|
||||
"ProfileVersion": {"Value": {"Fn::GetAtt": ["Profile", "ProfileVersion"]}},
|
||||
"ProfileVersionArn": {"Value": {"Fn::GetAtt": ["Profile", "ProfileVersionArn"]}},
|
||||
"CscRef": {"Value": {"Ref": "Csc"}},
|
||||
"CscArn": {"Value": {"Fn::GetAtt": ["Csc", "CodeSigningConfigArn"]}},
|
||||
"CscId": {"Value": {"Fn::GetAtt": ["Csc", "CodeSigningConfigId"]}},
|
||||
"Name": {"Value": {"Ref": "Fn"}}
|
||||
}
|
||||
}
|
||||
""".formatted(functionProperty);
|
||||
}
|
||||
|
||||
private static void assertCodeSigningConfig(String function, String expected) {
|
||||
given()
|
||||
.when()
|
||||
.get("/2020-06-30/functions/" + function + "/code-signing-config")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CodeSigningConfigArn", equalTo(expected));
|
||||
}
|
||||
|
||||
private static XmlPath describe(String stackName) {
|
||||
return cfn("DescribeStacks", stackName).when().post("/").then().statusCode(200).extract().xmlPath();
|
||||
}
|
||||
|
||||
private static String output(XmlPath stack, String key) {
|
||||
return stack.getString("DescribeStacksResponse.DescribeStacksResult.Stacks.member"
|
||||
+ ".Outputs.member.find { it.OutputKey == '" + key + "' }.OutputValue");
|
||||
}
|
||||
}
|
||||
+67
-1
@@ -42,6 +42,8 @@ class LambdaCfnProvisionerTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String FUNCTION_ARN = "arn:aws:lambda:us-east-1:000000000000:function:";
|
||||
private static final String TEMPLATE_TAG_KEYS_ATTR = "FlociLambdaTemplateTagKeys";
|
||||
private static final String CSC_ARN =
|
||||
"arn:aws:lambda:us-east-1:000000000000:code-signing-config:csc-0123456789abcdef0";
|
||||
|
||||
private final LambdaService lambda = mock(LambdaService.class);
|
||||
private final LambdaCfnProvisioner provisioner = new LambdaCfnProvisioner(
|
||||
@@ -103,12 +105,13 @@ class LambdaCfnProvisionerTest {
|
||||
return fn;
|
||||
}
|
||||
|
||||
private void stubInPlaceUpdate(String name, Map<String, String> currentTags) {
|
||||
private LambdaFunction stubInPlaceUpdate(String name, Map<String, String> currentTags) {
|
||||
LambdaFunction existing = lambdaFunction(name);
|
||||
when(lambda.getFunction(REGION, name)).thenReturn(existing);
|
||||
when(lambda.updateFunctionConfiguration(anyString(), anyString(), anyMap())).thenReturn(existing);
|
||||
when(lambda.updateFunctionCode(anyString(), anyString(), anyMap())).thenReturn(existing);
|
||||
when(lambda.listTags(FUNCTION_ARN + name)).thenReturn(new HashMap<>(currentTags));
|
||||
return existing;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -275,6 +278,69 @@ class LambdaCfnProvisionerTest {
|
||||
verify(lambda, times(1)).getFunction(REGION, "my-fn");
|
||||
}
|
||||
|
||||
@Test
|
||||
void codeSigningConfigFromTheTemplateReachesCreateFunction() {
|
||||
LambdaFunction created = lambdaFunction("my-fn");
|
||||
created.setCodeSigningConfigArn(CSC_ARN);
|
||||
when(lambda.createFunction(eq(REGION), anyMap())).thenReturn(created);
|
||||
|
||||
provisioner.provision(function(null), props("my-fn").put("CodeSigningConfigArn", CSC_ARN), ctx());
|
||||
|
||||
assertEquals(CSC_ARN, capturedCreateRequest().get("CodeSigningConfigArn"));
|
||||
verify(lambda, never()).attachFunctionCodeSigningConfig(anyString(), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void inPlaceUpdateAttachesANewCodeSigningConfig() {
|
||||
stubInPlaceUpdate("my-fn", Map.of());
|
||||
|
||||
provisioner.provision(function("my-fn"), props("my-fn").put("CodeSigningConfigArn", CSC_ARN),
|
||||
updateCtx("my-fn"));
|
||||
|
||||
verify(lambda).attachFunctionCodeSigningConfig(REGION, "my-fn", CSC_ARN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void inPlaceUpdateWithTheSameCodeSigningConfigLeavesItAttached() {
|
||||
stubInPlaceUpdate("my-fn", Map.of()).setCodeSigningConfigArn(CSC_ARN);
|
||||
|
||||
provisioner.provision(function("my-fn"), props("my-fn").put("CodeSigningConfigArn", CSC_ARN),
|
||||
updateCtx("my-fn"));
|
||||
|
||||
verify(lambda, never()).attachFunctionCodeSigningConfig(anyString(), anyString(), anyString());
|
||||
verify(lambda, never()).deleteFunctionCodeSigningConfig(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void blankCodeSigningConfigArnIsLeftForLambdaToReject() {
|
||||
when(lambda.createFunction(eq(REGION), anyMap())).thenReturn(lambdaFunction("my-fn"));
|
||||
|
||||
provisioner.provision(function(null), props("my-fn").put("CodeSigningConfigArn", " "), ctx());
|
||||
|
||||
assertEquals(" ", capturedCreateRequest().get("CodeSigningConfigArn"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void inPlaceUpdateWithTheCodeSigningConfigGoneDetachesIt() {
|
||||
stubInPlaceUpdate("my-fn", Map.of()).setCodeSigningConfigArn(CSC_ARN);
|
||||
ProvisionContext update = updateCtx("my-fn");
|
||||
|
||||
provisioner.provision(function("my-fn"), props("my-fn"), new ProvisionContext(update.engine(), REGION,
|
||||
update.accountId(), update.stackName(), "my-fn", event -> {},
|
||||
props("my-fn").put("CodeSigningConfigArn", CSC_ARN)));
|
||||
|
||||
verify(lambda).deleteFunctionCodeSigningConfig(REGION, "my-fn");
|
||||
}
|
||||
|
||||
@Test
|
||||
void inPlaceUpdateKeepsACodeSigningConfigTheStackNeverDeclared() {
|
||||
stubInPlaceUpdate("my-fn", Map.of()).setCodeSigningConfigArn(CSC_ARN);
|
||||
|
||||
provisioner.provision(function("my-fn"), props("my-fn"), updateCtx("my-fn"));
|
||||
|
||||
verify(lambda, never()).deleteFunctionCodeSigningConfig(anyString(), anyString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> capturedCreateRequest() {
|
||||
ArgumentCaptor<Map<String, Object>> request = ArgumentCaptor.forClass(Map.class);
|
||||
|
||||
+284
@@ -0,0 +1,284 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation.provisioners;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
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.services.cloudformation.CloudFormationTemplateEngine;
|
||||
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaCodeSigningConfigService;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaService;
|
||||
import io.github.hectorvent.floci.services.lambda.model.CodeSigningConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
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.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class LambdaCodeSigningConfigCfnProvisionerTest {
|
||||
|
||||
private static final String REGION = "eu-west-1";
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
private static final String CSC_ARN = "arn:aws:lambda:eu-west-1:000000000000:code-signing-config:csc-0123456789abcdef0";
|
||||
private static final String PROFILE_VERSION_ARN =
|
||||
"arn:aws:signer:eu-west-1:000000000000:/signing-profiles/my_profile/AbCdEfGhIj";
|
||||
|
||||
private final LambdaCodeSigningConfigService configs = mock(LambdaCodeSigningConfigService.class);
|
||||
private final LambdaService lambda = mock(LambdaService.class);
|
||||
private final LambdaCodeSigningConfigCfnProvisioner provisioner =
|
||||
new LambdaCodeSigningConfigCfnProvisioner(configs, lambda);
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
LambdaCodeSigningConfigCfnProvisionerTest() {
|
||||
when(configs.withConfigLock(anyString(), any())).thenAnswer(inv -> ((Supplier<?>) inv.getArgument(1)).get());
|
||||
}
|
||||
|
||||
private ProvisionContext ctx(String priorPhysicalId) {
|
||||
CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class);
|
||||
when(engine.resolve(any())).thenAnswer(inv -> {
|
||||
JsonNode node = inv.getArgument(0);
|
||||
return node == null || node.isMissingNode() ? null : node.asText();
|
||||
});
|
||||
when(engine.resolveNode(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||
when(engine.resolveStringList(any())).thenAnswer(inv -> {
|
||||
List<String> values = new ArrayList<>();
|
||||
((JsonNode) inv.getArgument(0)).forEach(node -> values.add(node.asText()));
|
||||
return values;
|
||||
});
|
||||
return new ProvisionContext(engine, REGION, ACCOUNT, "my-stack", priorPhysicalId);
|
||||
}
|
||||
|
||||
private static StackResource config() {
|
||||
StackResource r = new StackResource();
|
||||
r.setLogicalId("Csc");
|
||||
r.setResourceType("AWS::Lambda::CodeSigningConfig");
|
||||
r.setAttributes(new HashMap<>());
|
||||
return r;
|
||||
}
|
||||
|
||||
private ObjectNode props() {
|
||||
ObjectNode props = mapper.createObjectNode();
|
||||
props.putObject("AllowedPublishers").putArray("SigningProfileVersionArns").add(PROFILE_VERSION_ARN);
|
||||
return props;
|
||||
}
|
||||
|
||||
private static CodeSigningConfig stored() {
|
||||
CodeSigningConfig config = new CodeSigningConfig();
|
||||
config.setCodeSigningConfigArn(CSC_ARN);
|
||||
config.setCodeSigningConfigId("csc-0123456789abcdef0");
|
||||
return config;
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRefsTheArnAndExposesBothAttributes() {
|
||||
when(configs.create(eq(REGION), eq(ACCOUNT), any(), any(), any())).thenReturn(stored());
|
||||
StackResource r = config();
|
||||
|
||||
provisioner.provision(r, props(), ctx(null));
|
||||
|
||||
assertEquals(CSC_ARN, r.getPhysicalId());
|
||||
assertEquals(CSC_ARN, r.getAttributes().get("CodeSigningConfigArn"));
|
||||
assertEquals("csc-0123456789abcdef0", r.getAttributes().get("CodeSigningConfigId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createPassesThePublishersAndTheDefaults() {
|
||||
when(configs.create(eq(REGION), eq(ACCOUNT), any(), any(), any())).thenReturn(stored());
|
||||
ArgumentCaptor<CodeSigningConfig.AllowedPublishers> publishers =
|
||||
ArgumentCaptor.forClass(CodeSigningConfig.AllowedPublishers.class);
|
||||
ArgumentCaptor<CodeSigningConfig.CodeSigningPolicies> policies =
|
||||
ArgumentCaptor.forClass(CodeSigningConfig.CodeSigningPolicies.class);
|
||||
|
||||
provisioner.provision(config(), props(), ctx(null));
|
||||
|
||||
verify(configs).create(eq(REGION), eq(ACCOUNT), eq(""), publishers.capture(), policies.capture());
|
||||
assertEquals(List.of(PROFILE_VERSION_ARN), publishers.getValue().getSigningProfileVersionArns());
|
||||
assertEquals("Warn", policies.getValue().getUntrustedArtifactOnDeployment());
|
||||
}
|
||||
|
||||
@Test
|
||||
void absentPropertiesLeaveTheMissingPublishersForLambdaToReject() {
|
||||
when(configs.create(eq(REGION), eq(ACCOUNT), any(), any(), any())).thenReturn(stored());
|
||||
ArgumentCaptor<CodeSigningConfig.AllowedPublishers> publishers =
|
||||
ArgumentCaptor.forClass(CodeSigningConfig.AllowedPublishers.class);
|
||||
|
||||
provisioner.provision(config(), null, ctx(null));
|
||||
|
||||
verify(configs).create(eq(REGION), eq(ACCOUNT), eq(""), publishers.capture(), any());
|
||||
assertEquals(List.of(), publishers.getValue().getSigningProfileVersionArns());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAppliesTheTemplateInPlace() {
|
||||
when(configs.get(REGION, CSC_ARN)).thenReturn(stored());
|
||||
when(configs.update(eq(REGION), eq(CSC_ARN), any(), any(), any())).thenReturn(stored());
|
||||
ObjectNode props = props().put("Description", "signed");
|
||||
props.putObject("CodeSigningPolicies").put("UntrustedArtifactOnDeployment", "Enforce");
|
||||
ArgumentCaptor<CodeSigningConfig.CodeSigningPolicies> policies =
|
||||
ArgumentCaptor.forClass(CodeSigningConfig.CodeSigningPolicies.class);
|
||||
StackResource r = config();
|
||||
r.setPhysicalId(CSC_ARN);
|
||||
|
||||
provisioner.provision(r, props, ctx(CSC_ARN));
|
||||
|
||||
verify(configs).withConfigLock(eq(CSC_ARN), any());
|
||||
verify(configs).update(eq(REGION), eq(CSC_ARN), eq("signed"), any(), policies.capture());
|
||||
verify(configs, never()).create(any(), any(), any(), any(), any());
|
||||
assertEquals("Enforce", policies.getValue().getUntrustedArtifactOnDeployment());
|
||||
assertEquals(CSC_ARN, r.getPhysicalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rollbackRestoresWhatTheUpdateChanged() {
|
||||
CodeSigningConfig before = stored();
|
||||
before.setDescription("before");
|
||||
CodeSigningConfig.AllowedPublishers publishers = new CodeSigningConfig.AllowedPublishers();
|
||||
publishers.setSigningProfileVersionArns(List.of(PROFILE_VERSION_ARN));
|
||||
before.setAllowedPublishers(publishers);
|
||||
CodeSigningConfig.CodeSigningPolicies policies = new CodeSigningConfig.CodeSigningPolicies();
|
||||
policies.setUntrustedArtifactOnDeployment("Warn");
|
||||
before.setCodeSigningPolicies(policies);
|
||||
when(configs.get(REGION, CSC_ARN)).thenReturn(before);
|
||||
when(configs.update(eq(REGION), eq(CSC_ARN), any(), any(), any())).thenReturn(stored());
|
||||
StackResource r = config();
|
||||
r.setPhysicalId(CSC_ARN);
|
||||
provisioner.provision(r, props().put("Description", "signed"), ctx(CSC_ARN));
|
||||
ArgumentCaptor<CodeSigningConfig.AllowedPublishers> restoredPublishers =
|
||||
ArgumentCaptor.forClass(CodeSigningConfig.AllowedPublishers.class);
|
||||
ArgumentCaptor<CodeSigningConfig.CodeSigningPolicies> restoredPolicies =
|
||||
ArgumentCaptor.forClass(CodeSigningConfig.CodeSigningPolicies.class);
|
||||
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
|
||||
verify(configs).update(eq(REGION), eq(CSC_ARN), eq("before"), restoredPublishers.capture(),
|
||||
restoredPolicies.capture());
|
||||
assertEquals(List.of(PROFILE_VERSION_ARN), restoredPublishers.getValue().getSigningProfileVersionArns());
|
||||
assertEquals("Warn", restoredPolicies.getValue().getUntrustedArtifactOnDeployment());
|
||||
assertEquals(CSC_ARN, r.getPhysicalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rollbackOfAStubMigrationDeletesTheCreatedConfig() {
|
||||
when(configs.create(eq(REGION), eq(ACCOUNT), any(), any(), any())).thenReturn(stored());
|
||||
StackResource r = config();
|
||||
r.setPhysicalId("Csc-0a1b2c3d");
|
||||
r.getAttributes().put("Arn", "arn:aws:stub:::Csc");
|
||||
provisioner.provision(r, props(), ctx("Csc-0a1b2c3d"));
|
||||
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
|
||||
verify(lambda).deleteCodeSigningConfig(REGION, ACCOUNT, CSC_ARN);
|
||||
assertEquals("Csc-0a1b2c3d", r.getPhysicalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void configARollbackCouldNotDeleteIsDeletedByTheNextCleanup() {
|
||||
when(configs.create(eq(REGION), eq(ACCOUNT), any(), any(), any())).thenReturn(stored());
|
||||
doThrow(new AwsException("ResourceConflictException", "attached", 409)).doNothing()
|
||||
.when(lambda).deleteCodeSigningConfig(REGION, ACCOUNT, CSC_ARN);
|
||||
StackResource r = config();
|
||||
r.setPhysicalId("Csc-0a1b2c3d");
|
||||
r.getAttributes().put("Arn", "arn:aws:stub:::Csc");
|
||||
provisioner.provision(r, props(), ctx("Csc-0a1b2c3d"));
|
||||
assertThrows(AwsException.class, () -> provisioner.rollbackUpdate(r));
|
||||
|
||||
assertTrue(provisioner.hasReplacementUpdate(r));
|
||||
assertEquals(CSC_ARN, provisioner.updateCleanupPhysicalId(r));
|
||||
assertTrue(provisioner.completeUpdate(r).complete());
|
||||
verify(lambda, times(2)).deleteCodeSigningConfig(REGION, ACCOUNT, CSC_ARN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whitespaceDescriptionIsKept() {
|
||||
when(configs.create(eq(REGION), eq(ACCOUNT), any(), any(), any())).thenReturn(stored());
|
||||
|
||||
provisioner.provision(config(), props().put("Description", " "), ctx(null));
|
||||
|
||||
verify(configs).create(eq(REGION), eq(ACCOUNT), eq(" "), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void blankPolicyIsLeftForLambdaToReject() {
|
||||
when(configs.create(eq(REGION), eq(ACCOUNT), any(), any(), any())).thenReturn(stored());
|
||||
ObjectNode props = props();
|
||||
props.putObject("CodeSigningPolicies").put("UntrustedArtifactOnDeployment", " ");
|
||||
ArgumentCaptor<CodeSigningConfig.CodeSigningPolicies> policies =
|
||||
ArgumentCaptor.forClass(CodeSigningConfig.CodeSigningPolicies.class);
|
||||
|
||||
provisioner.provision(config(), props, ctx(null));
|
||||
|
||||
verify(configs).create(eq(REGION), eq(ACCOUNT), eq(""), any(), policies.capture());
|
||||
assertEquals(" ", policies.getValue().getUntrustedArtifactOnDeployment());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateOfAStubFromBeforeThisProvisionerCreatesTheConfig() {
|
||||
when(configs.create(eq(REGION), eq(ACCOUNT), any(), any(), any())).thenReturn(stored());
|
||||
StackResource r = config();
|
||||
r.setPhysicalId("Csc-0a1b2c3d");
|
||||
|
||||
provisioner.provision(r, props(), ctx("Csc-0a1b2c3d"));
|
||||
|
||||
verify(configs, never()).update(any(), any(), any(), any(), any());
|
||||
assertEquals(CSC_ARN, r.getPhysicalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteOfAStubTouchesNothing() {
|
||||
provisioner.delete("AWS::Lambda::CodeSigningConfig", "Csc-0a1b2c3d", REGION);
|
||||
|
||||
verify(lambda, never()).deleteCodeSigningConfig(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRemovesTheConfigThroughLambda() {
|
||||
provisioner.delete("AWS::Lambda::CodeSigningConfig", CSC_ARN, REGION);
|
||||
|
||||
verify(lambda).deleteCodeSigningConfig(REGION, ACCOUNT, CSC_ARN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteToleratesAConfigAlreadyGone() {
|
||||
doThrow(new AwsException("ResourceNotFoundException", "gone", 404))
|
||||
.when(lambda).deleteCodeSigningConfig(REGION, ACCOUNT, CSC_ARN);
|
||||
|
||||
provisioner.delete("AWS::Lambda::CodeSigningConfig", CSC_ARN, REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteLooksTheConfigUpInTheArnsOwnAccount() {
|
||||
String foreign = "arn:aws:lambda:eu-west-1:111111111111:code-signing-config:csc-0123456789abcdef0";
|
||||
doThrow(new AwsException("ResourceNotFoundException", "not found", 404))
|
||||
.when(lambda).deleteCodeSigningConfig(REGION, "111111111111", foreign);
|
||||
|
||||
provisioner.delete("AWS::Lambda::CodeSigningConfig", foreign, REGION);
|
||||
|
||||
verify(lambda).deleteCodeSigningConfig(REGION, "111111111111", foreign);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRefusesAConfigStillAttachedToAFunction() {
|
||||
doThrow(new AwsException("ResourceConflictException", "attached", 409))
|
||||
.when(lambda).deleteCodeSigningConfig(REGION, ACCOUNT, CSC_ARN);
|
||||
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> provisioner.delete("AWS::Lambda::CodeSigningConfig", CSC_ARN, REGION));
|
||||
|
||||
assertEquals("ResourceConflictException", e.getErrorCode());
|
||||
}
|
||||
}
|
||||
+290
@@ -0,0 +1,290 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation.provisioners;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.BooleanNode;
|
||||
import com.fasterxml.jackson.databind.node.DoubleNode;
|
||||
import com.fasterxml.jackson.databind.node.LongNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
|
||||
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
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.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class SignerCfnProvisionerTest {
|
||||
|
||||
private static final String PROFILE_ARN_PREFIX = "arn:aws:signer:eu-west-1:000000000000:/signing-profiles/";
|
||||
|
||||
private final SignerCfnProvisioner provisioner = new SignerCfnProvisioner();
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
private ProvisionContext ctx(String priorPhysicalId) {
|
||||
CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class);
|
||||
when(engine.resolve(any())).thenAnswer(inv -> {
|
||||
JsonNode node = inv.getArgument(0);
|
||||
return node == null || node.isMissingNode() ? null : node.asText();
|
||||
});
|
||||
when(engine.resolveNodeOmittingNoValue(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||
return new ProvisionContext(engine, "eu-west-1", "000000000000", "my-stack", priorPhysicalId);
|
||||
}
|
||||
|
||||
private static StackResource profile() {
|
||||
StackResource r = new StackResource();
|
||||
r.setLogicalId("Profile");
|
||||
r.setResourceType("AWS::Signer::SigningProfile");
|
||||
r.setAttributes(new HashMap<>());
|
||||
return r;
|
||||
}
|
||||
|
||||
private ObjectNode props(String profileName) {
|
||||
ObjectNode props = mapper.createObjectNode().put("PlatformId", "AWSLambda-SHA384-ECDSA");
|
||||
if (profileName != null) {
|
||||
props.put("ProfileName", profileName);
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
@Test
|
||||
void namedProfileRefsItsArnAndExposesEveryAttribute() {
|
||||
StackResource r = profile();
|
||||
|
||||
provisioner.provision(r, props("my_profile"), ctx(null));
|
||||
|
||||
String arn = PROFILE_ARN_PREFIX + "my_profile";
|
||||
String version = r.getAttributes().get("ProfileVersion");
|
||||
assertEquals(arn, r.getPhysicalId());
|
||||
assertEquals(arn, r.getAttributes().get("Arn"));
|
||||
assertEquals("my_profile", r.getAttributes().get("ProfileName"));
|
||||
assertTrue(version.matches("[A-Za-z0-9]{10}"), version);
|
||||
assertEquals(arn + "/" + version, r.getAttributes().get("ProfileVersionArn"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unnamedProfileGetsTheLogicalIdAndARandomSuffix() {
|
||||
StackResource r = profile();
|
||||
|
||||
provisioner.provision(r, props(null), ctx(null));
|
||||
|
||||
String name = r.getAttributes().get("ProfileName");
|
||||
assertTrue(name.matches("Profile_[A-Za-z0-9]{12}"), name);
|
||||
assertEquals(PROFILE_ARN_PREFIX + name, r.getPhysicalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void generatedNameStaysWithinTheProfileNameLimit() {
|
||||
StackResource r = profile();
|
||||
r.setLogicalId("L".repeat(80));
|
||||
|
||||
provisioner.provision(r, props(null), ctx(null));
|
||||
|
||||
String name = r.getAttributes().get("ProfileName");
|
||||
assertEquals(64, name.length());
|
||||
assertTrue(name.matches("L{51}_[A-Za-z0-9]{12}"), name);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWithTheSameCreateOnlyPropertiesKeepsTheProfile() {
|
||||
StackResource r = profile();
|
||||
provisioner.provision(r, props(null), ctx(null));
|
||||
Map<String, String> created = new HashMap<>(r.getAttributes());
|
||||
String physicalId = r.getPhysicalId();
|
||||
|
||||
ObjectNode tagged = props(null);
|
||||
tagged.putArray("Tags").addObject().put("Key", "team").put("Value", "a");
|
||||
provisioner.provision(r, tagged, ctx(physicalId));
|
||||
|
||||
assertEquals(physicalId, r.getPhysicalId());
|
||||
assertEquals(created, r.getAttributes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void changedPlatformReplacesAnUnnamedProfile() {
|
||||
StackResource r = profile();
|
||||
provisioner.provision(r, props(null), ctx(null));
|
||||
String physicalId = r.getPhysicalId();
|
||||
|
||||
provisioner.provision(r, props(null).put("PlatformId", "Notation-OCI-SHA384-ECDSA"), ctx(physicalId));
|
||||
|
||||
assertNotEquals(physicalId, r.getPhysicalId());
|
||||
assertTrue(r.getAttributes().get("ProfileName").matches("Profile_[A-Za-z0-9]{12}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void changedValidityPeriodReplacesAnUnnamedProfile() {
|
||||
StackResource r = profile();
|
||||
provisioner.provision(r, props(null), ctx(null));
|
||||
String physicalId = r.getPhysicalId();
|
||||
|
||||
ObjectNode changed = props(null);
|
||||
changed.putObject("SignatureValidityPeriod").put("Type", "DAYS").put("Value", 30);
|
||||
provisioner.provision(r, changed, ctx(physicalId));
|
||||
|
||||
assertNotEquals(physicalId, r.getPhysicalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void reorderedValidityPeriodKeysKeepTheProfile() {
|
||||
StackResource r = profile();
|
||||
ObjectNode created = props(null);
|
||||
created.putObject("SignatureValidityPeriod").put("Type", "DAYS").put("Value", 30);
|
||||
provisioner.provision(r, created, ctx(null));
|
||||
String physicalId = r.getPhysicalId();
|
||||
|
||||
ObjectNode reordered = props(null);
|
||||
reordered.putObject("SignatureValidityPeriod").put("Value", 30).put("Type", "DAYS");
|
||||
reordered.putArray("Tags").addObject().put("Key", "team").put("Value", "a");
|
||||
provisioner.provision(r, reordered, ctx(physicalId));
|
||||
|
||||
assertEquals(physicalId, r.getPhysicalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rollbackOfAReplacementRestoresThePriorProfile() {
|
||||
StackResource r = profile();
|
||||
provisioner.provision(r, props(null), ctx(null));
|
||||
Map<String, String> created = new HashMap<>(r.getAttributes());
|
||||
String physicalId = r.getPhysicalId();
|
||||
provisioner.provision(r, props(null).put("PlatformId", "Notation-OCI-SHA384-ECDSA"), ctx(physicalId));
|
||||
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
|
||||
assertEquals(physicalId, r.getPhysicalId());
|
||||
assertEquals(created, r.getAttributes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rollbackOfAnInPlaceUpdateKeepsTheProfile() {
|
||||
StackResource r = profile();
|
||||
provisioner.provision(r, props(null), ctx(null));
|
||||
String physicalId = r.getPhysicalId();
|
||||
ObjectNode tagged = props(null);
|
||||
tagged.putArray("Tags").addObject().put("Key", "team").put("Value", "a");
|
||||
provisioner.provision(r, tagged, ctx(physicalId));
|
||||
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
|
||||
assertEquals(physicalId, r.getPhysicalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void committedReplacementCleansUpTheDisplacedProfile() {
|
||||
StackResource r = profile();
|
||||
provisioner.provision(r, props(null), ctx(null));
|
||||
String physicalId = r.getPhysicalId();
|
||||
provisioner.provision(r, props(null).put("PlatformId", "Notation-OCI-SHA384-ECDSA"), ctx(physicalId));
|
||||
|
||||
assertTrue(provisioner.hasReplacementUpdate(r));
|
||||
assertEquals(physicalId, provisioner.updateCleanupPhysicalId(r));
|
||||
assertTrue(provisioner.completeUpdate(r).complete());
|
||||
provisioner.clearUpdate(r);
|
||||
|
||||
assertFalse(provisioner.hasReplacementUpdate(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
void replacingACustomNamedProfileIsRefused() {
|
||||
StackResource r = profile();
|
||||
provisioner.provision(r, props("my_profile"), ctx(null));
|
||||
ObjectNode changed = props("my_profile").put("PlatformId", "Notation-OCI-SHA384-ECDSA");
|
||||
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> provisioner.provision(r, changed, ctx(r.getPhysicalId())));
|
||||
|
||||
assertEquals("ValidationError", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingPlatformIdIsRejected() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> provisioner.provision(profile(), mapper.createObjectNode(), ctx(null)));
|
||||
|
||||
assertEquals("ValidationError", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownPlatformIdIsRejected() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> provisioner.provision(profile(), props(null).put("PlatformId", "AWSIoT"), ctx(null)));
|
||||
|
||||
assertEquals("ValidationError", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void validityPeriodWithoutAKnownTypeAndAValueIsRejectedAsSignerRejectsIt() throws Exception {
|
||||
String noType = "Signature validity period type must be one of [DAYS, MONTHS, YEARS]";
|
||||
Map<String, String> cases = Map.of(
|
||||
"{\"Type\": \"WEEKS\", \"Value\": 30}", noType,
|
||||
"{}", noType,
|
||||
"{\"Value\": 999999}", noType,
|
||||
"{\"Type\": \"DAYS\"}", "Signature validity period value must be greater than 0.");
|
||||
for (Map.Entry<String, String> period : cases.entrySet()) {
|
||||
ObjectNode props = props(null);
|
||||
props.set("SignatureValidityPeriod", mapper.readTree(period.getKey()));
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> provisioner.provision(profile(), props, ctx(null)),
|
||||
period.getKey());
|
||||
|
||||
assertEquals("ValidationError", e.getErrorCode(), period.getKey());
|
||||
assertEquals(period.getValue(), e.getMessage(), period.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void validityPeriodOutsideTheSignerLimitsIsRejected() {
|
||||
for (String period : List.of("DAYS:0", "DAYS:4106", "MONTHS:136", "YEARS:12")) {
|
||||
ObjectNode props = props(null);
|
||||
props.putObject("SignatureValidityPeriod").put("Type", period.split(":")[0])
|
||||
.put("Value", Integer.parseInt(period.split(":")[1]));
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> provisioner.provision(profile(), props, ctx(null)),
|
||||
period);
|
||||
|
||||
assertEquals("ValidationError", e.getErrorCode(), period);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void validityPeriodValueThatIsNotAnIntegerIsRejected() {
|
||||
for (JsonNode value : List.<JsonNode>of(DoubleNode.valueOf(11.5), BooleanNode.TRUE,
|
||||
LongNode.valueOf(99_999_999_999L))) {
|
||||
ObjectNode props = props(null);
|
||||
props.putObject("SignatureValidityPeriod").put("Type", "YEARS").set("Value", value);
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> provisioner.provision(profile(), props, ctx(null)),
|
||||
value.toString());
|
||||
|
||||
assertEquals("ValidationError", e.getErrorCode(), value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void validityPeriodAtTheSignerLimitIsAccepted() {
|
||||
ObjectNode props = props(null);
|
||||
props.putObject("SignatureValidityPeriod").put("Type", "YEARS").put("Value", 11);
|
||||
|
||||
provisioner.provision(profile(), props, ctx(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void profileNameOutsideThePatternIsRejected() {
|
||||
for (String name : List.of("thiink-signing-profile", "", " ")) {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> provisioner.provision(profile(), props(name), ctx(null)), "'" + name + "'");
|
||||
|
||||
assertEquals("ValidationError", e.getErrorCode(), "'" + name + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/** Code-signing mutations stay in the account selected by the request context. */
|
||||
class LambdaCodeSigningAccountScopeTest {
|
||||
@@ -84,7 +83,7 @@ class LambdaCodeSigningAccountScopeTest {
|
||||
LambdaService service = new LambdaService(store, new WarmPool(), new CodeStore(codePath),
|
||||
new ZipExtractor(), regions);
|
||||
LambdaCodeSigningController controller = new LambdaCodeSigningController(
|
||||
service, mock(LambdaCodeSigningConfigService.class), regions, new ObjectMapper());
|
||||
service, regions, new ObjectMapper());
|
||||
|
||||
List<String> references = List.of(
|
||||
REGION + ":" + CALLER_ACCOUNT + ":function:" + FUNCTION_NAME,
|
||||
@@ -234,7 +233,7 @@ class LambdaCodeSigningAccountScopeTest {
|
||||
new ZipExtractor(), regions);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
LambdaCodeSigningController controller = new LambdaCodeSigningController(
|
||||
service, mock(LambdaCodeSigningConfigService.class), regions, mapper);
|
||||
service, regions, mapper);
|
||||
String foreignArn = "arn:aws:lambda:" + REGION + ":" + ARN_ACCOUNT
|
||||
+ ":function:" + FUNCTION_NAME;
|
||||
|
||||
|
||||
+5
-3
@@ -63,10 +63,12 @@ class LambdaCodeSigningConfigDeleteRaceTest {
|
||||
function.setFunctionArn("arn:aws:lambda:" + REGION + ":" + ACCOUNT + ":function:" + NAME);
|
||||
function.setVersion("$LATEST");
|
||||
functions.saveForAccount(ACCOUNT, REGION, function);
|
||||
LambdaService lambda = new LambdaService(functions, new WarmPool(), new CodeStore(codePath),
|
||||
new ZipExtractor(), regions);
|
||||
LambdaService lambda = new LambdaService(functions, null, new LambdaConcurrencyLimiter(),
|
||||
new WarmPool(), new CodeStore(codePath), new ZipExtractor(), null, regions, null, null,
|
||||
new LambdaTargetResolver(functions, null), null, null, null, null, null, factory,
|
||||
null, null, null, null, new ObjectMapper(), configs);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
LambdaCodeSigningController attachments = new LambdaCodeSigningController(lambda, configs, regions, mapper);
|
||||
LambdaCodeSigningController attachments = new LambdaCodeSigningController(lambda, regions, mapper);
|
||||
LambdaCodeSigningConfigFunctionsController configController =
|
||||
new LambdaCodeSigningConfigFunctionsController(configs, lambda, regions, mapper);
|
||||
|
||||
|
||||
+4
-2
@@ -53,8 +53,10 @@ class LambdaCodeSigningConfigUpdateDeleteRaceTest {
|
||||
String arn = configs.create(REGION, ACCOUNT, null, publishers, null).getCodeSigningConfigArn();
|
||||
|
||||
LambdaFunctionStore functions = new LambdaFunctionStore(AccountAwareStorageBackend.inMemory(ACCOUNT));
|
||||
LambdaService lambda = new LambdaService(functions, new WarmPool(), new CodeStore(codePath),
|
||||
new ZipExtractor(), regions);
|
||||
LambdaService lambda = new LambdaService(functions, null, new LambdaConcurrencyLimiter(),
|
||||
new WarmPool(), new CodeStore(codePath), new ZipExtractor(), null, regions, null, null,
|
||||
new LambdaTargetResolver(functions, null), null, null, null, null, null, factory,
|
||||
null, null, null, null, new ObjectMapper(), configs);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
LambdaCodeSigningConfigFunctionsController controller =
|
||||
new LambdaCodeSigningConfigFunctionsController(configs, lambda, regions, mapper);
|
||||
|
||||
Reference in new issue
Block a user