Compare commits

..

9 commits

Author SHA1 Message Date
b642b7bc9b
refactor: use Husky.NET instead of pre-commit
Some checks failed
continuous-integration/drone/push Build is failing
2023-09-18 10:59:46 +02:00
980414b794
ci: migrate to Drone CI
Some checks failed
continuous-integration/drone/push Build is failing
2023-09-15 19:40:34 +02:00
2061f6f684
chore: update deps 2023-09-15 19:01:48 +02:00
Peter Kurfer
222715b077
chore(deps): update to latest versions
All checks were successful
agola/client-dotnet/Lint The run finished successfully
2022-09-26 17:03:28 +02:00
25ae369e6e
Update dependency nuke.globaltool to v6.1.2
All checks were successful
agola/client-dotnet/Lint The run finished successfully
2022-09-26 16:55:35 +02:00
2c45a41a0d
Update dependency Nuke.Common to v6.1.2
All checks were successful
agola/client-dotnet/Lint The run finished successfully
2022-09-26 16:52:26 +02:00
Peter Kurfer
d26b7ff041
fix(ci): add GitVersion tool
All checks were successful
agola/client-dotnet/Lint The run finished successfully
2022-09-26 16:50:30 +02:00
Peter Kurfer
d8143ffd3a
fix(tests): start container as part of test fixture
All checks were successful
agola/client-dotnet/Lint The run finished successfully
2022-09-26 16:33:59 +02:00
Peter Kurfer
a4812683bb
chore(ci): add Agola CI config
Some checks failed
agola/client-dotnet/Lint The run failed
2022-09-26 15:15:26 +02:00
30 changed files with 310 additions and 188 deletions

53
.agola/config.yml Normal file
View file

@ -0,0 +1,53 @@
version: v0
runs:
- name: Lint
tasks:
- name: Checkout code
runtime:
containers:
- image: docker.io/alpine/git
steps:
- clone:
- save_to_workspace:
contents:
- source_dir: .
dest_dir: .
paths:
- '**'
- name: Run .NET tests
runtime:
containers:
- image: mcr.microsoft.com/dotnet/sdk:6.0
environment:
DOCKER_HOST: tcp://127.0.0.1:2375
INETMOCK_SOCKET: http://127.0.0.1:6767
TESTCONTAINERS_RYUK_DISABLED: "true"
- image: code.icb4dc0.de/prskr/ci-images/dind:latest
privileged: true
steps:
- restore_workspace:
dest_dir: .
- run:
name: .NET tests
command: |-
dotnet tool restore
dotnet nuke Test
depends:
- Checkout code
- name: Lint protobuf
runtime:
containers:
- image: docker.io/bufbuild/buf:latest
steps:
- restore_workspace:
dest_dir: .
- run:
name: buf lint
command: |-
buf ls-files
buf lint
working_dir: ~/project/api/proto
depends:
- Checkout code

View file

@ -3,16 +3,34 @@
"isRoot": true, "isRoot": true,
"tools": { "tools": {
"dotnet-grpc": { "dotnet-grpc": {
"version": "2.47.0", "version": "2.57.0",
"commands": [ "commands": [
"dotnet-grpc" "dotnet-grpc"
] ]
}, },
"nuke.globaltool": { "nuke.globaltool": {
"version": "6.0.3", "version": "7.0.5",
"commands": [ "commands": [
"nuke" "nuke"
] ]
},
"gitversion.tool": {
"version": "5.12.0",
"commands": [
"dotnet-gitversion"
]
},
"husky": {
"version": "0.6.1",
"commands": [
"husky"
]
},
"jetbrains.resharper.globaltools": {
"version": "2023.2.1",
"commands": [
"jb"
]
} }
} }
} }

24
.drone.yml Normal file
View file

@ -0,0 +1,24 @@
---
kind: pipeline
type: docker
name: default
platform:
os: linux
arch: arm64
trigger:
branch:
- main
event:
- push
- pull_request
- tag
steps:
- name: Test
image: mcr.microsoft.com/dotnet/sdk:6.0
commands:
- dotnet tool restore
- dotnet restore
- dotnet nuke test

