Skip to content

Commit ed73ae9

Browse files
authored
Merge pull request #28 from cythral/LAMBJ-37
LAMBJ-37 v0.3.0-beta3 LAMBJ-36 Client Factories RoleArn Fix
2 parents 9f1a8ac + 1600fe8 commit ed73ae9

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

.github/releases/v0.3.0-beta3.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This release introduces the following:
2+
3+
- Fixes an issue where client factories would attempt to do an sts:AssumeRole if no role arn was given.

src/Generator/LambdaGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ MemberDeclarationSyntax GenerateCreateMethod()
373373

374374
IEnumerable<StatementSyntax> GenerateBody()
375375
{
376-
yield return IfStatement(ParseExpression("roleArn == null"),
376+
yield return IfStatement(ParseExpression("roleArn != null"),
377377
Block(
378378
ParseStatement("var request = new AssumeRoleRequest { RoleArn = roleArn, RoleSessionName = \"lambdajection-assume-role\" };"),
379379
ParseStatement("var response = await stsClient.AssumeRoleAsync(request);"),

tests/WithFactories/IntegrationTests.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
using System;
2+
using System.Reflection;
13
using System.Threading.Tasks;
24

35
using Amazon.Lambda.Core;
46
using Amazon.S3;
7+
using Amazon.SecurityToken;
8+
using Amazon.SecurityToken.Model;
59

610
using FluentAssertions;
711

@@ -12,8 +16,9 @@
1216
using Microsoft.Extensions.DependencyInjection;
1317
using Microsoft.Extensions.Logging;
1418

15-
using NUnit.Framework;
19+
using NSubstitute;
1620

21+
using NUnit.Framework;
1722
namespace Lambdajection.Tests
1823
{
1924
[Lambda(Startup = typeof(Startup))]
@@ -86,5 +91,33 @@ public async Task TestExampleLambdaRun()
8691

8792
result.Should().BeEquivalentTo("foo bar");
8893
}
94+
95+
[Test]
96+
public async Task TestFactoriesDoNotPerformAssumeRoleIfNoRoleArnGiven()
97+
{
98+
var client = Substitute.For<IAmazonSecurityTokenService>();
99+
var configuratorType = typeof(ExampleLambda).GetNestedType("LambdajectionConfigurator", BindingFlags.NonPublic)!;
100+
var s3FactoryType = configuratorType.GetNestedType("S3Factory", BindingFlags.NonPublic)!;
101+
var factory = Activator.CreateInstance(s3FactoryType, new object[] { client });
102+
var createMethod = s3FactoryType.GetMethod("Create")!;
103+
createMethod.Invoke(factory, new object[] { null! });
104+
105+
await client.DidNotReceive().AssumeRoleAsync(Arg.Any<AssumeRoleRequest>());
106+
}
107+
108+
[Test]
109+
public async Task TestFactoriesPerformAssumeRoleIfRoleArnGiven()
110+
{
111+
var client = Substitute.For<IAmazonSecurityTokenService>();
112+
var configuratorType = typeof(ExampleLambda).GetNestedType("LambdajectionConfigurator", BindingFlags.NonPublic)!;
113+
var s3FactoryType = configuratorType.GetNestedType("S3Factory", BindingFlags.NonPublic)!;
114+
var factory = Activator.CreateInstance(s3FactoryType, new object[] { client });
115+
var createMethod = s3FactoryType.GetMethod("Create")!;
116+
var roleArn = "rolearn";
117+
118+
createMethod.Invoke(factory, new object[] { roleArn });
119+
120+
await client.Received().AssumeRoleAsync(Arg.Is<AssumeRoleRequest>(req => req.RoleArn == roleArn));
121+
}
89122
}
90123
}

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "0.3.0-beta2",
3+
"version": "0.3.0-beta3",
44
"publicReleaseRefSpec": ["^refs/heads/master$", "^refs/tags/v\\d\\.\\d"]
55
}

0 commit comments

Comments
 (0)