Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Sign assemblies with a strong name #815

Merged
merged 3 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*.crt filter=lfs diff=lfs merge=lfs -text
*.ico filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.snk filter=lfs diff=lfs merge=lfs -text

# Setting up Netlify with Git LFS is cumbersome
docs/*.ico !filter=lfs !diff=lfs !merge=lfs -text
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
lfs: true

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
14 changes: 9 additions & 5 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<SolutionDir Condition=" '$(SolutionDir)' == '' ">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), Testcontainers.sln))/</SolutionDir>
<SolutionDir Condition=" '$(SolutionDir)' == '' ">$([MSBuild]::GetDirectoryNameOfFileAbove('$(MSBuildProjectDirectory)', 'Testcontainers.sln'))/</SolutionDir>
</PropertyGroup>
<PropertyGroup>
<PackageId>$(AssemblyName)</PackageId>
Expand All @@ -23,13 +23,17 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/testcontainers/testcontainers-dotnet</RepositoryUrl>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>$(SolutionDir)src/strongname.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<NoWarn>CS0618,CS1591,SA0001,SA1600,SA1633,SA1649</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup>
<NoWarn>CA1716,CS1591,SA0001,SA1402,SA1600,SA1633,SA1649,CS0618</NoWarn>
</PropertyGroup>
<ItemGroup>
<None Include="$(SolutionDir)docs/banner.png" Visible="false" Pack="true" PackagePath="docs/" />
<None Include="$(SolutionDir)docs/logo.png" Visible="false" Pack="true" PackagePath="docs/" />
Expand All @@ -38,7 +42,7 @@
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Testcontainers.Tests</_Parameter1>
<_Parameter1>Testcontainers.Tests, PublicKey=$([System.IO.File]::ReadAllText($(SolutionDir)src/strongname.pub))</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" />
<PackageReference Update="JetBrains.Annotations" Version="2022.3.1" PrivateAssets="all" />
<PackageReference Update="Docker.DotNet" Version="3.125.12" />
<PackageReference Update="Docker.DotNet.X509" Version="3.125.12" />
<PackageReference Update="Docker.DotNet" Version="3.125.13" />
<PackageReference Update="Docker.DotNet.X509" Version="3.125.13" />
<PackageReference Update="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="6.0.3" />
<PackageReference Update="Portable.BouncyCastle" Version="1.9.0" />
Expand Down
28 changes: 14 additions & 14 deletions Testcontainers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Redis", "src
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Redpanda", "src\Testcontainers.Redpanda\Testcontainers.Redpanda.csproj", "{45D6F69C-4D87-4130-AA90-0DB2F7460DAE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.SqlEdge", "src\Testcontainers.SqlEdge\Testcontainers.SqlEdge.csproj", "{C95A3B2F-2B28-49A7-8806-731C158BBC21}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers", "src\Testcontainers\Testcontainers.csproj", "{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Commons", "tests\Testcontainers.Commons\Testcontainers.Commons.csproj", "{2478673C-B063-469D-ABD1-0C3E0A25541B}"
Expand Down Expand Up @@ -99,12 +101,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Redpanda.Tes
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.ResourceReaper.Tests", "tests\Testcontainers.ResourceReaper.Tests\Testcontainers.ResourceReaper.Tests.csproj", "{9E8E6AA5-65D1-498F-BEAB-BA34723A0050}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tests\Testcontainers.Tests\Testcontainers.Tests.csproj", "{27CDB869-A150-4593-958F-6F26E5391E7C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.SqlEdge", "src\Testcontainers.SqlEdge\Testcontainers.SqlEdge.csproj", "{C95A3B2F-2B28-49A7-8806-731C158BBC21}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.SqlEdge.Tests", "tests\Testcontainers.SqlEdge.Tests\Testcontainers.SqlEdge.Tests.csproj", "{1A1983E6-5297-435F-B467-E8E1F11277D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tests\Testcontainers.Tests\Testcontainers.Tests.csproj", "{27CDB869-A150-4593-958F-6F26E5391E7C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -190,6 +190,10 @@ Global
{45D6F69C-4D87-4130-AA90-0DB2F7460DAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45D6F69C-4D87-4130-AA90-0DB2F7460DAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45D6F69C-4D87-4130-AA90-0DB2F7460DAE}.Release|Any CPU.Build.0 = Release|Any CPU
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Release|Any CPU.Build.0 = Release|Any CPU
{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -286,18 +290,14 @@ Global
{9E8E6AA5-65D1-498F-BEAB-BA34723A0050}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E8E6AA5-65D1-498F-BEAB-BA34723A0050}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E8E6AA5-65D1-498F-BEAB-BA34723A0050}.Release|Any CPU.Build.0 = Release|Any CPU
{27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.Build.0 = Release|Any CPU
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C95A3B2F-2B28-49A7-8806-731C158BBC21}.Release|Any CPU.Build.0 = Release|Any CPU
{1A1983E6-5297-435F-B467-E8E1F11277D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A1983E6-5297-435F-B467-E8E1F11277D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A1983E6-5297-435F-B467-E8E1F11277D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A1983E6-5297-435F-B467-E8E1F11277D6}.Release|Any CPU.Build.0 = Release|Any CPU
{27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{58E94721-2681-4D82-8D94-0B2F9DB0D575} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
Expand All @@ -319,6 +319,7 @@ Global
{F6394475-D6F1-46E2-81BF-4BA78A40B878} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{BFDA179A-40EB-4CEB-B8E9-0DF32C65E2C5} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{45D6F69C-4D87-4130-AA90-0DB2F7460DAE} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{C95A3B2F-2B28-49A7-8806-731C158BBC21} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{2478673C-B063-469D-ABD1-0C3E0A25541B} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{809322BA-D690-4F2B-B884-23F895663963} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
Expand All @@ -343,8 +344,7 @@ Global
{31EE94A0-E721-4073-B6F1-DD912D004DEF} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{867BD04E-4670-4FBA-98D5-9F83220E6DFB} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{9E8E6AA5-65D1-498F-BEAB-BA34723A0050} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{C95A3B2F-2B28-49A7-8806-731C158BBC21} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{1A1983E6-5297-435F-B467-E8E1F11277D6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
EndGlobalSection
EndGlobal
1 change: 0 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Task("Build")
Verbosity = param.Verbosity,
NoRestore = true,
ArgumentCustomization = args => args
.Append($"/p:TreatWarningsAsErrors={param.IsReleaseBuild.ToString()}")
});
});

Expand Down
26 changes: 9 additions & 17 deletions src/Testcontainers.MongoDb/MongoDbBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public MongoDbBuilder WithPassword(string password)
public override MongoDbContainer Build()
{
Validate();

var mongoDbBuilder = DockerResourceConfiguration.WaitStrategies.Count() > 1 ? this : WithWaitStrategy(Wait.ForUnixContainer().AddCustomWaitStrategy(new WaitUntil(DockerResourceConfiguration)));
return new MongoDbContainer(mongoDbBuilder.DockerResourceConfiguration, TestcontainersSettings.Logger);
return new MongoDbContainer(DockerResourceConfiguration, TestcontainersSettings.Logger);
}

/// <inheritdoc />
Expand All @@ -72,7 +70,8 @@ protected override MongoDbBuilder Init()
.WithImage(MongoDbImage)
.WithPortBinding(MongoDbPort, true)
.WithUsername(DefaultUsername)
.WithPassword(DefaultPassword);
.WithPassword(DefaultPassword)
.WithWaitStrategy(Wait.ForUnixContainer().AddCustomWaitStrategy(new WaitUntil()));
}

/// <inheritdoc />
Expand Down Expand Up @@ -110,25 +109,18 @@ protected override MongoDbBuilder Merge(MongoDbConfiguration oldValue, MongoDbCo
/// <inheritdoc cref="IWaitUntil" />
private sealed class WaitUntil : IWaitUntil
{
private readonly IList<string> _mongoDbShellCommand;

/// <summary>
/// Initializes a new instance of the <see cref="WaitUntil" /> class.
/// </summary>
/// <param name="configuration">The container configuration.</param>
public WaitUntil(MongoDbConfiguration configuration)
{
const string js = "db.runCommand({hello:1}).isWritablePrimary";
_mongoDbShellCommand = new MongoDbShellCommand(js, configuration.Username, configuration.Password);
}
private static readonly string[] LineEndings = { "\r\n", "\n" };

/// <inheritdoc />
public async Task<bool> UntilAsync(IContainer container)
{
var execResult = await container.ExecAsync(_mongoDbShellCommand)
var (stdout, stderr) = await container.GetLogs(timestampsEnabled: false)
.ConfigureAwait(false);

return 0L.Equals(execResult.ExitCode) && "true\n".Equals(execResult.Stdout, StringComparison.OrdinalIgnoreCase);
return 2.Equals(Array.Empty<string>()
.Concat(stdout.Split(LineEndings, StringSplitOptions.RemoveEmptyEntries))
.Concat(stderr.Split(LineEndings, StringSplitOptions.RemoveEmptyEntries))
.Count(line => line.Contains("Waiting for connections")));
}
}
}
13 changes: 12 additions & 1 deletion src/Testcontainers.MongoDb/MongoDbContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ public async Task<ExecResult> ExecScriptAsync(string scriptContent, Cancellation
await CopyFileAsync(scriptFilePath, Encoding.Default.GetBytes(scriptContent), 493, 0, 0, ct)
.ConfigureAwait(false);

return await ExecAsync(new MongoDbShellCommand($"load('{scriptFilePath}')", _configuration.Username, _configuration.Password), ct)

var mongoShellCommand = new MongoDbShellCommand($"load('{scriptFilePath}')", _configuration.Username, _configuration.Password);

Logger.LogInformation(string.Format("{0}: {1}", Id, string.Join(" ", mongoShellCommand)));

var result = await ExecAsync(mongoShellCommand, ct)
.ConfigureAwait(false);

Logger.LogInformation(string.Format("{0}: {1}", "ExitCode", result.ExitCode));
Logger.LogInformation(string.Format("{0}: {1}", "Stdout", result.Stdout));
Logger.LogInformation(string.Format("{0}: {1}", "Stderr", result.Stderr));

return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma warning disable SA1403
#pragma warning disable SA1402
#pragma warning disable SA1403

namespace DotNet.Testcontainers
{
Expand Down Expand Up @@ -98,4 +99,5 @@ public sealed class TestcontainersBuilder<TContainerEntity> : ContainerBuilder<T
}
}

#pragma warning restore SA1402
#pragma warning restore SA1403
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace DotNet.Testcontainers.Builders
{
using System;
using DotNet.Testcontainers.Images;
using JetBrains.Annotations;

Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers/Images/DockerImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace DotNet.Testcontainers.Images

/// <inheritdoc cref="IImage" />
[PublicAPI]
public sealed partial class DockerImage : IImage
public sealed class DockerImage : IImage
{
private static readonly Func<string, IImage> GetDockerImage = MatchImage.Match;

Expand Down
1 change: 1 addition & 0 deletions src/strongname.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0024000004800000940000000602000000240000525341310004000001000100d11d30732581cf3e164cf872af326ceeeee2ff5ed15e68a9dad4c3ee5a60d9f6d094a50f82347147200cfe4710562800bb40296b160cab40def36769087e7d0938bd109df4cc015659f014430c325ce25259407402f1efd6ab33dec7a0d073e00e09f205f447a127558d862a15fe20aed1c607b615536c1ac2f92870e90b87c4
3 changes: 3 additions & 0 deletions src/strongname.snk
Git LFS file not shown
7 changes: 7 additions & 0 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
</Project>
3 changes: 3 additions & 0 deletions tests/Testcontainers.Commons/Testcontainers.Commons.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<Configurations>Debug;Release</Configurations>
<RootNamespace>DotNet.Testcontainers.Commons</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" />
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions tests/Testcontainers.Tests/Testcontainers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<Configurations>Debug;Release</Configurations>
<RootNamespace>DotNet.Testcontainers.Tests</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
Expand Down