View file

@ -6,6 +6,7 @@ end_of_line = lf
charset = utf-8 charset = utf-8
insert_final_newline = true insert_final_newline = true
max_line_length = 120 max_line_length = 120
indent_size = 4
[*.xml] [*.xml]
indent_size = 4 indent_size = 4
@ -14,6 +15,16 @@ indent_size = 4
indent_size = 4 indent_size = 4
csharp_style_namespace_declarations = file_scoped:warning csharp_style_namespace_declarations = file_scoped:warning
csharp_prefer_braces = true:warning csharp_prefer_braces = true:warning
dotnet_style_qualification_for_field = false:warning
dotnet_style_qualification_for_property = false:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_event = false:warning
dotnet_style_require_accessibility_modifiers = omit_if_default:warning
csharp_style_expression_bodied_methods = true:silent
csharp_style_expression_bodied_properties = true:warning
csharp_style_expression_bodied_indexers = true:warning
csharp_style_expression_bodied_accessors = true:warning
[*.json] [*.json]
indent_size = 2 indent_size = 2

View file

@ -1,61 +0,0 @@
image: mcr.microsoft.com/dotnet/sdk:6.0
stages:
- test
- release
variables:
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_CERT_PATH: "/certs/client"
DOCKER_TLS_VERIFY: 1
DOCKER_HOST: 'tcp://docker:2376'
test:
stage: test
services:
- docker:dind
before_script:
- |
curl https://download.docker.com/linux/static/stable/x86_64/docker-20.10.14.tgz | tar -xzv -C /usr/local/
docker run --rm -d \
--cap-add CAP_NET_RAW \
--cap-add CAP_NET_ADMIN \
--cap-add CAP_NET_BIND_SERVICE \
-u root \
-p 6767:6767 \
-e INETMOCK_API_LISTEN=tcp://0.0.0.0:6767 \
--name inetmock \
registry.gitlab.com/inetmock/inetmock:latest
for i in `seq 1 10`
do
docker exec -i inetmock /usr/lib/inetmock/bin/imctl health container 2>&1 > /dev/null || sleep 1;
done;
after_script:
- docker stop inetmock
variables:
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/docker
INETMOCK_SOCKET: http://docker:6767
script:
- dotnet tool restore
- dotnet nuke Test
protobuf-lint:
stage: test
image:
name: docker.io/bufbuild/buf:latest
entrypoint: [""]
script:
- cd api/proto/
- buf ls-files
- buf lint
nuget-publish:
stage: release
only:
refs:
- tags
script:
- dotnet tool restore
- dotnet nuke NuGetPush

4
.husky/pre-commit Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
dotnet husky run --group pre-commit

34
.husky/task-runner.json Normal file
View file

@ -0,0 +1,34 @@
{
"tasks": [
{
"name": "dotnet-format",
"group": "pre-commit",
"command": "dotnet",
"args": [
"dotnet-format",
"--include",
"${staged}"
],
"include": [
"**/*.cs",
"**/*.vb"
]
},
{
"name": "Run JB Clean Up Code",
"group": "pre-commit",
"command": "dotnet",
"pathMode": "relative",
"args": [
"jb",
"cleanupcode",
"INetMock.sln",
"--telemetry-optout"
],
"include": [
"**/*.cs",
"**/*.vb"
]
}
]
}

View file

