Skip to content

Commit 9a5531f

Browse files
authored
feat: Sign assemblies with a strong name (#815)
1 parent a1e14cb commit 9a5531f

16 files changed

+70
-43
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*.crt filter=lfs diff=lfs merge=lfs -text
1313
*.ico filter=lfs diff=lfs merge=lfs -text
1414
*.png filter=lfs diff=lfs merge=lfs -text
15+
*.snk filter=lfs diff=lfs merge=lfs -text
1516

1617
# Setting up Netlify with Git LFS is cumbersome
1718
docs/*.ico !filter=lfs !diff=lfs !merge=lfs -text

.github/workflows/codeql-analysis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
steps:
2626
- name: Checkout Repository
2727
uses: actions/checkout@v3
28+
with:
29+
lfs: true
2830

2931
- name: Initialize CodeQL
3032
uses: github/codeql-action/init@v2

Directory.Build.props

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project>
33
<PropertyGroup>
4-
<SolutionDir Condition=" '$(SolutionDir)' == '' ">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), Testcontainers.sln))/</SolutionDir>
4+
<SolutionDir Condition=" '$(SolutionDir)' == '' ">$([MSBuild]::GetDirectoryNameOfFileAbove('$(MSBuildProjectDirectory)', 'Testcontainers.sln'))/</SolutionDir>
55
</PropertyGroup>
66
<PropertyGroup>
77
<PackageId>$(AssemblyName)</PackageId>
@@ -23,13 +23,17 @@
2323
<RepositoryType>git</RepositoryType>
2424
<RepositoryUrl>https://github.com/testcontainers/testcontainers-dotnet</RepositoryUrl>
2525
</PropertyGroup>
26+
<PropertyGroup>
27+
<AssemblyOriginatorKeyFile>$(SolutionDir)src/strongname.snk</AssemblyOriginatorKeyFile>
28+
<SignAssembly>true</SignAssembly>
29+
</PropertyGroup>
30+
<PropertyGroup>
31+
<NoWarn>CS0618,CS1591,SA0001,SA1600,SA1633,SA1649</NoWarn>
32+
</PropertyGroup>
2633
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
2734
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2835
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
2936
</PropertyGroup>
30-
<PropertyGroup>
31-
<NoWarn>CA1716,CS1591,SA0001,SA1402,SA1600,SA1633,SA1649,CS0618</NoWarn>
32-
</PropertyGroup>
3337
<ItemGroup>
3438
<None Include="$(SolutionDir)docs/banner.png" Visible="false" Pack="true" PackagePath="docs/" />
3539
<None Include="$(SolutionDir)docs/logo.png" Visible="false" Pack="true" PackagePath="docs/" />
@@ -38,7 +42,7 @@
3842
</ItemGroup>
3943
<ItemGroup>
4044
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
41-
<_Parameter1>Testcontainers.Tests</_Parameter1>
45+
<_Parameter1>Testcontainers.Tests, PublicKey=$([System.IO.File]::ReadAllText($(SolutionDir)src/strongname.pub))</_Parameter1>
4246
</AssemblyAttribute>
4347
</ItemGroup>
4448
</Project>

Packages.props

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
66
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" />
77
<PackageReference Update="JetBrains.Annotations" Version="2022.3.1" PrivateAssets="all" />
8-
<PackageReference Update="Docker.DotNet" Version="3.125.12" />
9-
<PackageReference Update="Docker.DotNet.X509" Version="3.125.12" />
8+
<PackageReference Update="Docker.DotNet" Version="3.125.13" />
9+
<PackageReference Update="Docker.DotNet.X509" Version="3.125.13" />
1010
<PackageReference Update="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
1111
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="6.0.3" />
1212
<PackageReference Update="Portable.BouncyCastle" Version="1.9.0" />

Testcontainers.sln

+14-14
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Redis", "src
5151
EndProject
5252
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Redpanda", "src\Testcontainers.Redpanda\Testcontainers.Redpanda.csproj", "{45D6F69C-4D87-4130-AA90-0DB2F7460DAE}"
5353
EndProject
54+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.SqlEdge", "src\Testcontainers.SqlEdge\Testcontainers.SqlEdge.csproj", "{C95A3B2F-2B28-49A7-8806-731C158BBC21}"
55+
EndProject
5456
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers", "src\Testcontainers\Testcontainers.csproj", "{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733}"
5557
EndProject
5658
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Commons", "tests\Testcontainers.Commons\Testcontainers.Commons.csproj", "{2478673C-B063-469D-ABD1-0C3E0A25541B}"
@@ -99,12 +101,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Redpanda.Tes
99101
EndProject
100102
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.ResourceReaper.Tests", "tests\Testcontainers.ResourceReaper.Tests\Testcontainers.ResourceReaper.Tests.csproj", "{9E8E6AA5-65D1-498F-BEAB-BA34723A0050}"
101103
EndProject
102-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tests\Testcontainers.Tests\Testcontainers.Tests.csproj", "{27CDB869-A150-4593-958F-6F26E5391E7C}"
103-
EndProject
104-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.SqlEdge", "src\Testcontainers.SqlEdge\Testcontainers.SqlEdge.csproj", "{C95A3B2F-2B28-49A7-8806-731C158BBC21}"
105-
EndProject
106104
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.SqlEdge.Tests", "tests\Testcontainers.SqlEdge.Tests\Testcontainers.SqlEdge.Tests.csproj", "{1A1983E6-5297-435F-B467-E8E1F11277D6}"
107105
EndProject
106+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tests\Testcontainers.Tests\Testcontainers.Tests.csproj", "{27CDB869-A150-4593-958F-6F26E5391E7C}"
107+
EndProject
108108
Global
109109
GlobalSection(SolutionConfigurationPlatforms) = preSolution
110110
Debug|Any CPU = Debug|Any CPU
@@ -190,6 +190,10 @@ Global
190190
{45D6F69C-4D87-4130-AA90-0DB2F7460DAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
191191
{45D6F69C-4D87-4130-AA90-0DB2F7460DAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
192192
{45D6F69C-4D87-4130-AA90-0DB2F7460DAE}.Release|Any CPU.Build.0 = Release|Any CPU
193+
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
194+
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Debug|Any CPU.Build.0 = Debug|Any CPU
195+
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Release|Any CPU.ActiveCfg = Release|Any CPU
196+
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Release|Any CPU.Build.0 = Release|Any CPU
193197
{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
194198
{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733}.Debug|Any CPU.Build.0 = Debug|Any CPU
195199
{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -286,18 +290,14 @@ Global
286290
{9E8E6AA5-65D1-498F-BEAB-BA34723A0050}.Debug|Any CPU.Build.0 = Debug|Any CPU
287291
{9E8E6AA5-65D1-498F-BEAB-BA34723A0050}.Release|Any CPU.ActiveCfg = Release|Any CPU
288292
{9E8E6AA5-65D1-498F-BEAB-BA34723A0050}.Release|Any CPU.Build.0 = Release|Any CPU
289-
{27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
290-
{27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
291-
{27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
292-
{27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.Build.0 = Release|Any CPU
293-
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
294-
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Debug|Any CPU.Build.0 = Debug|Any CPU
295-
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Release|Any CPU.ActiveCfg = Release|Any CPU
296-
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Release|Any CPU.Build.0 = Release|Any CPU
297293
{1A1983E6-5297-435F-B467-E8E1F11277D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
298294
{1A1983E6-5297-435F-B467-E8E1F11277D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
299295
{1A1983E6-5297-435F-B467-E8E1F11277D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
300296
{1A1983E6-5297-435F-B467-E8E1F11277D6}.Release|Any CPU.Build.0 = Release|Any CPU
297+
{27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
298+
{27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
299+
{27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
300+
{27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.Build.0 = Release|Any CPU
301301
EndGlobalSection
302302
GlobalSection(NestedProjects) = preSolution
303303
{58E94721-2681-4D82-8D94-0B2F9DB0D575} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
@@ -319,6 +319,7 @@ Global
319319
{F6394475-D6F1-46E2-81BF-4BA78A40B878} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
320320
{BFDA179A-40EB-4CEB-B8E9-0DF32C65E2C5} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
321321
{45D6F69C-4D87-4130-AA90-0DB2F7460DAE} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
322+
{C95A3B2F-2B28-49A7-8806-731C158BBC21} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
322323
{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
323324
{2478673C-B063-469D-ABD1-0C3E0A25541B} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
324325
{809322BA-D690-4F2B-B884-23F895663963} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
@@ -343,8 +344,7 @@ Global
343344
{31EE94A0-E721-4073-B6F1-DD912D004DEF} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
344345
{867BD04E-4670-4FBA-98D5-9F83220E6DFB} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
345346
{9E8E6AA5-65D1-498F-BEAB-BA34723A0050} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
346-
{27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
347-
{C95A3B2F-2B28-49A7-8806-731C158BBC21} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
348347
{1A1983E6-5297-435F-B467-E8E1F11277D6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
348+
{27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
349349
EndGlobalSection
350350
EndGlobal

build.cake

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ Task("Build")
6767
Verbosity = param.Verbosity,
6868
NoRestore = true,
6969
ArgumentCustomization = args => args
70-
.Append($"/p:TreatWarningsAsErrors={param.IsReleaseBuild.ToString()}")
7170
});
7271
});
7372

src/Testcontainers.MongoDb/MongoDbBuilder.cs

+9-17
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ public MongoDbBuilder WithPassword(string password)
6060
public override MongoDbContainer Build()
6161
{
6262
Validate();
63-
64-
var mongoDbBuilder = DockerResourceConfiguration.WaitStrategies.Count() > 1 ? this : WithWaitStrategy(Wait.ForUnixContainer().AddCustomWaitStrategy(new WaitUntil(DockerResourceConfiguration)));
65-
return new MongoDbContainer(mongoDbBuilder.DockerResourceConfiguration, TestcontainersSettings.Logger);
63+
return new MongoDbContainer(DockerResourceConfiguration, TestcontainersSettings.Logger);
6664
}
6765

6866
/// <inheritdoc />
@@ -72,7 +70,8 @@ protected override MongoDbBuilder Init()
7270
.WithImage(MongoDbImage)
7371
.WithPortBinding(MongoDbPort, true)
7472
.WithUsername(DefaultUsername)
75-
.WithPassword(DefaultPassword);
73+
.WithPassword(DefaultPassword)
74+
.WithWaitStrategy(Wait.ForUnixContainer().AddCustomWaitStrategy(new WaitUntil()));
7675
}
7776

7877
/// <inheritdoc />
@@ -110,25 +109,18 @@ protected override MongoDbBuilder Merge(MongoDbConfiguration oldValue, MongoDbCo
110109
/// <inheritdoc cref="IWaitUntil" />
111110
private sealed class WaitUntil : IWaitUntil
112111
{
113-
private readonly IList<string> _mongoDbShellCommand;
114-
115-
/// <summary>
116-
/// Initializes a new instance of the <see cref="WaitUntil" /> class.
117-
/// </summary>
118-
/// <param name="configuration">The container configuration.</param>
119-
public WaitUntil(MongoDbConfiguration configuration)
120-
{
121-
const string js = "db.runCommand({hello:1}).isWritablePrimary";
122-
_mongoDbShellCommand = new MongoDbShellCommand(js, configuration.Username, configuration.Password);
123-
}
112+
private static readonly string[] LineEndings = { "\r\n", "\n" };
124113

125114
/// <inheritdoc />
126115
public async Task<bool> UntilAsync(IContainer container)
127116
{
128-
var execResult = await container.ExecAsync(_mongoDbShellCommand)
117+
var (stdout, stderr) = await container.GetLogs(timestampsEnabled: false)
129118
.ConfigureAwait(false);
130119

131-
return 0L.Equals(execResult.ExitCode) && "true\n".Equals(execResult.Stdout, StringComparison.OrdinalIgnoreCase);
120+
return 2.Equals(Array.Empty<string>()
121+
.Concat(stdout.Split(LineEndings, StringSplitOptions.RemoveEmptyEntries))
122+
.Concat(stderr.Split(LineEndings, StringSplitOptions.RemoveEmptyEntries))
123+
.Count(line => line.Contains("Waiting for connections")));
132124
}
133125
}
134126
}

src/Testcontainers.MongoDb/MongoDbContainer.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ public async Task<ExecResult> ExecScriptAsync(string scriptContent, Cancellation
4343
await CopyFileAsync(scriptFilePath, Encoding.Default.GetBytes(scriptContent), 493, 0, 0, ct)
4444
.ConfigureAwait(false);
4545

46-
return await ExecAsync(new MongoDbShellCommand($"load('{scriptFilePath}')", _configuration.Username, _configuration.Password), ct)
46+
47+
var mongoShellCommand = new MongoDbShellCommand($"load('{scriptFilePath}')", _configuration.Username, _configuration.Password);
48+
49+
Logger.LogInformation(string.Format("{0}: {1}", Id, string.Join(" ", mongoShellCommand)));
50+
51+
var result = await ExecAsync(mongoShellCommand, ct)
4752
.ConfigureAwait(false);
53+
54+
Logger.LogInformation(string.Format("{0}: {1}", "ExitCode", result.ExitCode));
55+
Logger.LogInformation(string.Format("{0}: {1}", "Stdout", result.Stdout));
56+
Logger.LogInformation(string.Format("{0}: {1}", "Stderr", result.Stderr));
57+
58+
return result;
4859
}
4960
}

src/Testcontainers/BackwardCompatibility/BackwardsCompatibility.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#pragma warning disable SA1403
1+
#pragma warning disable SA1402
2+
#pragma warning disable SA1403
23

34
namespace DotNet.Testcontainers
45
{
@@ -98,4 +99,5 @@ public sealed class TestcontainersBuilder<TContainerEntity> : ContainerBuilder<T
9899
}
99100
}
100101

102+
#pragma warning restore SA1402
101103
#pragma warning restore SA1403

src/Testcontainers/Builders/IImageFromDockerfileBuilder`1.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace DotNet.Testcontainers.Builders
22
{
3-
using System;
43
using DotNet.Testcontainers.Images;
54
using JetBrains.Annotations;
65

src/Testcontainers/Images/DockerImage.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace DotNet.Testcontainers.Images
66

77
/// <inheritdoc cref="IImage" />
88
[PublicAPI]
9-
public sealed partial class DockerImage : IImage
9+
public sealed class DockerImage : IImage
1010
{
1111
private static readonly Func<string, IImage> GetDockerImage = MatchImage.Match;
1212

src/strongname.pub

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0024000004800000940000000602000000240000525341310004000001000100d11d30732581cf3e164cf872af326ceeeee2ff5ed15e68a9dad4c3ee5a60d9f6d094a50f82347147200cfe4710562800bb40296b160cab40def36769087e7d0938bd109df4cc015659f014430c325ce25259407402f1efd6ab33dec7a0d073e00e09f205f447a127558d862a15fe20aed1c607b615536c1ac2f92870e90b87c4

src/strongname.snk

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:f38c749ff7790241c728a936bb535e427d8a47fbc63a4672a1758e06374ca069
3+
size 596

tests/Directory.Build.props

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
4+
<PropertyGroup>
5+
<SignAssembly>false</SignAssembly>
6+
</PropertyGroup>
7+
</Project>

tests/Testcontainers.Commons/Testcontainers.Commons.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<Configurations>Debug;Release</Configurations>
88
<RootNamespace>DotNet.Testcontainers.Commons</RootNamespace>
99
</PropertyGroup>
10+
<PropertyGroup>
11+
<SignAssembly>true</SignAssembly>
12+
</PropertyGroup>
1013
<ItemGroup>
1114
<PackageReference Include="JetBrains.Annotations" />
1215
</ItemGroup>

tests/Testcontainers.Tests/Testcontainers.Tests.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<Configurations>Debug;Release</Configurations>
88
<RootNamespace>DotNet.Testcontainers.Tests</RootNamespace>
99
</PropertyGroup>
10+
<PropertyGroup>
11+
<SignAssembly>true</SignAssembly>
12+
</PropertyGroup>
1013
<ItemGroup>
1114
<PackageReference Include="JetBrains.Annotations" />
1215
<PackageReference Include="Microsoft.NET.Test.Sdk" />

0 commit comments

Comments
 (0)