@ -1,7 +1,7 @@
{ {
"$schema": "http://json-schema.org/draft-04/schema#", "$schema": "http://json-schema.org/draft-04/schema#",
"title": "Build Schema",
"$ref": "#/definitions/build", "$ref": "#/definitions/build",
"title": "Build Schema",
"definitions": { "definitions": {
"build": { "build": {
"type": "object", "type": "object",
@ -29,6 +29,7 @@
"AppVeyor", "AppVeyor",
"AzurePipelines", "AzurePipelines",
"Bamboo", "Bamboo",
"Bitbucket",
"Bitrise", "Bitrise",
"GitHubActions", "GitHubActions",
"GitLab", "GitLab",
@ -38,8 +39,8 @@
"TeamCity", "TeamCity",
"Terminal", "Terminal",
"TravisCI", "TravisCI",
"VisualStudio", "VSCode",
"VSCode" "VisualStudio"
] ]
}, },
"NoLogo": { "NoLogo": {

View file

@ -1,13 +0,0 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/dotnet/format
rev: "v5.1.225507" # Specify a tag or sha here, or run "pre-commit autoupdate"
hooks:
- id: dotnet-format
args:
- ""
- --folder
- --check
- --verbosity=detailed
- --include

View file

@ -7,8 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig .editorconfig = .editorconfig
.gitignore = .gitignore .gitignore = .gitignore
.gitlab-ci.yml = .gitlab-ci.yml
.pre-commit-config.yaml = .pre-commit-config.yaml
README.md = README.md README.md = README.md
global.json = global.json global.json = global.json
EndProjectSection EndProjectSection

View file

@ -2,7 +2,6 @@ using NuGet.Versioning;
using Nuke.Common; using Nuke.Common;
using Nuke.Common.CI; using Nuke.Common.CI;
using Nuke.Common.CI.GitLab; using Nuke.Common.CI.GitLab;
using Nuke.Common.Execution;
using Nuke.Common.Git; using Nuke.Common.Git;
using Nuke.Common.IO; using Nuke.Common.IO;
using Nuke.Common.ProjectModel; using Nuke.Common.ProjectModel;
@ -13,19 +12,18 @@ using Nuke.Common.Utilities.Collections;
using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks; using static Nuke.Common.Tools.DotNet.DotNetTasks;
[CheckBuildProjectConfigurations]
[ShutdownDotNetAfterServerBuild] [ShutdownDotNetAfterServerBuild]
class Build : NukeBuild class Build : NukeBuild
{ {
private const string NuGetSourceName = "GitLab"; const string NuGetSourceName = "GitLab";
public static int Main() => Execute<Build>(x => x.Test);
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
[Solution] readonly Solution? Solution;
[GitRepository] readonly GitRepository? GitRepository; [GitRepository] readonly GitRepository? GitRepository;
[GitVersion(NoFetch = true, Framework = "net6.0")] readonly GitVersion? GitVersion; [GitVersion(Framework = "net6.0", NoFetch = true)] readonly GitVersion? GitVersion;
[Solution] readonly Solution? Solution;
GitLab? CI => GitLab.Instance; GitLab? CI => GitLab.Instance;
@ -90,7 +88,8 @@ class Build : NukeBuild
.SetProject(csproj) .SetProject(csproj)
.SetConfiguration(Configuration) .SetConfiguration(Configuration)
.SetOutputDirectory(ArtifactsDirectory) .SetOutputDirectory(ArtifactsDirectory)
.SetVersion(GitVersion?.FullSemVer ?? SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToNormalizedString()) .SetVersion(GitVersion?.NuGetVersionV2 ??
SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToNormalizedString())
.EnableIncludeSource() .EnableIncludeSource()
.EnableIncludeSymbols() .EnableIncludeSymbols()
.EnableNoRestore() .EnableNoRestore()
@ -117,4 +116,6 @@ class Build : NukeBuild
.SetSource(NuGetSourceName) .SetSource(NuGetSourceName)
.SetTargetPath(nupkg) .SetTargetPath(nupkg)
.EnableProcessLogOutput()))); .EnableProcessLogOutput())));
public static int Main() => Execute<Build>(x => x.Test);
} }

View file

@ -7,8 +7,5 @@ public class Configuration : Enumeration
public static Configuration Debug = new() { Value = nameof(Debug) }; public static Configuration Debug = new() { Value = nameof(Debug) };
public static Configuration Release = new() { Value = nameof(Release) }; public static Configuration Release = new() { Value = nameof(Release) };
public static implicit operator string(Configuration configuration) public static implicit operator string(Configuration configuration) => configuration.Value;
{
return configuration.Value;
}
} }

View file

@ -13,8 +13,12 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Nuke.Common" Version="6.0.3" /> <PackageReference Include="Nuke.Common" Version="7.0.5"/>
<PackageDownload Include="GitVersion.Tool" Version="[5.8.0]"/> <PackageDownload Include="GitVersion.Tool" Version="[5.8.0]"/>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="ci\" />
</ItemGroup>
</Project> </Project>

View file

@ -71,7 +71,6 @@ public record Event<T> : EventBase where T : EventDetails, new()
{ {
public Event() public Event()
{ {
} }
public Event(EventEntity entity) : base(entity) public Event(EventEntity entity) : base(entity)

View file

@ -10,7 +10,6 @@ public interface IEventReader : IDisposable, IAsyncDisposable
IAsyncEnumerable<Event> ReadAllAsync(CancellationToken token = default); IAsyncEnumerable<Event> ReadAllAsync(CancellationToken token = default);
/// <summary> /// <summary>
///
/// </summary> /// </summary>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns> /// <returns>
@ -25,7 +24,6 @@ public interface IEventReader<T> : IDisposable, IAsyncDisposable where T : Event
IAsyncEnumerable<Event<T>> ReadAllAsync(CancellationToken token = default); IAsyncEnumerable<Event<T>> ReadAllAsync(CancellationToken token = default);
/// <summary> /// <summary>
///
/// </summary> /// </summary>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns> /// <returns>

View file

@ -1,7 +1,6 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Inetmock.Audit.V1;
namespace INetMock.Client.Audit; namespace INetMock.Client.Audit;

View file

@ -37,8 +37,5 @@ public sealed class GenericReader : IEventReader
public ValueTask DisposeAsync() => _reader.DisposeAsync(); public ValueTask DisposeAsync() => _reader.DisposeAsync();
public void Dispose() public void Dispose() => _reader.Dispose();
{
_reader.Dispose();
}
} }

View file

@ -9,9 +9,9 @@ namespace INetMock.Client.Audit.Serialization;
public sealed class ProtoReader : IProtoEventReader public sealed class ProtoReader : IProtoEventReader
{ {
private readonly bool _keepStreamOpen;
private readonly MemoryPool<byte> _memoryPool; private readonly MemoryPool<byte> _memoryPool;
private readonly Stream _sourceStream; private readonly Stream _sourceStream;
private readonly bool _keepStreamOpen;
public ProtoReader(Stream sourceStream, bool keepStreamOpen = false) public ProtoReader(Stream sourceStream, bool keepStreamOpen = false)
{ {

View file

@ -27,8 +27,8 @@ public enum DropMode
public sealed class TypedReader<T> : IEventReader<T> where T : EventDetails, new() public sealed class TypedReader<T> : IEventReader<T> where T : EventDetails, new()
{ {
private readonly IProtoEventReader _reader;
private readonly DropMode _dropMode; private readonly DropMode _dropMode;
private readonly IProtoEventReader _reader;
public TypedReader(IProtoEventReader reader, DropMode dropMode = DropMode.DropDetails) public TypedReader(IProtoEventReader reader, DropMode dropMode = DropMode.DropDetails)
{ {

View file

@ -9,10 +9,10 @@
<Using Include="Inetmock.Rpc.V1"/> <Using Include="Inetmock.Rpc.V1"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.21.1" /> <PackageReference Include="Google.Protobuf" Version="3.24.3"/>
<PackageReference Include="Grpc.Net.Client" Version="2.46.0" /> <PackageReference Include="Grpc.Net.Client" Version="2.57.0"/>
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.46.0" /> <PackageReference Include="Grpc.Net.ClientFactory" Version="2.57.0"/>
<PackageReference Include="Grpc.Tools" Version="2.46.3"> <PackageReference Include="Grpc.Tools" Version="2.58.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>

View file

@ -7,7 +7,7 @@ using System.Threading.Tasks;
using Google.Protobuf.WellKnownTypes; using Google.Protobuf.WellKnownTypes;
using Grpc.Core; using Grpc.Core;
using Grpc.Net.Client; using Grpc.Net.Client;
using ChannelFactory = INetMock.Client.Grpc.ChannelFactory; using INetMock.Client.Grpc;
namespace INetMock.Client.PCAP.Client; namespace INetMock.Client.PCAP.Client;
@ -32,7 +32,13 @@ public class PcapApiClient : IPcapApiClient
public async Task<IReadOnlyList<RecordingDevice>> ListAvailableDevicesAsync(CancellationToken token = default) public async Task<IReadOnlyList<RecordingDevice>> ListAvailableDevicesAsync(CancellationToken token = default)
{ {
var devices = await _pcapServiceClient.ListAvailableDevicesAsync(new(), Metadata.Empty, null, token); var devices = await _pcapServiceClient.ListAvailableDevicesAsync(
new ListAvailableDevicesRequest(),
Metadata.Empty,
null,
token
);
return devices.AvailableDevices return devices.AvailableDevices
.Select(d => new RecordingDevice( .Select(d => new RecordingDevice(
d.Name, d.Name,
@ -46,7 +52,13 @@ public class PcapApiClient : IPcapApiClient
public async Task<IReadOnlyList<Subscription>> ListActiveRecordingsAsync(CancellationToken token = default) public async Task<IReadOnlyList<Subscription>> ListActiveRecordingsAsync(CancellationToken token = default)
{ {
var recordings = await _pcapServiceClient.ListActiveRecordingsAsync(new(), Metadata.Empty, null, token); var recordings = await _pcapServiceClient.ListActiveRecordingsAsync(
new ListActiveRecordingsRequest(),
Metadata.Empty,
null,
token
);
return recordings.Subscriptions return recordings.Subscriptions
.Select(consumerKey => new Subscription(consumerKey)) .Select(consumerKey => new Subscription(consumerKey))
.ToList(); .ToList();

View file

@ -20,6 +20,7 @@ public class TypedReaderTest
Assert.NotNull(ev); Assert.NotNull(ev);
count++; count++;
} }
Assert.True(count > 0); Assert.True(count > 0);
} }
@ -27,7 +28,8 @@ public class TypedReaderTest
public async Task Test_ReadAllAsync_DropEntity_AuditFile_HTTPEvents() public async Task Test_ReadAllAsync_DropEntity_AuditFile_HTTPEvents()
{ {
await using var fileStream = File.OpenRead(Path.Join("testdata", "test.ima")); await using var fileStream = File.OpenRead(Path.Join("testdata", "test.ima"));
await using IEventReader<HttpDetails> httpReader = new TypedReader<HttpDetails>(new ProtoReader(fileStream), DropMode.DropEntity); await using IEventReader<HttpDetails> httpReader =
new TypedReader<HttpDetails>(new ProtoReader(fileStream), DropMode.DropEntity);
var count = 0; var count = 0;
await foreach (var ev in httpReader.ReadAllAsync()) await foreach (var ev in httpReader.ReadAllAsync())
@ -36,6 +38,7 @@ public class TypedReaderTest
Assert.NotNull(ev.Details); Assert.NotNull(ev.Details);
count++; count++;
} }
Assert.True(count > 0); Assert.True(count > 0);
} }
@ -51,6 +54,7 @@ public class TypedReaderTest
Assert.NotNull(ev); Assert.NotNull(ev);
count++; count++;
} }
Assert.True(count > 0); Assert.True(count > 0);
} }
@ -58,7 +62,8 @@ public class TypedReaderTest
public async Task Test_ReadAllAsync_DropEntity_AuditFile_DNSEvents() public async Task Test_ReadAllAsync_DropEntity_AuditFile_DNSEvents()
{ {
await using var fileStream = File.OpenRead(Path.Join("testdata", "test.ima")); await using var fileStream = File.OpenRead(Path.Join("testdata", "test.ima"));
await using IEventReader<DnsDetails> httpReader = new TypedReader<DnsDetails>(new ProtoReader(fileStream), DropMode.DropEntity); await using IEventReader<DnsDetails> httpReader =
new TypedReader<DnsDetails>(new ProtoReader(fileStream), DropMode.DropEntity);
var count = 0; var count = 0;
await foreach (var ev in httpReader.ReadAllAsync()) await foreach (var ev in httpReader.ReadAllAsync())
@ -66,6 +71,7 @@ public class TypedReaderTest
Assert.NotNull(ev); Assert.NotNull(ev);
count++; count++;
} }
Assert.True(count > 0); Assert.True(count > 0);
} }
} }

View file

@ -11,13 +11,14 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2"/>
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="Testcontainers" Version="3.5.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> <PackageReference Include="xunit" Version="2.5.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2"> <PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>

View file

@ -1,19 +1,52 @@
using System; using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using Xunit;
namespace INetMock.Client.IntegrationTest; namespace INetMock.Client.IntegrationTest;
public class INetMockFixture public class INetMockFixture : IAsyncLifetime
{ {
private const string DefaultINetMockSocketPath = "unix:///var/run/inetmock/inetmock.sock"; private const string DefaultINetMockSocketPath = "unix:///var/run/inetmock/inetmock.sock";
private readonly IContainer _inetmockContainer;
private readonly Stream _memStream = new MemoryStream();
public INetMockFixture() public INetMockFixture()
{
INetMockSocketPath = Environment.GetEnvironmentVariable("INETMOCK_SOCKET") ?? DefaultINetMockSocketPath;
if (INetMockSocketPath.StartsWith("http:"))
{ {
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
}
_inetmockContainer = new ContainerBuilder()
.WithPrivileged(true)
.WithExposedPort(6767)
.WithPortBinding(6767, true)
.WithCreateParameterModifier(parameters => { parameters.User = "root"; })
.WithEnvironment("INETMOCK_API_LISTEN", "tcp://0.0.0.0:6767")
.WithImage("registry.gitlab.com/inetmock/inetmock:latest")
.WithName("inetmock")
.WithWaitStrategy(Wait.ForUnixContainer().UntilOperationIsSucceeded(() =>
{
Thread.Sleep(5000);
return true;
}, 1))
.Build();
} }
public string INetMockSocketPath { get; } public string INetMockSocketPath { get; private set; } = DefaultINetMockSocketPath;
public async Task InitializeAsync()
{
await using (_memStream)
{
await _inetmockContainer.StartAsync();
}
INetMockSocketPath = $"http://{_inetmockContainer.Hostname}:{_inetmockContainer.GetMappedPublicPort(6767)}";
}
public async Task DisposeAsync() => await _inetmockContainer.StopAsync();
} }

View file

@ -8,8 +8,8 @@ namespace INetMock.Client.IntegrationTest.PCAP.Client;
public class PcapApiClientTests : IClassFixture<INetMockFixture> public class PcapApiClientTests : IClassFixture<INetMockFixture>
{ {
private readonly ITestOutputHelper _outputHelper;
private readonly IPcapApiClient _apiClient; private readonly IPcapApiClient _apiClient;
private readonly ITestOutputHelper _outputHelper;
public PcapApiClientTests(ITestOutputHelper testOutputHelper, INetMockFixture inetMockFixture) public PcapApiClientTests(ITestOutputHelper testOutputHelper, INetMockFixture inetMockFixture)
{ {
@ -48,7 +48,7 @@ public class PcapApiClientTests : IClassFixture<INetMockFixture>
} }
var targetPath = $"/tmp/{recordingDevice.Name}_record.pcap"; var targetPath = $"/tmp/{recordingDevice.Name}_record.pcap";
await _apiClient.StartPcapFileRecordingAsync(new(recordingDevice.Name, targetPath)); await _apiClient.StartPcapFileRecordingAsync(new RecordingRequest(recordingDevice.Name, targetPath));
var subscriptions = await _apiClient.ListActiveRecordingsAsync(); var subscriptions = await _apiClient.ListActiveRecordingsAsync();
Assert.Contains(subscriptions, subscription => Assert.Contains(subscriptions, subscription =>

View file

@ -8,11 +8,15 @@ namespace INetMock.Client.Test.Audit.Serialization;
public class GenericReaderTest public class GenericReaderTest
{ {
private const string HttpEventPayload = "000000a7120b088092b8c398feffffff01180120022a047f00000132047f00000138d8fc0140504a3308041224544c535f45434448455f45434453415f574954485f4145535f3235365f4342435f5348411a096c6f63616c686f7374a2014c080112096c6f63616c686f73741a15687474703a2f2f6c6f63616c686f73742f6173646622084854545020312e312a1c0a0641636365707412120a106170706c69636174696f6e2f6a736f6e"; private const string HttpEventPayload =
private const string DnsEventPayload = "0000004e120b088092b8c398feffffff01180220012a100000000000000000000000000000000132100000000000000000000000000000000138d8fc014050aa0110120e0801120a6769746c61622e636f6d"; "000000a7120b088092b8c398feffffff01180120022a047f00000132047f00000138d8fc0140504a3308041224544c535f45434448455f45434453415f574954485f4145535f3235365f4342435f5348411a096c6f63616c686f7374a2014c080112096c6f63616c686f73741a15687474703a2f2f6c6f63616c686f73742f6173646622084854545020312e312a1c0a0641636365707412120a106170706c69636174696f6e2f6a736f6e";
private const string DnsEventPayload =
"0000004e120b088092b8c398feffffff01180220012a100000000000000000000000000000000132100000000000000000000000000000000138d8fc014050aa0110120e0801120a6769746c61622e636f6d";
private readonly byte[] _dnsEventPayloadBytes;
private readonly byte[] _httpEventPayloadBytes; private readonly byte[] _httpEventPayloadBytes;
private readonly byte[] _dnsEventPayloadBytes;
public GenericReaderTest() public GenericReaderTest()
{ {

View file

@ -8,11 +8,15 @@ namespace INetMock.Client.Test.Audit.Serialization;
public class TypedReaderTest public class TypedReaderTest
{ {
private const string HttpEventPayload = "000000e5120b088092b8c398feffffff01180120022a047f00000132047f00000138d8fc0140504a3308041224544c535f45434448455f45434453415f574954485f4145535f3235365f4342435f5348411a096c6f63616c686f7374528a010a3c747970652e676f6f676c65617069732e636f6d2f696e65746d6f636b2e61756469742e64657461696c732e4854545044657461696c73456e74697479124a12096c6f63616c686f73741a15687474703a2f2f6c6f63616c686f73742f6173646622084854545020312e312a1c0a0641636365707412120a106170706c69636174696f6e2f6a736f6e"; private const string HttpEventPayload =
private const string DnsEventPayload = "0000003b120b088092b8c398feffffff01180120012a100000000000000000000000000000000132100000000000000000000000000000000138d8fc014050"; "000000e5120b088092b8c398feffffff01180120022a047f00000132047f00000138d8fc0140504a3308041224544c535f45434448455f45434453415f574954485f4145535f3235365f4342435f5348411a096c6f63616c686f7374528a010a3c747970652e676f6f676c65617069732e636f6d2f696e65746d6f636b2e61756469742e64657461696c732e4854545044657461696c73456e74697479124a12096c6f63616c686f73741a15687474703a2f2f6c6f63616c686f73742f6173646622084854545020312e312a1c0a0641636365707412120a106170706c69636174696f6e2f6a736f6e";
private const string DnsEventPayload =
"0000003b120b088092b8c398feffffff01180120012a100000000000000000000000000000000132100000000000000000000000000000000138d8fc014050";
private readonly byte[] _dnsEventPayloadBytes;
private readonly byte[] _httpEventPayloadBytes; private readonly byte[] _httpEventPayloadBytes;
private readonly byte[] _dnsEventPayloadBytes;
public TypedReaderTest() public TypedReaderTest()
{ {

View file

@ -5,11 +5,9 @@ namespace INetMock.Client.Test.Hex;
public static class Converter public static class Converter
{ {
public static byte[] HexToByteArray(this string hex) public static byte[] HexToByteArray(this string hex) =>
{ Enumerable.Range(0, hex.Length)
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0) .Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray(); .ToArray();
} }
}

View file

@ -1,27 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> <PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2"> <PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\INetMock.Client\INetMock.Client.csproj" /> <ProjectReference Include="..\..\src\INetMock.Client\INetMock.Client.csproj" />
</ItemGroup> </ItemGroup>
<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High" />
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High" WorkingDirectory="../.." />
</Target>
</Project> </Project>