From b6611a82977ab7212066e8f4697d891245db8d85 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 13 Oct 2021 12:04:46 +0000 Subject: [PATCH 01/51] Update mcr.microsoft.com/dotnet/sdk Docker tag to v6 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 671c2f3..5fa61e8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: mcr.microsoft.com/dotnet/sdk:5.0 +image: mcr.microsoft.com/dotnet/sdk:6.0 stages: - test -- 2.45.2 From 0fda26add512dff7e454f96902d091bea17b522d Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 13 Oct 2021 12:04:43 +0000 Subject: [PATCH 02/51] Update dependency nuke.globaltool to v5.3.0 --- .config/dotnet-tools.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index a68deb5..cc6da98 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -9,7 +9,7 @@ ] }, "nuke.globaltool": { - "version": "5.0.2", + "version": "5.3.0", "commands": [ "nuke" ] -- 2.45.2 From 15454a84dfb0d4251859a96723bdd1dffb862d6d Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 13 Oct 2021 11:03:58 +0000 Subject: [PATCH 03/51] Update dependency dotnet-grpc to v2.40.0 --- .config/dotnet-tools.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index cc6da98..8d59dce 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "dotnet-grpc": { - "version": "2.35.0", + "version": "2.40.0", "commands": [ "dotnet-grpc" ] -- 2.45.2 From 4b59642899428e7065cbf5ce21cd502bf0d63831 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 13 Oct 2021 11:03:55 +0000 Subject: [PATCH 04/51] Update dependency Nuke.Common to v5.3.0 --- build/_build.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/_build.csproj b/build/_build.csproj index 4f38007..adfe94b 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -10,7 +10,7 @@ - + -- 2.45.2 From ef41984bed740b887323bf2ca4ad678e939fadda Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 15 Oct 2021 11:04:00 +0000 Subject: [PATCH 05/51] Update dependency Grpc.Tools to v2.41.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index d44e560..7a54fa1 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -8,7 +8,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- 2.45.2 From c826462318a32c2e237a2a216cdb9779b3b1f812 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 15 Oct 2021 11:03:55 +0000 Subject: [PATCH 06/51] Update dependency Grpc.Net.Client to v2.40.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 7a54fa1..4ca27cb 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -6,7 +6,7 @@ - + all -- 2.45.2 From b262d43cba112ea390cd0148a636a03338419325 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 15 Oct 2021 12:04:37 +0000 Subject: [PATCH 07/51] Update dependency Grpc.Net.ClientFactory to v2.40.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 4ca27cb..1c031fd 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -7,7 +7,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- 2.45.2 From f359ea49325291ce4bb850e82c6c459649d0efda Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 20 Oct 2021 22:04:06 +0000 Subject: [PATCH 08/51] Update dependency Google.Protobuf to v3.19.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 1c031fd..bb0c688 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -5,7 +5,7 @@ latest - + -- 2.45.2 From 55dfb3ce5701230dd913683b8a2df33dda0b6e15 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 26 Oct 2021 12:04:43 +0000 Subject: [PATCH 09/51] Update dependency Grpc.Tools to v2.41.1 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index bb0c688..3029a30 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -8,7 +8,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- 2.45.2 From b61b4df2c2167018758dde59a3b9de2de480c3f4 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Wed, 26 Jan 2022 10:38:47 +0100 Subject: [PATCH 10/51] Squashed 'api/' changes from 9fe203c..a65ee4f a65ee4f Fix buf lint stage bc5fad6 Merge commit '580d2995be07ca1dd4839c3e9214ee881b98bb3e' into 45-add-api-to-restart-handlers 226c480 Add endpoint API to control running endpoint groups 505b06f Add support for DHCP to audit stream d742b08 Introduce profiling API e7e9e82 Introduce DNS-over-HTTPS and HTTP2 support 6a5ac9b Merge branch 'renovate/configure' into 'main' d9d3c9f Add renovate.json 5cad2aa Include PPROF handler to improve observability 3698421 Remove unnecessary proto import 74f521c Move to grpc default health service definition f341615 Return ConsumerKey when recording is started git-subtree-dir: api git-subtree-split: a65ee4f207bd1734095990e12e56069ec3881d0e --- .gitlab-ci.yml | 1 + buf.yaml | 20 --------- proto/audit/v1/dhcp_details.proto | 25 +++++++++++ proto/audit/v1/dns_details.proto | 6 --- proto/audit/v1/event_entity.proto | 20 +++++---- proto/audit/v1/http_details.proto | 6 --- proto/buf.yaml | 10 +++++ proto/rpc/v1/audit.proto | 6 --- proto/rpc/v1/endpoint.proto | 73 +++++++++++++++++++++++++++++++ proto/rpc/v1/health.proto | 34 -------------- proto/rpc/v1/pcap.proto | 7 +-- proto/rpc/v1/pprof.proto | 38 ++++++++++++++++ renovate.json | 6 +++ 13 files changed, 166 insertions(+), 86 deletions(-) delete mode 100644 buf.yaml create mode 100644 proto/audit/v1/dhcp_details.proto create mode 100644 proto/buf.yaml create mode 100644 proto/rpc/v1/endpoint.proto delete mode 100644 proto/rpc/v1/health.proto create mode 100644 proto/rpc/v1/pprof.proto create mode 100644 renovate.json diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d674fc4..e7e6606 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,5 +8,6 @@ stages: lint: stage: test script: + - cd proto/ - buf ls-files - buf lint diff --git a/buf.yaml b/buf.yaml deleted file mode 100644 index 1a3861e..0000000 --- a/buf.yaml +++ /dev/null @@ -1,20 +0,0 @@ -# Below is not the lint and breaking configuration we recommend! -# This just just what googleapis passes. -# For lint, we recommend having the single value "DEFAULT" in "use" -# with no values in "except". -# For breaking, we recommend having the single value "FILE" in use. -# See https://docs.buf.build/lint-usage -# See https://docs.buf.build/breaking-usage -version: v1beta1 -build: - roots: - - proto -lint: - use: - - DEFAULT - except: - - PACKAGE_DIRECTORY_MATCH - allow_comment_ignores: true -breaking: - use: - - FILE diff --git a/proto/audit/v1/dhcp_details.proto b/proto/audit/v1/dhcp_details.proto new file mode 100644 index 0000000..b0f1e37 --- /dev/null +++ b/proto/audit/v1/dhcp_details.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; + +package inetmock.audit.v1; + +enum DHCPOpCode { + DHCP_OP_CODE_UNSPECIFIED = 0; + DHCP_OP_CODE_BOOT_REQUEST = 1; + DHCP_OP_CODE_BOOT_REPLY = 2; +} + +enum DHCPHwType { + DHCP_HW_TYPE_UNSPECIFIED = 0; + DHCP_HW_TYPE_ETHERNET = 1; + DHCP_HW_TYPE_LOCAL_NET = 12; + DHCP_HW_TYPE_FIBRE_CHANNEL = 18; + DHCP_HW_TYPE_SERIAL_LINE = 20; + DHCP_HW_TYPE_IPSEC = 31; + DHCP_HW_TYPE_INFINIBAND = 32; +} + +message DHCPDetailsEntity { + int32 hop_count = 1; + DHCPOpCode opcode = 2; + DHCPHwType hw_type = 3; +} diff --git a/proto/audit/v1/dns_details.proto b/proto/audit/v1/dns_details.proto index e85b978..5b499ad 100644 --- a/proto/audit/v1/dns_details.proto +++ b/proto/audit/v1/dns_details.proto @@ -2,12 +2,6 @@ syntax = "proto3"; package inetmock.audit.v1; -option csharp_namespace = "INetMock.Client.Audit"; -option go_package = "gitlab.com/inetmock/inetmock/pkg/audit/v1"; -option java_multiple_files = true; -option java_outer_classname = "HandlerEventProto"; -option java_package = "com.github.baez90.inetmock.audit"; - enum DNSOpCode { //buf:lint:ignore ENUM_ZERO_VALUE_SUFFIX DNS_OP_CODE_QUERY = 0; diff --git a/proto/audit/v1/event_entity.proto b/proto/audit/v1/event_entity.proto index 0e2046f..d0b09bd 100644 --- a/proto/audit/v1/event_entity.proto +++ b/proto/audit/v1/event_entity.proto @@ -2,14 +2,10 @@ syntax = "proto3"; package inetmock.audit.v1; -option csharp_namespace = "INetMock.Client.Audit"; -option go_package = "gitlab.com/inetmock/inetmock/pkg/audit/v1"; -option java_multiple_files = true; -option java_outer_classname = "HandlerEventProto"; -option java_package = "com.github.baez90.inetmock.audit"; - -import "google/protobuf/any.proto"; import "google/protobuf/timestamp.proto"; +import "audit/v1/http_details.proto"; +import "audit/v1/dns_details.proto"; +import "audit/v1/dhcp_details.proto"; enum TransportProtocol { TRANSPORT_PROTOCOL_UNSPECIFIED = 0; @@ -22,6 +18,9 @@ enum AppProtocol { APP_PROTOCOL_DNS = 1; APP_PROTOCOL_HTTP = 2; APP_PROTOCOL_HTTP_PROXY = 3; + APP_PROTOCOL_PPROF = 4; + APP_PROTOCOL_DNS_OVER_HTTPS = 5; + APP_PROTOCOL_DHCP = 6; } enum TLSVersion { @@ -48,5 +47,10 @@ message EventEntity { uint32 source_port = 7; uint32 destination_port = 8; TLSDetailsEntity tls = 9; - google.protobuf.Any protocol_details = 10; + + oneof protocol_details { + HTTPDetailsEntity http = 20; + DNSDetailsEntity dns = 21; + DHCPDetailsEntity dhcp = 22; + } } diff --git a/proto/audit/v1/http_details.proto b/proto/audit/v1/http_details.proto index 6d55bfa..0f62c0c 100644 --- a/proto/audit/v1/http_details.proto +++ b/proto/audit/v1/http_details.proto @@ -2,12 +2,6 @@ syntax = "proto3"; package inetmock.audit.v1; -option csharp_namespace = "INetMock.Client.Audit"; -option go_package = "gitlab.com/inetmock/inetmock/pkg/audit/v1"; -option java_multiple_files = true; -option java_outer_classname = "HandlerEventProto"; -option java_package = "com.github.baez90.inetmock.audit"; - enum HTTPMethod { HTTP_METHOD_UNSPECIFIED = 0; HTTP_METHOD_GET = 1; diff --git a/proto/buf.yaml b/proto/buf.yaml new file mode 100644 index 0000000..e3198e7 --- /dev/null +++ b/proto/buf.yaml @@ -0,0 +1,10 @@ +version: v1 +breaking: + use: + - FILE +lint: + use: + - DEFAULT + except: + - PACKAGE_DIRECTORY_MATCH + allow_comment_ignores: true diff --git a/proto/rpc/v1/audit.proto b/proto/rpc/v1/audit.proto index 03a6459..6927383 100644 --- a/proto/rpc/v1/audit.proto +++ b/proto/rpc/v1/audit.proto @@ -2,12 +2,6 @@ syntax = "proto3"; package inetmock.rpc.v1; -option csharp_namespace = "INetMock.Client.Rpc"; -option go_package = "gitlab.com/inetmock/inetmock/pkg/rpc/v1"; -option java_multiple_files = true; -option java_outer_classname = "AuditProto"; -option java_package = "com.github.baez90.inetmock.rpc"; - import "audit/v1/event_entity.proto"; message WatchEventsRequest { diff --git a/proto/rpc/v1/endpoint.proto b/proto/rpc/v1/endpoint.proto new file mode 100644 index 0000000..66c9570 --- /dev/null +++ b/proto/rpc/v1/endpoint.proto @@ -0,0 +1,73 @@ +syntax = "proto3"; + +package inetmock.rpc.v1; + +message ListenerGroup { + string name = 1; + repeated string endpoints = 2; +} + +message ListAllServingGroupsRequest { +} + +message ListAllServingGroupsResponse { + repeated ListenerGroup groups = 1; +} + +message ListAllConfiguredGroupsRequest { +} + +message ListAllConfiguredGroupsResponse { + repeated ListenerGroup groups = 1; +} + +message StartListenerGroupRequest { + string group_name = 1; +} + +message StartListenerGroupResponse { +} + +message StartAllGroupsRequest { +} + +message StartAllGroupsResponse { +} + +message StopListenerGroupRequest { + string group_name = 1; +} + +message StopListenerGroupResponse { +} + +message StopAllGroupsRequest { +} + +message StopAllGroupsResponse { +} + +message RestartListenerGroupRequest { + string group_name = 1; +} + +message RestartListenerGroupResponse { +} + +message RestartAllGroupsRequest { +} + +message RestartAllGroupsResponse { +} + + +service EndpointOrchestratorService { + rpc ListAllServingGroups(ListAllServingGroupsRequest) returns(ListAllServingGroupsResponse); + rpc ListAllConfiguredGroups(ListAllConfiguredGroupsRequest) returns(ListAllConfiguredGroupsResponse); + rpc StartListenerGroup(StartListenerGroupRequest) returns (StartListenerGroupResponse); + rpc StartAllGroups(StartAllGroupsRequest) returns (StartAllGroupsResponse); + rpc StopListenerGroup(StopListenerGroupRequest) returns (StopListenerGroupResponse); + rpc StopAllGroups(StopAllGroupsRequest) returns (StopAllGroupsResponse); + rpc RestartListenerGroup(RestartListenerGroupRequest) returns (RestartListenerGroupResponse); + rpc RestartAllGroups(RestartAllGroupsRequest) returns (RestartAllGroupsResponse); +} diff --git a/proto/rpc/v1/health.proto b/proto/rpc/v1/health.proto deleted file mode 100644 index 8a543e4..0000000 --- a/proto/rpc/v1/health.proto +++ /dev/null @@ -1,34 +0,0 @@ -syntax = "proto3"; - -package inetmock.rpc.v1; - -option csharp_namespace = "INetMock.Client.Rpc"; -option go_package = "gitlab.com/inetmock/inetmock/pkg/rpc/v1"; -option java_multiple_files = true; -option java_outer_classname = "HealthProto"; -option java_package = "com.github.baez90.inetmock.rpc"; - -enum HealthState { - HEALTH_STATE_UNSPECIFIED = 0; - HEALTH_STATE_INITIALIZING = 1; - HEALTH_STATE_UNHEALTHY = 2; - HEALTH_STATE_HEALTHY = 3; -} - -message GetHealthRequest { - repeated string components = 1; -} - -message ComponentHealth { - HealthState state = 1; - string message = 2; -} - -message GetHealthResponse { - HealthState overall_health_state = 1; - map components_health = 2; -} - -service HealthService { - rpc GetHealth(GetHealthRequest) returns (GetHealthResponse); -} diff --git a/proto/rpc/v1/pcap.proto b/proto/rpc/v1/pcap.proto index 47628a3..7660938 100644 --- a/proto/rpc/v1/pcap.proto +++ b/proto/rpc/v1/pcap.proto @@ -2,12 +2,6 @@ syntax = "proto3"; package inetmock.rpc.v1; -option csharp_namespace = "INetMock.Client.Rpc"; -option go_package = "gitlab.com/inetmock/inetmock/pkg/rpc/v1"; -option java_multiple_files = true; -option java_outer_classname = "AuditProto"; -option java_package = "com.github.baez90.inetmock.rpc"; - import "google/protobuf/duration.proto"; message ListAvailableDevicesRequest {} @@ -35,6 +29,7 @@ message StartPCAPFileRecordingRequest { message StartPCAPFileRecordingResponse { string resolved_path = 1; + string consumer_key = 2; } message StopPCAPFileRecordingRequest { diff --git a/proto/rpc/v1/pprof.proto b/proto/rpc/v1/pprof.proto new file mode 100644 index 0000000..520779d --- /dev/null +++ b/proto/rpc/v1/pprof.proto @@ -0,0 +1,38 @@ +syntax = "proto3"; + +package inetmock.rpc.v1; + +import "google/protobuf/duration.proto"; + +message ProfileDumpRequest { + string profile_name = 1; + int32 debug = 2; + // this applies only for 'heap' profile + bool gc_before_dump = 3; +} + +message ProfileDumpResponse { + bytes profile_data = 1; +} + +message CPUProfileRequest { + google.protobuf.Duration profile_duration = 1; +} + +message CPUProfileResponse { + bytes profile_data = 1; +} + +message TraceRequest { + google.protobuf.Duration trace_duration = 1; +} + +message TraceResponse { + bytes profile_data = 1; +} + +service ProfilingService { + rpc ProfileDump(ProfileDumpRequest) returns (ProfileDumpResponse); + rpc CPUProfile(CPUProfileRequest) returns (CPUProfileResponse); + rpc Trace(TraceRequest) returns (TraceResponse); +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..39a2b6e --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ] +} -- 2.45.2 From 56b77353f2e3a9fe198f23016957ee761fb80ac3 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Wed, 26 Jan 2022 15:19:04 +0100 Subject: [PATCH 11/51] Update to .NET 6 and latest InetMock API --- .config/dotnet-tools.json | 4 +- .editorconfig | 2 + .gitlab-ci.yml | 28 +++- .nuke | 1 - .nuke/build.schema.json | 127 +++++++++++++++ .nuke/parameters.json | 4 + .pre-commit-config.yaml | 13 ++ INetMock.sln | 1 + build.cmd | 2 +- build.ps1 | 6 +- build.sh | 2 +- build/Build.cs | 60 +++---- build/Configuration.cs | 6 +- build/_build.csproj | 8 +- global.json | 6 + .../Audit/Client/AuditApiClient.cs | 112 +++++++------- src/INetMock.Client/Audit/Details.cs | 121 +++++---------- src/INetMock.Client/Audit/Event.cs | 146 ++++++++---------- src/INetMock.Client/Audit/IAuditApiClient.cs | 15 +- src/INetMock.Client/Audit/IEventReader.cs | 44 ++++-- .../Audit/INetMockHttpHeaders.cs | 15 +- .../Audit/IProtoEventReader.cs | 10 +- .../Serialization/EventServerStreamReader.cs | 36 +++-- .../Audit/Serialization/GenericReader.cs | 60 ++++--- .../Audit/Serialization/ProtoReader.cs | 89 ++++++----- .../Audit/Serialization/TypedReader.cs | 141 ++++++++--------- src/INetMock.Client/Grpc/ChannelFactory.cs | 55 ++++--- src/INetMock.Client/INetMock.Client.csproj | 20 ++- .../PCAP/Client/PcapApiClient.cs | 128 ++++++++------- src/INetMock.Client/PCAP/IPcapApiClient.cs | 14 +- src/INetMock.Client/PCAP/Models.cs | 77 +++++---- .../Audit/Serialization/GenericReaderTest.cs | 26 ++++ .../Audit/Serialization/TypedReaderTest.cs | 71 +++++++++ .../DockerEndpoint.cs | 36 ----- .../DockerEndpointTests.cs | 22 --- .../INetMock.Client.IntegrationTest.csproj | 15 +- .../INetMockFixture.cs | 19 +++ .../INetMockServerFixture.cs | 42 ----- .../PCAP/Client/PcapApiClientTests.cs | 70 +++++---- .../testdata/test.ima | Bin 0 -> 3946 bytes .../Audit/Serialization/GenericReaderTest.cs | 83 +++++----- .../Audit/Serialization/TypedReaderTest.cs | 57 ++++--- tests/INetMock.Client.Test/Hex/Converter.cs | 16 +- .../INetMock.Client.Test.csproj | 6 +- .../PCAP/SubscriptionTests.cs | 19 ++- 45 files changed, 1000 insertions(+), 835 deletions(-) delete mode 100644 .nuke create mode 100644 .nuke/build.schema.json create mode 100644 .nuke/parameters.json create mode 100644 .pre-commit-config.yaml create mode 100644 global.json create mode 100644 tests/INetMock.Client.IntegrationTest/Audit/Serialization/GenericReaderTest.cs create mode 100644 tests/INetMock.Client.IntegrationTest/Audit/Serialization/TypedReaderTest.cs delete mode 100644 tests/INetMock.Client.IntegrationTest/DockerEndpoint.cs delete mode 100644 tests/INetMock.Client.IntegrationTest/DockerEndpointTests.cs create mode 100644 tests/INetMock.Client.IntegrationTest/INetMockFixture.cs delete mode 100644 tests/INetMock.Client.IntegrationTest/INetMockServerFixture.cs create mode 100644 tests/INetMock.Client.IntegrationTest/testdata/test.ima diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 8d59dce..4b91376 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,13 +3,13 @@ "isRoot": true, "tools": { "dotnet-grpc": { - "version": "2.40.0", + "version": "2.42.0", "commands": [ "dotnet-grpc" ] }, "nuke.globaltool": { - "version": "5.3.0", + "version": "6.0.1", "commands": [ "nuke" ] diff --git a/.editorconfig b/.editorconfig index 01e1042..2a559ae 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,6 +12,8 @@ indent_size = 4 [*.cs] indent_size = 4 +csharp_style_namespace_declarations = file_scoped:warning +csharp_prefer_braces = true:warning [*.json] indent_size = 2 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5fa61e8..d7a9992 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,13 +14,30 @@ test: stage: test services: - docker:dind + before_script: + - | + curl https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.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: - - curl https://download.docker.com/linux/static/stable/x86_64/docker-20.10.4.tgz | tar -xzv -C /usr/local/ - - mkdir /usr/local/share/ca-certificates/docker-ca - - cp "${DOCKER_CERT_PATH}/ca.pem" /usr/local/share/ca-certificates/docker-ca/ - - update-ca-certificates --fresh - dotnet tool restore - dotnet nuke Test @@ -30,7 +47,7 @@ protobuf-lint: name: docker.io/bufbuild/buf:latest entrypoint: [""] script: - - cd api/ + - cd api/proto/ - buf ls-files - buf lint @@ -39,6 +56,7 @@ nuget-publish: only: refs: - tags + - main script: - dotnet tool restore - dotnet nuke NuGetPush diff --git a/.nuke b/.nuke deleted file mode 100644 index ae940c5..0000000 --- a/.nuke +++ /dev/null @@ -1 +0,0 @@ -INetMock.sln \ No newline at end of file diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json new file mode 100644 index 0000000..ed1030d --- /dev/null +++ b/.nuke/build.schema.json @@ -0,0 +1,127 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Build Schema", + "$ref": "#/definitions/build", + "definitions": { + "build": { + "type": "object", + "properties": { + "Configuration": { + "type": "string", + "description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)", + "enum": [ + "Debug", + "Release" + ] + }, + "Continue": { + "type": "boolean", + "description": "Indicates to continue a previously failed build attempt" + }, + "Help": { + "type": "boolean", + "description": "Shows the help text for this build assembly" + }, + "Host": { + "type": "string", + "description": "Host for execution. Default is 'automatic'", + "enum": [ + "AppVeyor", + "AzurePipelines", + "Bamboo", + "Bitrise", + "GitHubActions", + "GitLab", + "Jenkins", + "Rider", + "SpaceAutomation", + "TeamCity", + "Terminal", + "TravisCI", + "VisualStudio", + "VSCode" + ] + }, + "NoLogo": { + "type": "boolean", + "description": "Disables displaying the NUKE logo" + }, + "nuget-password": { + "type": "string", + "description": "Password to use for publishing NuGet packages" + }, + "nuget-username": { + "type": "string", + "description": "Username to use for publishing NuGet packages" + }, + "Partition": { + "type": "string", + "description": "Partition to use on CI" + }, + "Plan": { + "type": "boolean", + "description": "Shows the execution plan (HTML)" + }, + "Profile": { + "type": "array", + "description": "Defines the profiles to load", + "items": { + "type": "string" + } + }, + "Root": { + "type": "string", + "description": "Root directory during build execution" + }, + "Skip": { + "type": "array", + "description": "List of targets to be skipped. Empty list skips all dependencies", + "items": { + "type": "string", + "enum": [ + "AddNugetSource", + "Clean", + "Compile", + "Format", + "NuGetPush", + "Pack", + "Restore", + "Test" + ] + } + }, + "Solution": { + "type": "string", + "description": "Path to a solution file that is automatically loaded" + }, + "Target": { + "type": "array", + "description": "List of targets to be invoked. Default is '{default_target}'", + "items": { + "type": "string", + "enum": [ + "AddNugetSource", + "Clean", + "Compile", + "Format", + "NuGetPush", + "Pack", + "Restore", + "Test" + ] + } + }, + "Verbosity": { + "type": "string", + "description": "Logging verbosity during build execution. Default is 'Normal'", + "enum": [ + "Minimal", + "Normal", + "Quiet", + "Verbose" + ] + } + } + } + } +} \ No newline at end of file diff --git a/.nuke/parameters.json b/.nuke/parameters.json new file mode 100644 index 0000000..a165392 --- /dev/null +++ b/.nuke/parameters.json @@ -0,0 +1,4 @@ +{ + "$schema": "./build.schema.json", + "Solution": "INetMock.sln" +} \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..9cbe814 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +# 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 diff --git a/INetMock.sln b/INetMock.sln index 2d86fc6..54084ae 100644 --- a/INetMock.sln +++ b/INetMock.sln @@ -8,6 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt .editorconfig = .editorconfig .gitignore = .gitignore .gitlab-ci.yml = .gitlab-ci.yml + .pre-commit-config.yaml = .pre-commit-config.yaml EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{07100561-E3C0-4B95-92E1-D2D3BA12C3A6}" diff --git a/build.cmd b/build.cmd index 8b8b89d..b08cc59 100755 --- a/build.cmd +++ b/build.cmd @@ -4,4 +4,4 @@ :; exit $? @ECHO OFF -powershell -ExecutionPolicy ByPass -NoProfile "%~dp0build.ps1" %* +powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %* diff --git a/build.ps1 b/build.ps1 index e5c8a44..1c774e5 100644 --- a/build.ps1 +++ b/build.ps1 @@ -14,7 +14,7 @@ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent ########################################################################### $BuildProjectFile = "$PSScriptRoot\build\_build.csproj" -$TempDirectory = "$PSScriptRoot\\.tmp" +$TempDirectory = "$PSScriptRoot\\.nuke\temp" $DotNetGlobalFile = "$PSScriptRoot\\global.json" $DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1" @@ -56,9 +56,9 @@ else { # Install by channel or version $DotNetDirectory = "$TempDirectory\dotnet-win" if (!(Test-Path variable:DotNetVersion)) { - ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } } else { - ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } } $env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe" } diff --git a/build.sh b/build.sh index 3d52643..e8961f9 100755 --- a/build.sh +++ b/build.sh @@ -10,7 +10,7 @@ SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) ########################################################################### BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj" -TEMP_DIRECTORY="$SCRIPT_DIR//.tmp" +TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp" DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json" DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh" diff --git a/build/Build.cs b/build/Build.cs index e513723..2d9d880 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -1,4 +1,4 @@ -using System.IO; +using System; using JetBrains.Annotations; using Nuke.Common; using Nuke.Common.CI; @@ -8,7 +8,6 @@ using Nuke.Common.Git; using Nuke.Common.IO; using Nuke.Common.ProjectModel; using Nuke.Common.Tooling; -using Nuke.Common.Tools.Docker; using Nuke.Common.Tools.DotNet; using Nuke.Common.Tools.GitVersion; using Nuke.Common.Utilities.Collections; @@ -20,38 +19,29 @@ using static Nuke.Common.Tools.DotNet.DotNetTasks; class Build : NukeBuild { private const string NuGetSourceName = "GitLab"; - public static int Main() => Execute(x => x.Compile); + public static int Main() => Execute(x => x.Test); [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; + [Parameter("Username to use for publishing NuGet packages", Name = "nuget-username")] + string NuGetUsername { get; } = Environment.GetEnvironmentVariable("NUGET_USERNAME") ?? string.Empty; + + [Parameter("Password to use for publishing NuGet packages", Name = "nuget-password")] + string NuGetPassword { get; } = Environment.GetEnvironmentVariable("NUGET_PASSWORD") ?? string.Empty; + [Solution] readonly Solution Solution; [GitRepository] readonly GitRepository GitRepository; - [GitVersion(NoFetch = true, Framework = "net5.0")] readonly GitVersion GitVersion; + [GitVersion(NoFetch = true)] readonly GitVersion GitVersion; - [CanBeNull] GitLab CI => GitLab.Instance; + [CanBeNull] + GitLab CI => GitLab.Instance; AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath TestsDirectory => RootDirectory / "tests"; AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts"; - Target PrintEnv => _ => _ - .Executes(() => - { - if (CI == null) - { - Logger.Info("Running in local environment"); - Logger.Info($"Git commit: {GitRepository.Commit}"); - } - else - { - Logger.Info("Running in GitLab CI"); - Logger.Info($"Git commit: {CI.CommitSha}"); - Logger.Info($"Pipeline ID: {CI.PipelineId}"); - } - }); - Target Clean => _ => _ .Before(Restore) .Executes(() => @@ -69,7 +59,7 @@ class Build : NukeBuild }); Target Compile => _ => _ - .DependsOn(Restore, PrintEnv) + .DependsOn(Restore) .Executes(() => { DotNetBuild(s => s @@ -81,14 +71,12 @@ class Build : NukeBuild .EnableNoRestore()); }); - Target IntegrationTestImage => _ => _ - .Executes(() => DockerTasks.DockerBuild(s => s - .SetFile(Path.Join("assets", "integration-tests.dockerfile")) - .SetTag("inetmock-root") - .SetPath("."))); + Target Format => _ => _ + .DependsOn(Restore) + .Executes(() => DotNet(CI == null ? "format --no-restore" : "format --no-restore --verify-no-changes")); Target Test => _ => _ - .DependsOn(Compile, IntegrationTestImage) + .DependsOn(Compile, Format) .Executes(() => DotNetTest(s => s .SetProjectFile(Solution) .SetConfiguration(Configuration) @@ -97,20 +85,20 @@ class Build : NukeBuild .EnableProcessLogOutput())); Target AddNugetSource => _ => _ - .OnlyWhenStatic(() => GitRepository.IsOnMasterBranch()) + .OnlyWhenStatic(() => GitRepository.IsOnMainBranch()) .OnlyWhenStatic(() => CI != null) + .OnlyWhenStatic(() => !string.IsNullOrEmpty(NuGetUsername) && !string.IsNullOrEmpty(NuGetPassword)) .ProceedAfterFailure() .Executes(() => DotNetNuGetAddSource(s => s .SetName(NuGetSourceName) - //.SetSource($"https://gitlab.com/api/v4/projects/{CI.ProjectId}/packages/nuget/index.json") - .SetSource($"https://gitlab.com/api/v4/projects/24385200/packages/nuget/index.json") - .SetUsername("baez90") - .SetPassword("RcMwfaXgvBxSWt4ZMB6z") + .SetSource($"https://gitlab.com/api/v4/projects/{CI.ProjectId}/packages/nuget/index.json") + .SetUsername(NuGetUsername) + .SetPassword(NuGetPassword) .EnableStorePasswordInClearText())); Target Pack => _ => _ - .DependsOn(Test) - .OnlyWhenStatic(() => GitRepository.IsOnMasterBranch()) + .DependsOn(Compile) + .OnlyWhenStatic(() => GitRepository.IsOnMainBranch()) .Executes(() => SourceDirectory .GlobFiles("**/*.csproj") .ForEach(csproj => DotNetPack(s => s @@ -127,7 +115,7 @@ class Build : NukeBuild Target NuGetPush => _ => _ .DependsOn(Pack, AddNugetSource) - .OnlyWhenStatic(() => GitRepository.IsOnMasterBranch()) + .OnlyWhenStatic(() => GitRepository.IsOnMainBranch()) .Executes(() => ArtifactsDirectory .GlobFiles("**/*.nupkg") .ForEach(nupkg => DotNetNuGetPush(s => s diff --git a/build/Configuration.cs b/build/Configuration.cs index 9c08b1a..78049f7 100644 --- a/build/Configuration.cs +++ b/build/Configuration.cs @@ -1,13 +1,11 @@ -using System; using System.ComponentModel; -using System.Linq; using Nuke.Common.Tooling; [TypeConverter(typeof(TypeConverter))] public class Configuration : Enumeration { - public static Configuration Debug = new Configuration { Value = nameof(Debug) }; - public static Configuration Release = new Configuration { Value = nameof(Release) }; + public static Configuration Debug = new() { Value = nameof(Debug) }; + public static Configuration Release = new() { Value = nameof(Release) }; public static implicit operator string(Configuration configuration) { diff --git a/build/_build.csproj b/build/_build.csproj index adfe94b..794a52b 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -6,12 +6,14 @@ CS0649;CS0169 .. .. - net5.0 + net6.0 + latest + 1 - - + + diff --git a/global.json b/global.json new file mode 100644 index 0000000..08fc58c --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "6.0.100", + "rollForward": "latestMinor" + } +} \ No newline at end of file diff --git a/src/INetMock.Client/Audit/Client/AuditApiClient.cs b/src/INetMock.Client/Audit/Client/AuditApiClient.cs index 3559e17..0d5113d 100644 --- a/src/INetMock.Client/Audit/Client/AuditApiClient.cs +++ b/src/INetMock.Client/Audit/Client/AuditApiClient.cs @@ -6,69 +6,67 @@ using Grpc.Core; using Grpc.Net.Client; using INetMock.Client.Audit.Serialization; using INetMock.Client.Grpc; -using INetMock.Client.Rpc; -namespace INetMock.Client.Audit.Client +namespace INetMock.Client.Audit.Client; + +public class AuditApiClient : IAuditApiClient { - public class AuditApiClient : IAuditApiClient + private readonly AuditService.AuditServiceClient _auditClient; + + public AuditApiClient(string address, GrpcChannelOptions? options = null) : this(new Uri(address), options) { - private readonly AuditService.AuditServiceClient _auditClient; + } - public AuditApiClient(string address, GrpcChannelOptions? options = null) : this(new Uri(address), options) + public AuditApiClient(Uri address, GrpcChannelOptions? options = null) : this( + ChannelFactory.ForAddress(address, options ?? new GrpcChannelOptions())) + { + } + + public AuditApiClient(ChannelBase channel) + { + _auditClient = new AuditService.AuditServiceClient(channel); + } + + public async Task> ListSinksAsync(CancellationToken token = default) + { + var sinks = await _auditClient.ListSinksAsync(new ListSinksRequest(), Metadata.Empty, null, token); + return sinks.Sinks; + } + + public async Task RegisterFileSinkAsync(string targetPath, CancellationToken token = default) + { + var resp = await _auditClient.RegisterFileSinkAsync( + new RegisterFileSinkRequest { TargetPath = targetPath }, + Metadata.Empty, + null, + token + ); + + return resp.ResolvedPath; + } + + public async Task RemoveFileSinkAsync(string targetPath, CancellationToken token = default) + { + var resp = await _auditClient.RemoveFileSinkAsync(new RemoveFileSinkRequest { - } + TargetPath = targetPath + }, + Metadata.Empty, + null, + token + ); - public AuditApiClient(Uri address, GrpcChannelOptions? options = null) : this( - ChannelFactory.ForAddress(address, options ?? new GrpcChannelOptions())) - { - } + return resp.SinkGotRemoved; + } - public AuditApiClient(ChannelBase channel) - { - _auditClient = new AuditService.AuditServiceClient(channel); - } - - public async Task> ListSinksAsync(CancellationToken token = default) - { - var sinks = await _auditClient.ListSinksAsync(new ListSinksRequest(), Metadata.Empty, null, token); - return sinks.Sinks; - } - - public async Task RegisterFileSinkAsync(string targetPath, CancellationToken token = default) - { - var resp = await _auditClient.RegisterFileSinkAsync( - new RegisterFileSinkRequest {TargetPath = targetPath}, - Metadata.Empty, - null, - token - ); - - return resp.ResolvedPath; - } - - public async Task RemoveFileSinkAsync(string targetPath, CancellationToken token = default) - { - var resp = await _auditClient.RemoveFileSinkAsync(new RemoveFileSinkRequest - { - TargetPath = targetPath - }, - Metadata.Empty, - null, - token - ); - - return resp.SinkGotRemoved; - } - - public IProtoEventReader EventStreamAsync(string watcherName, CancellationToken token = default) - { - var stream = _auditClient.WatchEvents( - new WatchEventsRequest {WatcherName = watcherName}, - Metadata.Empty, - null, - token - ); - return new EventServerStreamReader(stream); - } + public IProtoEventReader EventStreamAsync(string watcherName, CancellationToken token = default) + { + var stream = _auditClient.WatchEvents( + new WatchEventsRequest { WatcherName = watcherName }, + Metadata.Empty, + null, + token + ); + return new EventServerStreamReader(stream); } } diff --git a/src/INetMock.Client/Audit/Details.cs b/src/INetMock.Client/Audit/Details.cs index ccfba88..d5dea8c 100644 --- a/src/INetMock.Client/Audit/Details.cs +++ b/src/INetMock.Client/Audit/Details.cs @@ -3,88 +3,51 @@ using System.Collections.Generic; using System.Net.Http; using System.Net.Http.Headers; using Google.Protobuf.Collections; -using Google.Protobuf.WellKnownTypes; -namespace INetMock.Client.Audit +namespace INetMock.Client.Audit; + +public abstract record EventDetails; + +public record HttpDetails() : EventDetails { - public abstract record EventDetails; - - public record EmptyDetails : EventDetails; - - public record GenericDetails : EventDetails + public HttpDetails(HTTPDetailsEntity detailsEntity) : this() { - private readonly Any? _detailsAny; - - public GenericDetails() - { - _detailsAny = null; - } - - public GenericDetails(Any? any) - { - _detailsAny = any; - } - - public static implicit operator HttpDetails(GenericDetails gd) - { - if (gd._detailsAny == null || gd._detailsAny.Value == null) return new(); - if (!gd._detailsAny.TypeUrl.EndsWith(HTTPDetailsEntity.Descriptor.FullName)) - throw new InvalidOperationException(); - return new HttpDetails(gd._detailsAny); - } - - public static implicit operator DnsDetails(GenericDetails gd) - { - if (gd._detailsAny == null || gd._detailsAny.Value == null) return new(); - if (!gd._detailsAny.TypeUrl.EndsWith(HTTPDetailsEntity.Descriptor.FullName)) - throw new InvalidOperationException(); - return new DnsDetails(gd._detailsAny); - } + Method = new HttpMethod(detailsEntity.Method.ToString()); + Host = detailsEntity.Host; + Uri = detailsEntity.Uri; + Proto = detailsEntity.Proto; + Headers = new INetMockHttpHeaders(detailsEntity.Headers); } - public record HttpDetails : EventDetails - { - public HttpDetails() - { - } - - public HttpDetails(Any? any) - { - if (any == null || any.Value == null) return; - - var detailsEntity = HTTPDetailsEntity.Parser.ParseFrom(any.Value); - - Method = new HttpMethod(detailsEntity.Method.ToString()); - Host = detailsEntity.Host; - Uri = detailsEntity.Uri; - Proto = detailsEntity.Proto; - Headers = new INetMockHttpHeaders(detailsEntity.Headers); - } - - public HttpMethod Method { get; init; } = HttpMethod.Get; - public string Host { get; init; } = string.Empty; - public string Uri { get; init; } = string.Empty; - public string Proto { get; init; } = string.Empty; - public HttpHeaders Headers { get; init; } = new INetMockHttpHeaders(new MapField()); - } - - public record DnsDetails : EventDetails - { - public DnsDetails() - { - } - - public DNSOpCode OpCode { get; init; } = DNSOpCode.Query; - - public IReadOnlyList Questions { get; init; } = Array.Empty(); - - public DnsDetails(Any? any) - { - if (any == null || any.Value == null) return; - - var entity = DNSDetailsEntity.Parser.ParseFrom(any.Value); - OpCode = entity.Opcode; - Questions = entity.Questions; - } - } + public HttpMethod Method { get; init; } = HttpMethod.Get; + public string Host { get; init; } = string.Empty; + public string Uri { get; init; } = string.Empty; + public string Proto { get; init; } = string.Empty; + public HttpHeaders Headers { get; init; } = new INetMockHttpHeaders(new MapField()); +} + +public record DnsDetails() : EventDetails +{ + public DnsDetails(DNSDetailsEntity entity) : this() + { + OpCode = entity.Opcode; + Questions = entity.Questions; + } + + public DNSOpCode OpCode { get; init; } = DNSOpCode.Query; + public IReadOnlyList Questions { get; init; } = Array.Empty(); +} + +public record DhcpDetails() : EventDetails +{ + public DhcpDetails(DHCPDetailsEntity entity) : this() + { + HopCount = entity.HopCount; + OpCode = entity.Opcode; + HardwareType = entity.HwType; + } + + public int HopCount { get; init; } + public DHCPOpCode OpCode { get; init; } = DHCPOpCode.Unspecified; + public DHCPHwType HardwareType { get; init; } = DHCPHwType.Unspecified; } diff --git a/src/INetMock.Client/Audit/Event.cs b/src/INetMock.Client/Audit/Event.cs index c1b93ff..3eeb1ff 100644 --- a/src/INetMock.Client/Audit/Event.cs +++ b/src/INetMock.Client/Audit/Event.cs @@ -1,90 +1,76 @@ using System; using System.Net; -namespace INetMock.Client.Audit +namespace INetMock.Client.Audit; + +public abstract record EventBase { - public record Event where T : EventDetails, new() + protected EventBase(EventEntity entity) { - public Event() + if (entity == null) { + throw new ArgumentNullException(nameof(entity)); } - public Event(EventEntity entity) - { - if (entity == null) throw new ArgumentNullException(nameof(entity)); - - var details = (new T(), entity.Application) switch - { - (GenericDetails, _) => new GenericDetails(entity.ProtocolDetails) as T, - (_, AppProtocol.Dns) => new DnsDetails(entity.ProtocolDetails) as T, - (_, AppProtocol.Http or AppProtocol.HttpProxy) => new HttpDetails(entity.ProtocolDetails) as T, - (_, _) => new EmptyDetails() as T - }; - - Id = entity.Id; - Timestamp = entity.Timestamp.ToDateTimeOffset(); - Transport = entity.Transport; - SourceIp = new IPAddress(entity.SourceIp.Span); - SourcePort = Convert.ToUInt16(entity.SourcePort); - DestinationIp = new IPAddress(entity.DestinationIp.Span); - DestinationPort = Convert.ToUInt16(entity.DestinationPort); - TlsDetails = entity.Tls; - Application = entity.Application; - Details = details; - } - - public long Id { get; init; } - public DateTimeOffset Timestamp { get; init; } - public TransportProtocol Transport { get; init; } - public AppProtocol Application { get; init; } - public IPAddress SourceIp { get; init; } = IPAddress.Any; - public IPAddress DestinationIp { get; init; } = IPAddress.Any; - public ushort SourcePort { get; init; } - public ushort DestinationPort { get; init; } - public TLSDetailsEntity TlsDetails { get; init; } = new(); - public T? Details { get; init; } - - public bool CanConvert() where TTarget : EventDetails, new() - { - if (Details == null) return false; - - return (new TTarget(), Application) switch - { - (DnsDetails, AppProtocol.Dns) => true, - (HttpDetails, AppProtocol.Http or AppProtocol.HttpProxy) => true, - (_, _) => false - }; - } - - public static explicit operator Event?(Event ge) - { - T? details = null; - if (ge.Details != null) - { - details = ge.Application switch - { - AppProtocol.Dns => (DnsDetails) ge.Details as T, - AppProtocol.Http or AppProtocol.HttpProxy => (HttpDetails) ge.Details as T, - _ => new EmptyDetails() as T - }; - } - - - if (details == null) return null; - - return new() - { - Id = ge.Id, - Timestamp = ge.Timestamp, - Transport = ge.Transport, - SourceIp = ge.SourceIp, - SourcePort = ge.SourcePort, - DestinationIp = ge.DestinationIp, - DestinationPort = ge.DestinationPort, - TlsDetails = ge.TlsDetails, - Application = ge.Application, - Details = details - }; - } + Id = entity.Id; + Timestamp = entity.Timestamp.ToDateTimeOffset(); + Transport = entity.Transport; + SourceIp = new IPAddress(entity.SourceIp.Span); + SourcePort = Convert.ToUInt16(entity.SourcePort); + DestinationIp = new IPAddress(entity.DestinationIp.Span); + DestinationPort = Convert.ToUInt16(entity.DestinationPort); + TlsDetails = entity.Tls; + Application = entity.Application; } + + public long Id { get; init; } + public DateTimeOffset Timestamp { get; init; } + public TransportProtocol Transport { get; init; } + public AppProtocol Application { get; init; } + public IPAddress SourceIp { get; init; } = IPAddress.Any; + public IPAddress DestinationIp { get; init; } = IPAddress.Any; + public ushort SourcePort { get; init; } + public ushort DestinationPort { get; init; } + public TLSDetailsEntity TlsDetails { get; init; } = new(); +} + +public record Event : EventBase +{ + public Event(EventEntity entity) : base(entity) + { + Details = entity.ProtocolDetailsCase switch + { + EventEntity.ProtocolDetailsOneofCase.Http => new HttpDetails(entity.Http), + EventEntity.ProtocolDetailsOneofCase.Dns => new DnsDetails(entity.Dns), + EventEntity.ProtocolDetailsOneofCase.Dhcp => new DhcpDetails(entity.Dhcp), + _ => null + }; + } + + public object? Details { get; init; } + + public T? DetailsAs() where T : EventDetails => Details as T; +} + +public record Event : EventBase where T : EventDetails, new() +{ + public Event(EventEntity entity) : base(entity) + { + Details = entity.ProtocolDetailsCase switch + { + EventEntity.ProtocolDetailsOneofCase.Http => new HttpDetails(entity.Http) as T, + EventEntity.ProtocolDetailsOneofCase.Dns => new DnsDetails(entity.Dns) as T, + EventEntity.ProtocolDetailsOneofCase.Dhcp => new DhcpDetails(entity.Dhcp) as T, + _ => null + }; + } + + private Event(Event raw) : base(raw) + { + Details = raw.Details as T; + } + + public T? Details { get; init; } + + public static explicit operator Event(Event raw) => new(raw); } diff --git a/src/INetMock.Client/Audit/IAuditApiClient.cs b/src/INetMock.Client/Audit/IAuditApiClient.cs index 45baca9..9aa0f55 100644 --- a/src/INetMock.Client/Audit/IAuditApiClient.cs +++ b/src/INetMock.Client/Audit/IAuditApiClient.cs @@ -2,13 +2,12 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -namespace INetMock.Client.Audit +namespace INetMock.Client.Audit; + +public interface IAuditApiClient { - public interface IAuditApiClient - { - IProtoEventReader EventStreamAsync(string watcherName, CancellationToken token = default); - Task> ListSinksAsync(CancellationToken token = default); - Task RegisterFileSinkAsync(string targetPath, CancellationToken token = default); - Task RemoveFileSinkAsync(string targetPath, CancellationToken token = default); - } + IProtoEventReader EventStreamAsync(string watcherName, CancellationToken token = default); + Task> ListSinksAsync(CancellationToken token = default); + Task RegisterFileSinkAsync(string targetPath, CancellationToken token = default); + Task RemoveFileSinkAsync(string targetPath, CancellationToken token = default); } diff --git a/src/INetMock.Client/Audit/IEventReader.cs b/src/INetMock.Client/Audit/IEventReader.cs index 9702237..1e347f3 100644 --- a/src/INetMock.Client/Audit/IEventReader.cs +++ b/src/INetMock.Client/Audit/IEventReader.cs @@ -3,20 +3,34 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -namespace INetMock.Client.Audit -{ - public interface IEventReader : IDisposable, IAsyncDisposable where T : EventDetails, new() - { - IAsyncEnumerable> ReadAllAsync(CancellationToken token = default); +namespace INetMock.Client.Audit; - /// - /// - /// - /// - /// - /// An event as long as underlying stream has data. - /// When the end of the stream has been reached it will return null. - /// - Task?> ReadAsync(CancellationToken token = default); - } +public interface IEventReader : IDisposable, IAsyncDisposable +{ + IAsyncEnumerable ReadAllAsync(CancellationToken token = default); + + /// + /// + /// + /// + /// + /// An event as long as underlying stream has data. + /// When the end of the stream has been reached it will return null. + /// + Task ReadAsync(CancellationToken token = default); +} + +public interface IEventReader : IDisposable, IAsyncDisposable where T : EventDetails, new() +{ + IAsyncEnumerable> ReadAllAsync(CancellationToken token = default); + + /// + /// + /// + /// + /// + /// An event as long as underlying stream has data. + /// When the end of the stream has been reached it will return null. + /// + Task?> ReadAsync(CancellationToken token = default); } diff --git a/src/INetMock.Client/Audit/INetMockHttpHeaders.cs b/src/INetMock.Client/Audit/INetMockHttpHeaders.cs index 968723e..23fe9b4 100644 --- a/src/INetMock.Client/Audit/INetMockHttpHeaders.cs +++ b/src/INetMock.Client/Audit/INetMockHttpHeaders.cs @@ -1,17 +1,20 @@ using System.Net.Http.Headers; using Google.Protobuf.Collections; -namespace INetMock.Client.Audit +namespace INetMock.Client.Audit; + +internal class INetMockHttpHeaders : HttpHeaders { - internal class INetMockHttpHeaders : HttpHeaders + internal INetMockHttpHeaders(MapField headers) { - internal INetMockHttpHeaders(MapField headers) + foreach (var (key, values) in headers) { - foreach (var (key, values) in headers) + if (string.IsNullOrEmpty(key) || values == null) { - if (string.IsNullOrEmpty(key) || values == null) continue; - Add(key, values.Values); + continue; } + + Add(key, values.Values); } } } diff --git a/src/INetMock.Client/Audit/IProtoEventReader.cs b/src/INetMock.Client/Audit/IProtoEventReader.cs index 01e434e..93d0cd9 100644 --- a/src/INetMock.Client/Audit/IProtoEventReader.cs +++ b/src/INetMock.Client/Audit/IProtoEventReader.cs @@ -1,11 +1,11 @@ using System; using System.Threading; using System.Threading.Tasks; +using Inetmock.Audit.V1; -namespace INetMock.Client.Audit +namespace INetMock.Client.Audit; + +public interface IProtoEventReader : IDisposable, IAsyncDisposable { - public interface IProtoEventReader : IDisposable, IAsyncDisposable - { - Task ReadAsync(CancellationToken token = default); - } + Task ReadAsync(CancellationToken token = default); } diff --git a/src/INetMock.Client/Audit/Serialization/EventServerStreamReader.cs b/src/INetMock.Client/Audit/Serialization/EventServerStreamReader.cs index e549ed2..42ef109 100644 --- a/src/INetMock.Client/Audit/Serialization/EventServerStreamReader.cs +++ b/src/INetMock.Client/Audit/Serialization/EventServerStreamReader.cs @@ -1,31 +1,33 @@ using System.Threading; using System.Threading.Tasks; using Grpc.Core; -using INetMock.Client.Rpc; -namespace INetMock.Client.Audit.Serialization +namespace INetMock.Client.Audit.Serialization; + +public sealed class EventServerStreamReader : IProtoEventReader { - public sealed class EventServerStreamReader : IProtoEventReader + private readonly AsyncServerStreamingCall _asyncEventStream; + + public EventServerStreamReader(AsyncServerStreamingCall asyncEventStream) { - private readonly AsyncServerStreamingCall _asyncEventStream; + _asyncEventStream = asyncEventStream; + } - public EventServerStreamReader(AsyncServerStreamingCall asyncEventStream) + public async Task ReadAsync(CancellationToken token = default) + { + if (!await _asyncEventStream.ResponseStream.MoveNext(token)) { - _asyncEventStream = asyncEventStream; + return null; } - public async Task ReadAsync(CancellationToken token = default) - { - if (!await _asyncEventStream.ResponseStream.MoveNext(token)) return null; - return _asyncEventStream.ResponseStream.Current.Entity; - } + return _asyncEventStream.ResponseStream.Current.Entity; + } - public void Dispose() => _asyncEventStream.Dispose(); + public void Dispose() => _asyncEventStream.Dispose(); - public ValueTask DisposeAsync() - { - _asyncEventStream.Dispose(); - return ValueTask.CompletedTask; - } + public ValueTask DisposeAsync() + { + _asyncEventStream.Dispose(); + return ValueTask.CompletedTask; } } diff --git a/src/INetMock.Client/Audit/Serialization/GenericReader.cs b/src/INetMock.Client/Audit/Serialization/GenericReader.cs index b175aec..9682a61 100644 --- a/src/INetMock.Client/Audit/Serialization/GenericReader.cs +++ b/src/INetMock.Client/Audit/Serialization/GenericReader.cs @@ -3,44 +3,42 @@ using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -namespace INetMock.Client.Audit.Serialization +namespace INetMock.Client.Audit.Serialization; + +public sealed class GenericReader : IEventReader { - public sealed class GenericReader : IEventReader + private readonly IProtoEventReader _reader; + + public GenericReader(IProtoEventReader reader) { - private readonly IProtoEventReader _reader; + _reader = reader; + } - public GenericReader(IProtoEventReader reader) + public async IAsyncEnumerable ReadAllAsync( + [EnumeratorCancellation] CancellationToken token = default) + { + while (true) { - _reader = reader; - } - - public async IAsyncEnumerable> ReadAllAsync( - [EnumeratorCancellation] CancellationToken token = default) - { - while (true) + var ev = await ReadAsync(token); + if (ev == null) { - var ev = await ReadAsync(token); - if (ev == null) - { - yield break; - } - - yield return ev; + yield break; } - } - public async Task?> ReadAsync(CancellationToken token = default) - { - var entity = await _reader.ReadAsync(token); - if (entity == null) return null; - return new Event(entity); - } - - public ValueTask DisposeAsync() => _reader.DisposeAsync(); - - public void Dispose() - { - _reader.Dispose(); + yield return ev; } } + + public async Task ReadAsync(CancellationToken token = default) + { + var entity = await _reader.ReadAsync(token); + return entity == null ? null : new Event(entity); + } + + public ValueTask DisposeAsync() => _reader.DisposeAsync(); + + public void Dispose() + { + _reader.Dispose(); + } } diff --git a/src/INetMock.Client/Audit/Serialization/ProtoReader.cs b/src/INetMock.Client/Audit/Serialization/ProtoReader.cs index bc0180c..c6728cf 100644 --- a/src/INetMock.Client/Audit/Serialization/ProtoReader.cs +++ b/src/INetMock.Client/Audit/Serialization/ProtoReader.cs @@ -5,64 +5,63 @@ using System.Threading; using System.Threading.Tasks; using Google.Protobuf; -namespace INetMock.Client.Audit.Serialization +namespace INetMock.Client.Audit.Serialization; + +public sealed class ProtoReader : IProtoEventReader { - public sealed class ProtoReader : IProtoEventReader + private readonly MemoryPool _memoryPool; + private readonly Stream _sourceStream; + private readonly bool _keepStreamOpen; + + public ProtoReader(Stream sourceStream, bool keepStreamOpen = false) { - private readonly MemoryPool _memoryPool; - private readonly Stream _sourceStream; - private readonly bool _keepStreamOpen; + _memoryPool = MemoryPool.Shared; + _sourceStream = sourceStream; + _keepStreamOpen = keepStreamOpen; + } - public ProtoReader(Stream sourceStream, bool keepStreamOpen = false) + public async Task ReadAsync(CancellationToken token = default) + { + using var rentedLengthMem = _memoryPool.Rent(4); + var lengthMem = rentedLengthMem.Memory.Slice(0, 4); + var read = await _sourceStream.ReadAsync(lengthMem, token); + if (read != 4) { - _memoryPool = MemoryPool.Shared; - _sourceStream = sourceStream; - _keepStreamOpen = keepStreamOpen; + return null; } - public async Task ReadAsync(CancellationToken token = default) + var messageLength = BinaryPrimitives.ReadInt32BigEndian(lengthMem.Span); + using var rentedMsgMem = _memoryPool.Rent(messageLength); + var msgMem = rentedMsgMem.Memory.Slice(0, messageLength); + read = await _sourceStream.ReadAsync(msgMem, token); + if (read != messageLength) { - using var rentedLengthMem = _memoryPool.Rent(4); - var lengthMem = rentedLengthMem.Memory.Slice(0, 4); - var read = await _sourceStream.ReadAsync(lengthMem, token); - if (read != 4) - { - return null; - } - - var messageLength = BinaryPrimitives.ReadInt32BigEndian(lengthMem.Span); - using var rentedMsgMem = _memoryPool.Rent(messageLength); - var msgMem = rentedMsgMem.Memory.Slice(0, messageLength); - read = await _sourceStream.ReadAsync(msgMem, token); - if (read != messageLength) - { - return null; - } - - var entity = new EventEntity(); - entity.MergeFrom(msgMem.ToArray()); - - return entity; + return null; } - public async ValueTask DisposeAsync() - { - if (!_keepStreamOpen) - { - await _sourceStream.DisposeAsync(); - } + var entity = new EventEntity(); + entity.MergeFrom(msgMem.ToArray()); - _memoryPool.Dispose(); + return entity; + } + + public async ValueTask DisposeAsync() + { + if (!_keepStreamOpen) + { + await _sourceStream.DisposeAsync(); } - public void Dispose() - { - if (!_keepStreamOpen) - { - _sourceStream?.Dispose(); - } + _memoryPool.Dispose(); + } - _memoryPool?.Dispose(); + public void Dispose() + { + if (!_keepStreamOpen) + { + _sourceStream?.Dispose(); } + + _memoryPool?.Dispose(); } } diff --git a/src/INetMock.Client/Audit/Serialization/TypedReader.cs b/src/INetMock.Client/Audit/Serialization/TypedReader.cs index 6ed486c..4c0127f 100644 --- a/src/INetMock.Client/Audit/Serialization/TypedReader.cs +++ b/src/INetMock.Client/Audit/Serialization/TypedReader.cs @@ -3,77 +3,80 @@ using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -namespace INetMock.Client.Audit.Serialization +namespace INetMock.Client.Audit.Serialization; + +/// +/// Configures how the TypedReader proceeds with mismatching entities. +/// Given a TypedReader<HttpDetails> it can't guarantee that every Event<T> contains a HttpDetails entity. +/// Therefore different dropping strategies can be configured. +/// +public enum DropMode { /// - /// Configures how the TypedReader proceeds with mismatching entities. - /// Given a TypedReader<HttpDetails> it can't guarantee that every Event<T> contains a HttpDetails entity. - /// Therefore different dropping strategies can be configured. + /// Drops the whole entity. + /// This filters the actual stream for entities supporting the details in question. /// - public enum DropMode - { - /// - /// Drops the whole entity. - /// This filters the actual stream for entities supporting the details in question. - /// - DropEntity, + DropEntity, - /// - /// Drops only the mismatching details but keeps the event - /// e.g. a TypedReader<HttpDetails> would still contain DNS events but no details about them - /// - DropDetails - } - - public sealed class TypedReader : IEventReader where T : EventDetails, new() - { - private readonly IProtoEventReader _reader; - private readonly DropMode _dropMode; - - public TypedReader(IProtoEventReader reader, DropMode dropMode = DropMode.DropDetails) - { - _reader = reader; - _dropMode = dropMode; - } - - public async IAsyncEnumerable> ReadAllAsync([EnumeratorCancellation] CancellationToken token = default) - { - while (true) - { - var ev = await ReadAsync(token); - if (ev == null) - { - yield break; - } - - yield return ev; - } - } - - public async Task?> ReadAsync(CancellationToken token = default) - { - do - { - var entity = await _reader.ReadAsync(token); - if (entity == null) return null; - var parsed = new Event(entity); - - var canReturn = (_dropMode, parsed.Details) switch - { - (DropMode.DropDetails, null) => true, - (DropMode.DropEntity, null) => false, - (_, _) => true - }; - - if (canReturn) - { - return parsed; - } - } while (true); - } - - public void Dispose() => _reader.Dispose(); - - public ValueTask DisposeAsync() => _reader.DisposeAsync(); - } + /// + /// Drops only the mismatching details but keeps the event + /// e.g. a TypedReader<HttpDetails> would still contain DNS events but no details about them + /// + DropDetails +} + +public sealed class TypedReader : IEventReader where T : EventDetails, new() +{ + private readonly IProtoEventReader _reader; + private readonly DropMode _dropMode; + + public TypedReader(IProtoEventReader reader, DropMode dropMode = DropMode.DropDetails) + { + _reader = reader; + _dropMode = dropMode; + } + + public async IAsyncEnumerable> ReadAllAsync([EnumeratorCancellation] CancellationToken token = default) + { + while (true) + { + var ev = await ReadAsync(token); + if (ev == null) + { + yield break; + } + + yield return ev; + } + } + + public async Task?> ReadAsync(CancellationToken token = default) + { + do + { + var entity = await _reader.ReadAsync(token); + if (entity == null) + { + return null; + } + + var parsed = new Event(entity); + + var canReturn = (_dropMode, parsed.Details) switch + { + (DropMode.DropDetails, null) => true, + (DropMode.DropEntity, null) => false, + (_, _) => true + }; + + if (canReturn) + { + return parsed; + } + } while (true); + } + + public void Dispose() => _reader.Dispose(); + + public ValueTask DisposeAsync() => _reader.DisposeAsync(); } diff --git a/src/INetMock.Client/Grpc/ChannelFactory.cs b/src/INetMock.Client/Grpc/ChannelFactory.cs index c8cb588..b96bea2 100644 --- a/src/INetMock.Client/Grpc/ChannelFactory.cs +++ b/src/INetMock.Client/Grpc/ChannelFactory.cs @@ -3,38 +3,37 @@ using System.Net.Http; using System.Net.Sockets; using Grpc.Net.Client; -namespace INetMock.Client.Grpc +namespace INetMock.Client.Grpc; + +internal static class ChannelFactory { - internal static class ChannelFactory - { - internal static GrpcChannel ForAddress(Uri uri, GrpcChannelOptions options) => - uri.Scheme.ToLowerInvariant() switch - { - "unix" => ForUnixSocket(uri.AbsolutePath, options), - _ => GrpcChannel.ForAddress(uri, options) - }; - - private static GrpcChannel ForUnixSocket(string path, GrpcChannelOptions options) + internal static GrpcChannel ForAddress(Uri uri, GrpcChannelOptions options) => + uri.Scheme.ToLowerInvariant() switch { - var endpoint = new UnixDomainSocketEndPoint(path); - options.HttpHandler = new SocketsHttpHandler + "unix" => ForUnixSocket(uri.AbsolutePath, options), + _ => GrpcChannel.ForAddress(uri, options) + }; + + private static GrpcChannel ForUnixSocket(string path, GrpcChannelOptions options) + { + var endpoint = new UnixDomainSocketEndPoint(path); + options.HttpHandler = new SocketsHttpHandler + { + ConnectCallback = async (_, cancellationToken) => { - ConnectCallback = async (_, cancellationToken) => + var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); + try { - var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); - try - { - await socket.ConnectAsync(endpoint, cancellationToken).ConfigureAwait(false); - return new NetworkStream(socket, true); - } - catch - { - socket.Dispose(); - throw; - } + await socket.ConnectAsync(endpoint, cancellationToken).ConfigureAwait(false); + return new NetworkStream(socket, true); } - }; - return GrpcChannel.ForAddress("http://localhost", options); - } + catch + { + socket.Dispose(); + throw; + } + } + }; + return GrpcChannel.ForAddress("http://localhost", options); } } diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 3029a30..d90bc6d 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -1,24 +1,30 @@ - net5.0 + net6.0 enable latest - - - - + + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + + - + + diff --git a/src/INetMock.Client/PCAP/Client/PcapApiClient.cs b/src/INetMock.Client/PCAP/Client/PcapApiClient.cs index 4e4a00d..38f7344 100644 --- a/src/INetMock.Client/PCAP/Client/PcapApiClient.cs +++ b/src/INetMock.Client/PCAP/Client/PcapApiClient.cs @@ -7,82 +7,80 @@ using System.Threading.Tasks; using Google.Protobuf.WellKnownTypes; using Grpc.Core; using Grpc.Net.Client; -using INetMock.Client.Grpc; -using INetMock.Client.Rpc; +using ChannelFactory = INetMock.Client.Grpc.ChannelFactory; -namespace INetMock.Client.PCAP.Client +namespace INetMock.Client.PCAP.Client; + +public class PcapApiClient : IPcapApiClient { - public class PcapApiClient : IPcapApiClient + private readonly PCAPService.PCAPServiceClient _pcapServiceClient; + + public PcapApiClient(string address, GrpcChannelOptions? options = null) + : this(new Uri(address), options) { - private readonly PCAPService.PCAPServiceClient _pcapServiceClient; + } - public PcapApiClient(string address, GrpcChannelOptions? options = null) - : this(new Uri(address), options) - { - } + public PcapApiClient(Uri address, GrpcChannelOptions? options = null) + : this(ChannelFactory.ForAddress(address, options ?? new GrpcChannelOptions())) + { + } - public PcapApiClient(Uri address, GrpcChannelOptions? options = null) - : this(ChannelFactory.ForAddress(address, options ?? new GrpcChannelOptions())) - { - } + public PcapApiClient(ChannelBase channel) + { + _pcapServiceClient = new PCAPService.PCAPServiceClient(channel); + } - public PcapApiClient(ChannelBase channel) - { - _pcapServiceClient = new PCAPService.PCAPServiceClient(channel); - } - - public async Task> ListAvailableDevicesAsync(CancellationToken token = default) - { - var devices = await _pcapServiceClient.ListAvailableDevicesAsync(new(), Metadata.Empty, null, token); - return devices.AvailableDevices - .Select(d => new RecordingDevice( - d.Name, - d.Addresses - .Select(addr => new IPAddress(addr.Span)) - .ToList() - ) + public async Task> ListAvailableDevicesAsync(CancellationToken token = default) + { + var devices = await _pcapServiceClient.ListAvailableDevicesAsync(new(), Metadata.Empty, null, token); + return devices.AvailableDevices + .Select(d => new RecordingDevice( + d.Name, + d.Addresses + .Select(addr => new IPAddress(addr.Span)) + .ToList() ) - .ToList(); - } + ) + .ToList(); + } - public async Task> ListActiveRecordingsAsync(CancellationToken token = default) + public async Task> ListActiveRecordingsAsync(CancellationToken token = default) + { + var recordings = await _pcapServiceClient.ListActiveRecordingsAsync(new(), Metadata.Empty, null, token); + return recordings.Subscriptions + .Select(consumerKey => new Subscription(consumerKey)) + .ToList(); + } + + public async Task StartPcapFileRecordingAsync(RecordingRequest request, + CancellationToken token = default) + { + var clientRequest = new StartPCAPFileRecordingRequest { - var recordings = await _pcapServiceClient.ListActiveRecordingsAsync(new(), Metadata.Empty, null, token); - return recordings.Subscriptions - .Select(consumerKey => new Subscription(consumerKey)) - .ToList(); - } + Device = request.Device, + Promiscuous = request.Promiscuous, + TargetPath = request.TargetPath, + ReadTimeout = Duration.FromTimeSpan(request.ReadTimeout) + }; - public async Task StartPcapFileRecordingAsync(RecordingRequest request, - CancellationToken token = default) - { - var clientRequest = new StartPCAPFileRecordingRequest - { - Device = request.Device, - Promiscuous = request.Promiscuous, - TargetPath = request.TargetPath, - ReadTimeout = Duration.FromTimeSpan(request.ReadTimeout) - }; + var result = await _pcapServiceClient.StartPCAPFileRecordingAsync( + clientRequest, + Metadata.Empty, + null, + token); - var result = await _pcapServiceClient.StartPCAPFileRecordingAsync( - clientRequest, - Metadata.Empty, - null, - token); + return result.ResolvedPath; + } - return result.ResolvedPath; - } - - public async Task StopPcapFileRecording(string consumerKey, CancellationToken token = default) - { - var clientRequest = new StopPCAPFileRecordingRequest {ConsumerKey = consumerKey}; - var result = await _pcapServiceClient.StopPCAPFileRecordingAsync( - clientRequest, - Metadata.Empty, - null, - token - ); - return result.Removed; - } + public async Task StopPcapFileRecordingAsync(string consumerKey, CancellationToken token = default) + { + var clientRequest = new StopPCAPFileRecordingRequest { ConsumerKey = consumerKey }; + var result = await _pcapServiceClient.StopPCAPFileRecordingAsync( + clientRequest, + Metadata.Empty, + null, + token + ); + return result.Removed; } } diff --git a/src/INetMock.Client/PCAP/IPcapApiClient.cs b/src/INetMock.Client/PCAP/IPcapApiClient.cs index c5d5b25..42a5cf7 100644 --- a/src/INetMock.Client/PCAP/IPcapApiClient.cs +++ b/src/INetMock.Client/PCAP/IPcapApiClient.cs @@ -2,12 +2,12 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -namespace INetMock.Client.PCAP +namespace INetMock.Client.PCAP; + +public interface IPcapApiClient { - public interface IPcapApiClient - { - Task> ListAvailableDevicesAsync(CancellationToken token = default); - Task> ListActiveRecordingsAsync(CancellationToken token = default); - Task StartPcapFileRecordingAsync(RecordingRequest request, CancellationToken token = default); - } + Task> ListAvailableDevicesAsync(CancellationToken token = default); + Task> ListActiveRecordingsAsync(CancellationToken token = default); + Task StartPcapFileRecordingAsync(RecordingRequest request, CancellationToken token = default); + Task StopPcapFileRecordingAsync(string consumerKey, CancellationToken token = default); } diff --git a/src/INetMock.Client/PCAP/Models.cs b/src/INetMock.Client/PCAP/Models.cs index 2642158..2efed64 100644 --- a/src/INetMock.Client/PCAP/Models.cs +++ b/src/INetMock.Client/PCAP/Models.cs @@ -2,52 +2,51 @@ using System; using System.Collections.Generic; using System.Net; -namespace INetMock.Client.PCAP +namespace INetMock.Client.PCAP; + +public record RecordingDevice(string Name, IReadOnlyList Addresses); + +public record Subscription { - public record RecordingDevice(string Name, IReadOnlyList Addresses); - - public record Subscription + public Subscription(string consumerKey) { - public Subscription(string consumerKey) - { - ConsumerKey = consumerKey; - (ConsumerName, Device) = SplitConsumerKey(consumerKey); - } - - public Subscription(string consumerKey, string consumerName, string device) - { - ConsumerKey = consumerKey; - ConsumerName = consumerName; - Device = device; - } - - public string ConsumerKey { get; init; } - public string ConsumerName { get; init; } - public string Device { get; init; } - - private static (string name, string key) SplitConsumerKey(string consumerKey) - { - var splitIndex = consumerKey.IndexOf(':'); - if (splitIndex < 0) - { - throw new ArgumentOutOfRangeException( - nameof(consumerKey), - "The given consumer key could not be split into components" - ); - } - - return (consumerKey[(splitIndex + 1)..], consumerKey[..splitIndex]); - } + ConsumerKey = consumerKey; + (ConsumerName, Device) = SplitConsumerKey(consumerKey); } - public record RecordingRequest(string Device, string TargetPath, bool Promiscuous = false) + public Subscription(string consumerKey, string consumerName, string device) { - public RecordingRequest(string device, string targetPath, bool promiscuous, TimeSpan readTimeout) : this(device, - targetPath, promiscuous) + ConsumerKey = consumerKey; + ConsumerName = consumerName; + Device = device; + } + + public string ConsumerKey { get; init; } + public string ConsumerName { get; init; } + public string Device { get; init; } + + private static (string name, string key) SplitConsumerKey(string consumerKey) + { + var splitIndex = consumerKey.IndexOf(':'); + if (splitIndex < 0) { - ReadTimeout = readTimeout; + throw new ArgumentOutOfRangeException( + nameof(consumerKey), + "The given consumer key could not be split into components" + ); } - public TimeSpan ReadTimeout { get; } = TimeSpan.FromSeconds(30); + return (consumerKey[(splitIndex + 1)..], consumerKey[..splitIndex]); } } + +public record RecordingRequest(string Device, string TargetPath, bool Promiscuous = false) +{ + public RecordingRequest(string device, string targetPath, bool promiscuous, TimeSpan readTimeout) : this(device, + targetPath, promiscuous) + { + ReadTimeout = readTimeout; + } + + public TimeSpan ReadTimeout { get; } = TimeSpan.FromSeconds(30); +} diff --git a/tests/INetMock.Client.IntegrationTest/Audit/Serialization/GenericReaderTest.cs b/tests/INetMock.Client.IntegrationTest/Audit/Serialization/GenericReaderTest.cs new file mode 100644 index 0000000..1fc5cca --- /dev/null +++ b/tests/INetMock.Client.IntegrationTest/Audit/Serialization/GenericReaderTest.cs @@ -0,0 +1,26 @@ +using System.IO; +using System.Threading.Tasks; +using INetMock.Client.Audit; +using INetMock.Client.Audit.Serialization; +using Xunit; + +namespace INetMock.Client.IntegrationTest.Audit.Serialization; + +public class GenericReaderTest +{ + [Fact] + public async Task Test_ReadAllAsync_AuditFile() + { + await using var auditFileStream = File.OpenRead(Path.Join("testdata", "test.ima")); + await using IEventReader reader = new GenericReader(new ProtoReader(auditFileStream)); + + var count = 0; + await foreach (var ev in reader.ReadAllAsync()) + { + Assert.NotNull(ev); + count++; + } + + Assert.True(count > 0); + } +} diff --git a/tests/INetMock.Client.IntegrationTest/Audit/Serialization/TypedReaderTest.cs b/tests/INetMock.Client.IntegrationTest/Audit/Serialization/TypedReaderTest.cs new file mode 100644 index 0000000..274bbc9 --- /dev/null +++ b/tests/INetMock.Client.IntegrationTest/Audit/Serialization/TypedReaderTest.cs @@ -0,0 +1,71 @@ +using System.IO; +using System.Threading.Tasks; +using INetMock.Client.Audit; +using INetMock.Client.Audit.Serialization; +using Xunit; + +namespace INetMock.Client.IntegrationTest.Audit.Serialization; + +public class TypedReaderTest +{ + [Fact] + public async Task Test_ReadAllAsync_DropDetails_AuditFile_HTTPEvents() + { + await using var fileStream = File.OpenRead(Path.Join("testdata", "test.ima")); + await using IEventReader httpReader = new TypedReader(new ProtoReader(fileStream)); + + var count = 0; + await foreach (var ev in httpReader.ReadAllAsync()) + { + Assert.NotNull(ev); + count++; + } + Assert.True(count > 0); + } + + [Fact] + public async Task Test_ReadAllAsync_DropEntity_AuditFile_HTTPEvents() + { + await using var fileStream = File.OpenRead(Path.Join("testdata", "test.ima")); + await using IEventReader httpReader = new TypedReader(new ProtoReader(fileStream), DropMode.DropEntity); + + var count = 0; + await foreach (var ev in httpReader.ReadAllAsync()) + { + Assert.NotNull(ev); + Assert.NotNull(ev.Details); + count++; + } + Assert.True(count > 0); + } + + [Fact] + public async Task Test_ReadAllAsync_DropDetails_AuditFile_DNSEvents() + { + await using var fileStream = File.OpenRead(Path.Join("testdata", "test.ima")); + await using IEventReader httpReader = new TypedReader(new ProtoReader(fileStream)); + + var count = 0; + await foreach (var ev in httpReader.ReadAllAsync()) + { + Assert.NotNull(ev); + count++; + } + Assert.True(count > 0); + } + + [Fact] + public async Task Test_ReadAllAsync_DropEntity_AuditFile_DNSEvents() + { + await using var fileStream = File.OpenRead(Path.Join("testdata", "test.ima")); + await using IEventReader httpReader = new TypedReader(new ProtoReader(fileStream), DropMode.DropEntity); + + var count = 0; + await foreach (var ev in httpReader.ReadAllAsync()) + { + Assert.NotNull(ev); + count++; + } + Assert.True(count > 0); + } +} diff --git a/tests/INetMock.Client.IntegrationTest/DockerEndpoint.cs b/tests/INetMock.Client.IntegrationTest/DockerEndpoint.cs deleted file mode 100644 index 1649166..0000000 --- a/tests/INetMock.Client.IntegrationTest/DockerEndpoint.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Globalization; -using System.Runtime.InteropServices; - -namespace INetMock.Client.IntegrationTest -{ - internal static class DockerEndpoint - { - private const string DockerHostEnvName = "DOCKER_HOST"; - private const string DockerTlsVerifyEnvName = "DOCKER_TLS_VERIFY"; - - internal static string DetermineFromEnv() => DetermineEndpoint( - Environment.GetEnvironmentVariable(DockerHostEnvName), - Environment.GetEnvironmentVariable(DockerTlsVerifyEnvName) - ); - - internal static string DetermineEndpoint(string? dockerHost, string? tlsVerify) - { - dockerHost ??= ""; - var dockerTlsVerify = int.TryParse(tlsVerify, out var verify) && verify == 1; - var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - return (dockerHost, dockerTlsVerify, isWindows) switch - { - ("", _, true) => "npipe://./pipe/docker_engine", - ("", _, false) => "unix:/var/run/docker.sock", - (_, false, _) => dockerHost, - (var h, true, _) when h.StartsWith("tcp") => h.Replace( - "tcp", - "https", - true, - CultureInfo.InvariantCulture), - _ => "", - }; - } - } -} diff --git a/tests/INetMock.Client.IntegrationTest/DockerEndpointTests.cs b/tests/INetMock.Client.IntegrationTest/DockerEndpointTests.cs deleted file mode 100644 index b006fcc..0000000 --- a/tests/INetMock.Client.IntegrationTest/DockerEndpointTests.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Xunit; - -namespace INetMock.Client.IntegrationTest -{ - public class DockerEndpointTests - { - [Theory] - [InlineData(null, null, "unix:/var/run/docker.sock")] - [InlineData("tcp://docker:2375", null, "tcp://docker:2375")] - [InlineData("tcp://docker:2375", "0", "tcp://docker:2375")] - [InlineData("http://docker:2375", null, "http://docker:2375")] - [InlineData("http://docker:2375", "0", "http://docker:2375")] - [InlineData("tcp://docker:2376", "1", "https://docker:2376")] - [InlineData("https://docker:2376", "0", "https://docker:2376")] - public void DetermineDockerEndpoint_Input_ExpectedOutput(string? dockerHost, string? tlsVerify, string expected) - { - var actual = DockerEndpoint.DetermineEndpoint(dockerHost, tlsVerify); - - Assert.Equal(expected, actual); - } - } -} diff --git a/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj b/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj index 0961e02..99b230e 100644 --- a/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj +++ b/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj @@ -1,22 +1,23 @@ - net5.0 + net6.0 false enable + + 10 - - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -26,4 +27,10 @@ + + + PreserveNewest + + + diff --git a/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs b/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs new file mode 100644 index 0000000..f4c6120 --- /dev/null +++ b/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs @@ -0,0 +1,19 @@ +using System; + +namespace INetMock.Client.IntegrationTest; + +public class INetMockFixture +{ + private const string DefaultINetMockSocketPath = "unix:///var/run/inetmock/inetmock.sock"; + + public INetMockFixture() + { + INetMockSocketPath = Environment.GetEnvironmentVariable("INETMOCK_SOCKET") ?? DefaultINetMockSocketPath; + if (INetMockSocketPath.StartsWith("http:")) + { + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); + } + } + + public string INetMockSocketPath { get; } +} diff --git a/tests/INetMock.Client.IntegrationTest/INetMockServerFixture.cs b/tests/INetMock.Client.IntegrationTest/INetMockServerFixture.cs deleted file mode 100644 index f8cb433..0000000 --- a/tests/INetMock.Client.IntegrationTest/INetMockServerFixture.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.IO; -using System.Threading.Tasks; -using DotNet.Testcontainers.Containers.Builders; -using DotNet.Testcontainers.Containers.Modules; -using DotNet.Testcontainers.Containers.WaitStrategies; -using Xunit; - -namespace INetMock.Client.IntegrationTest -{ - public class INetMockServerFixture : IAsyncLifetime - { - - private readonly TestcontainersContainer _inetmockContainer; - - public INetMockServerFixture() - { - _inetmockContainer = new TestcontainersBuilder() - .WithImage("inetmock-root:latest") - .WithCommand("serve") - .WithPortBinding(80, true) - .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(80)) - .WithDockerEndpoint(DockerEndpoint.DetermineFromEnv()) - .WithMount(Path.GetTempPath(), "/var/run/inetmock") - .WithCleanUp(true) - .Build(); - } - - public Uri SocketPath => new($"unix://{Path.Join(Path.GetTempPath(), "inetmock.sock")}", UriKind.Absolute); - - public async Task InitializeAsync() - { - await _inetmockContainer.StartAsync(); - } - - public async Task DisposeAsync() - { - await _inetmockContainer.StopAsync(); - await _inetmockContainer.DisposeAsync(); - } - } -} diff --git a/tests/INetMock.Client.IntegrationTest/PCAP/Client/PcapApiClientTests.cs b/tests/INetMock.Client.IntegrationTest/PCAP/Client/PcapApiClientTests.cs index 0d291dc..bf135d1 100644 --- a/tests/INetMock.Client.IntegrationTest/PCAP/Client/PcapApiClientTests.cs +++ b/tests/INetMock.Client.IntegrationTest/PCAP/Client/PcapApiClientTests.cs @@ -1,45 +1,63 @@ +using System.Linq; using INetMock.Client.PCAP; using INetMock.Client.PCAP.Client; using Xunit; using Xunit.Abstractions; -namespace INetMock.Client.IntegrationTest.PCAP.Client +namespace INetMock.Client.IntegrationTest.PCAP.Client; + +public class PcapApiClientTests : IClassFixture { - public class PcapApiClientTests : IClassFixture + private readonly ITestOutputHelper _outputHelper; + private readonly IPcapApiClient _apiClient; + + public PcapApiClientTests(ITestOutputHelper testOutputHelper, INetMockFixture inetMockFixture) { - private readonly ITestOutputHelper _outputHelper; - private readonly IPcapApiClient _apiClient; + _outputHelper = testOutputHelper; + _apiClient = new PcapApiClient(inetMockFixture.INetMockSocketPath); + } - public PcapApiClientTests(ITestOutputHelper testOutputHelper, INetMockServerFixture inetmockFixture) + [Fact] + public async void ListAvailableDevicesAsync_RunningContainer_AtLeastLoopbackDevice() + { + var devs = await _apiClient.ListAvailableDevicesAsync(); + + foreach (var (name, _) in devs) { - _outputHelper = testOutputHelper; - _apiClient = new PcapApiClient(inetmockFixture.SocketPath); + _outputHelper.WriteLine(name); } - [Fact] - public async void ListAvailableDevicesAsync_RunningContainer_AtLeastLoopbackDevice() + Assert.Contains(devs, device => device.Name.Equals("lo")); + } + + [Fact] + public async void ListActiveRecordingsAsync_NoRecordingsRunning_EmptyResult() + { + var recordings = await _apiClient.ListActiveRecordingsAsync(); + + Assert.Empty(recordings); + } + + [Fact] + public async void StartPcapFileRecordingAsync_RecordLoopbackInterface_RunningRecording() + { + var recordingDevice = (await _apiClient.ListAvailableDevicesAsync()).FirstOrDefault(); + if (recordingDevice == null) { - var devs = await _apiClient.ListAvailableDevicesAsync(); - - Assert.Contains(devs, device => device.Name.Equals("lo")); + return; } - [Fact] - public async void ListActiveRecordingsAsync_NoRecordingsRunning_EmptyResult() - { - var recordings = await _apiClient.ListActiveRecordingsAsync(); - - Assert.Empty(recordings); - } + var targetPath = $"/tmp/{recordingDevice.Name}_record.pcap"; + await _apiClient.StartPcapFileRecordingAsync(new(recordingDevice.Name, targetPath)); - [Fact] - public async void StartPcapFileRecordingAsync_RecordLoopbackInterface_RunningRecording() + var subscriptions = await _apiClient.ListActiveRecordingsAsync(); + Assert.Contains(subscriptions, subscription => + subscription.Device.Equals(recordingDevice.Name) && + subscription.ConsumerName.Equals(targetPath) + ); + foreach (var subscription in subscriptions) { - const string targetPath = "/tmp/lo_record.pcap"; - await _apiClient.StartPcapFileRecordingAsync(new("lo", targetPath)); - - var subscriptions = await _apiClient.ListActiveRecordingsAsync(); - Assert.Contains(subscriptions, subscription => subscription.Device.Equals("lo") && subscription.ConsumerName.Equals(targetPath)); + await _apiClient.StopPcapFileRecordingAsync(subscription.ConsumerKey); } } } diff --git a/tests/INetMock.Client.IntegrationTest/testdata/test.ima b/tests/INetMock.Client.IntegrationTest/testdata/test.ima new file mode 100644 index 0000000000000000000000000000000000000000..d1cb3f08e1e3572a34252dfba279add0d603d1d1 GIT binary patch literal 3946 zcmdT`ZAcSg9N%pw=ef!*HC-==-x}=ZZI*s?h-hLExV|>7yW4rW-L2c{vM>2ksFfKK zQDA)-Sr8Sn$|8FaNvIGEDM2VAFtP~!(uW|>p1V2QZt9-7g|z3>p1u6;_wxMyk4~p^ zp{*mWm+tp}opj;Z=t9?6Z)VPy(3=AV`Xa=fqg#G0E}qiq5L?tv_@naIKlByX(A!8p zo{J)Qj+f#+1Sg7|hb3syOMq`3LEGXWCSQJshv@7ws1SMhb^x(85C{+w%P_ngLEsb; zmt#o;uP?wOTsad)*n{r^2nCd%aZ>?SB504;#JD|_v`mIk$Y`K$^>x)k>lGXi>$MXv zM2&bJNrV?KSSW^(2uku%if9bl9*1*d<{~`KLMTjW3CBi+mj(whD$?C~sQPbQ^8do~ ztLKpdq-fLH0SHH;eB_a#V%Sh?LNoAuXI;I^QC06EZRM`&%7d=@8i#G){va}dpawjP zw3QJhV38)w$_ReT@g`PkDMo9Y&O=t9g1Hde>Y!=XCtIonT4Z>E!!xlA?j-Ls7h~9A zKPy=r94p9pE{0c&mIhh&S!fRrcGREeV_PakK?ZLvb*#Y24R{8ox7*BnF=J%k+2UjI zLTm@+^Lcohl6g^3pTx`h{S?On-Ded&?#1fS`C?AhLl33LAcP)m2vBP?<>LvS7MP<- zj!jwCV`3xgx7y31Bw0Ui(!4ufP7FhN1_;E-YZ1U3*w>Yw_j zW_2(&tDoljlOX#Pf-F>4ZA3|eyqQ-%o@7E}!C$M!f~;z|PEQ5X%oWa9g=`{Y*DnYd zvqmMw8nPcgkE&$hO8GH_v58ArApzf>t2k^=rPsset3?%x4f?>ZsU*w~LFfTfR1mg8 zBtx~hBhKQx!{ZxbaSC%c9SJEVRXxDm)mZ$j``w1AP?y zI;zU0bmg&SPo@`FKVOj|(CE=UJO6*_QA(yu51ktPC$YhwK0Ve8AN()); + Assert.Null(ev.DetailsAs()); + + var httpEvent = (Event)ev; + Assert.NotNull(httpEvent); + Assert.NotNull(httpEvent.Details); } + } - [Fact] - public async void TestRead_HttpEvent_Success() + [Fact] + public async void TestRead_DnsEvent_Success() + { + await using var memStream = new MemoryStream(_dnsEventPayloadBytes); + await using var protoReader = new ProtoReader(new MemoryStream(_dnsEventPayloadBytes)); + await using IEventReader reader = new GenericReader(protoReader); + await foreach (var ev in reader.ReadAllAsync()) { - await using var protoReader = new ProtoReader(new MemoryStream(_httpEventPayloadBytes)); - await using IEventReader reader = new GenericReader(protoReader); - await foreach (var ev in reader.ReadAllAsync()) - { - Assert.NotNull(ev); - - Assert.True(ev.CanConvert()); - Assert.False(ev.CanConvert()); - - var httpEvent = (Event?) ev; - var dnsEvent = (Event?) ev; + Assert.NotNull(ev); + Assert.NotNull(ev.Details); + Assert.NotNull(ev.DetailsAs()); - Assert.NotNull(httpEvent); - Assert.Null(dnsEvent); - } - } - - [Fact] - public async void TestRead_DnsEvent_Success() - { - await using var memStream = new MemoryStream(_dnsEventPayloadBytes); - await using var protoReader = new ProtoReader(new MemoryStream(_dnsEventPayloadBytes)); - await using IEventReader reader = new GenericReader(protoReader); - await foreach (var ev in reader.ReadAllAsync()) - { - Assert.NotNull(ev); - Assert.True(ev.CanConvert()); - var dnsEvent = (Event?) ev; - Assert.NotNull(dnsEvent); - } + var dnsEvent = (Event)ev; + Assert.NotNull(dnsEvent); + Assert.NotNull(dnsEvent.Details); } } } diff --git a/tests/INetMock.Client.Test/Audit/Serialization/TypedReaderTest.cs b/tests/INetMock.Client.Test/Audit/Serialization/TypedReaderTest.cs index 57b90f5..f638ff3 100644 --- a/tests/INetMock.Client.Test/Audit/Serialization/TypedReaderTest.cs +++ b/tests/INetMock.Client.Test/Audit/Serialization/TypedReaderTest.cs @@ -4,42 +4,41 @@ using INetMock.Client.Audit.Serialization; using INetMock.Client.Test.Hex; using Xunit; -namespace INetMock.Client.Test.Audit.Serialization +namespace INetMock.Client.Test.Audit.Serialization; + +public class TypedReaderTest { - public class TypedReaderTest + private const string HttpEventPayload = "000000e5120b088092b8c398feffffff01180120022a047f00000132047f00000138d8fc0140504a3308041224544c535f45434448455f45434453415f574954485f4145535f3235365f4342435f5348411a096c6f63616c686f7374528a010a3c747970652e676f6f676c65617069732e636f6d2f696e65746d6f636b2e61756469742e64657461696c732e4854545044657461696c73456e74697479124a12096c6f63616c686f73741a15687474703a2f2f6c6f63616c686f73742f6173646622084854545020312e312a1c0a0641636365707412120a106170706c69636174696f6e2f6a736f6e"; + private const string DnsEventPayload = "0000003b120b088092b8c398feffffff01180120012a100000000000000000000000000000000132100000000000000000000000000000000138d8fc014050"; + + private readonly byte[] _httpEventPayloadBytes; + private readonly byte[] _dnsEventPayloadBytes; + + public TypedReaderTest() { - private const string HttpEventPayload = "000000e5120b088092b8c398feffffff01180120022a047f00000132047f00000138d8fc0140504a3308041224544c535f45434448455f45434453415f574954485f4145535f3235365f4342435f5348411a096c6f63616c686f7374528a010a3c747970652e676f6f676c65617069732e636f6d2f696e65746d6f636b2e61756469742e64657461696c732e4854545044657461696c73456e74697479124a12096c6f63616c686f73741a15687474703a2f2f6c6f63616c686f73742f6173646622084854545020312e312a1c0a0641636365707412120a106170706c69636174696f6e2f6a736f6e"; - private const string DnsEventPayload = "0000003b120b088092b8c398feffffff01180120012a100000000000000000000000000000000132100000000000000000000000000000000138d8fc014050"; + _httpEventPayloadBytes = HttpEventPayload.HexToByteArray(); + _dnsEventPayloadBytes = DnsEventPayload.HexToByteArray(); + } - private readonly byte[] _httpEventPayloadBytes; - private readonly byte[] _dnsEventPayloadBytes; - - public TypedReaderTest() + [Fact] + public async void TestRead_HttpEvent_Success() + { + await using var protoReader = new ProtoReader(new MemoryStream(_httpEventPayloadBytes)); + await using IEventReader reader = new TypedReader(protoReader, DropMode.DropEntity); + await foreach (var ev in reader.ReadAllAsync()) { - _httpEventPayloadBytes = HttpEventPayload.HexToByteArray(); - _dnsEventPayloadBytes = DnsEventPayload.HexToByteArray(); + Assert.NotNull(ev); } + } - [Fact] - public async void TestRead_HttpEvent_Success() + [Fact] + public async void TestRead_DnsEvent_Success() + { + await using var protoReader = new ProtoReader(new MemoryStream(_dnsEventPayloadBytes)); + await using IEventReader reader = new TypedReader(protoReader, DropMode.DropEntity); + await foreach (var ev in reader.ReadAllAsync()) { - await using var protoReader = new ProtoReader(new MemoryStream(_httpEventPayloadBytes)); - await using IEventReader reader = new TypedReader(protoReader, DropMode.DropEntity); - await foreach (var ev in reader.ReadAllAsync()) - { - Assert.NotNull(ev); - } - } - - [Fact] - public async void TestRead_DnsEvent_Success() - { - await using var protoReader = new ProtoReader(new MemoryStream(_dnsEventPayloadBytes)); - await using IEventReader reader = new TypedReader(protoReader, DropMode.DropEntity); - await foreach (var ev in reader.ReadAllAsync()) - { - Assert.NotNull(ev); - } + Assert.NotNull(ev); } } } diff --git a/tests/INetMock.Client.Test/Hex/Converter.cs b/tests/INetMock.Client.Test/Hex/Converter.cs index 4d1abd5..d34abac 100644 --- a/tests/INetMock.Client.Test/Hex/Converter.cs +++ b/tests/INetMock.Client.Test/Hex/Converter.cs @@ -1,15 +1,15 @@ using System; using System.Linq; -namespace INetMock.Client.Test.Hex +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) { - return Enumerable.Range(0, hex.Length) - .Where(x => x % 2 == 0) - .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) - .ToArray(); - } + return Enumerable.Range(0, hex.Length) + .Where(x => x % 2 == 0) + .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) + .ToArray(); } } diff --git a/tests/INetMock.Client.Test/INetMock.Client.Test.csproj b/tests/INetMock.Client.Test/INetMock.Client.Test.csproj index f81850c..138e18c 100644 --- a/tests/INetMock.Client.Test/INetMock.Client.Test.csproj +++ b/tests/INetMock.Client.Test/INetMock.Client.Test.csproj @@ -1,20 +1,20 @@ - net5.0 + net6.0 false latest enable - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/INetMock.Client.Test/PCAP/SubscriptionTests.cs b/tests/INetMock.Client.Test/PCAP/SubscriptionTests.cs index 7a4e776..66eecef 100644 --- a/tests/INetMock.Client.Test/PCAP/SubscriptionTests.cs +++ b/tests/INetMock.Client.Test/PCAP/SubscriptionTests.cs @@ -1,17 +1,16 @@ using INetMock.Client.PCAP; using Xunit; -namespace INetMock.Client.Test.PCAP +namespace INetMock.Client.Test.PCAP; + +public class SubscriptionTests { - public class SubscriptionTests + [Theory] + [InlineData("lo:test.pcap", "test.pcap", "lo")] + public void Constructor_ConsumerKey_SplitIntoComponents(string key, string expectedName, string expectedDevice) { - [Theory] - [InlineData("lo:test.pcap", "test.pcap", "lo")] - public void Constructor_ConsumerKey_SplitIntoComponents(string key, string expectedName, string expectedDevice) - { - var sub = new Subscription(key); - - Assert.Equal(sub, new Subscription(key, expectedName, expectedDevice)); - } + var sub = new Subscription(key); + + Assert.Equal(sub, new Subscription(key, expectedName, expectedDevice)); } } -- 2.45.2 From 752bd9d8f54e5c043c91711f47f4fb02a59f531b Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Thu, 27 Jan 2022 10:48:00 +0100 Subject: [PATCH 12/51] Add docs how to add the NuGet feed --- INetMock.sln | 1 + README.md | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/INetMock.sln b/INetMock.sln index 54084ae..1d04ae9 100644 --- a/INetMock.sln +++ b/INetMock.sln @@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt .gitignore = .gitignore .gitlab-ci.yml = .gitlab-ci.yml .pre-commit-config.yaml = .pre-commit-config.yaml + README.md = README.md EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{07100561-E3C0-4B95-92E1-D2D3BA12C3A6}" diff --git a/README.md b/README.md index cd7e63d..a4677e9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ # client-dotnet +## NuGet source + +```shell +dotnet nuget add source \ + https://gitlab.com/api/v4/projects/24385200/packages/nuget/index.json \ + -n GitLabInetMock \ + -u gitlab+deploy-token-776107 \ + -p 3FLWym5gfajuJNhBKvWV \ + --store-password-in-clear-text +``` -- 2.45.2 From c564229fb252491daad455fa0fb1be42eddd508e Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Thu, 27 Jan 2022 11:03:21 +0100 Subject: [PATCH 13/51] Fix tag build --- .gitlab-ci.yml | 3 +-- build/Build.cs | 54 ++++++++++++++++++++++++--------------------- build/_build.csproj | 1 + 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d7a9992..3474751 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -56,7 +56,6 @@ nuget-publish: only: refs: - tags - - main script: - dotnet tool restore - - dotnet nuke NuGetPush + - dotnet nuke NuGetPush --nuget-username "${NUGET_USERNAME}" --nuget-password "${NUGET_PASSWORD}" diff --git a/build/Build.cs b/build/Build.cs index 2d9d880..f559c63 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -1,5 +1,6 @@ using System; using JetBrains.Annotations; +using NuGet.Versioning; using Nuke.Common; using Nuke.Common.CI; using Nuke.Common.CI.GitLab; @@ -25,18 +26,17 @@ class Build : NukeBuild readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; [Parameter("Username to use for publishing NuGet packages", Name = "nuget-username")] - string NuGetUsername { get; } = Environment.GetEnvironmentVariable("NUGET_USERNAME") ?? string.Empty; + string NuGetUsername { get; set; } = Environment.GetEnvironmentVariable("NUGET_USERNAME") ?? string.Empty; [Parameter("Password to use for publishing NuGet packages", Name = "nuget-password")] - string NuGetPassword { get; } = Environment.GetEnvironmentVariable("NUGET_PASSWORD") ?? string.Empty; + string NuGetPassword { get; set; } = Environment.GetEnvironmentVariable("NUGET_PASSWORD") ?? string.Empty; - [Solution] readonly Solution Solution; - [GitRepository] readonly GitRepository GitRepository; - [GitVersion(NoFetch = true)] readonly GitVersion GitVersion; + [Solution] readonly Solution? Solution; + [GitRepository] readonly GitRepository? GitRepository; + [GitVersion(NoFetch = true, Framework = "net6.0")] readonly GitVersion? GitVersion; - [CanBeNull] - GitLab CI => GitLab.Instance; + GitLab? CI => GitLab.Instance; AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath TestsDirectory => RootDirectory / "tests"; @@ -62,12 +62,17 @@ class Build : NukeBuild .DependsOn(Restore) .Executes(() => { + var assemblyVersion = GitVersion?.AssemblySemVer ?? + SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToNormalizedString(); + var informationalVersion = GitVersion?.InformationalVersion ?? + SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToFullString(); + DotNetBuild(s => s .SetProjectFile(Solution) .SetConfiguration(Configuration) - .SetAssemblyVersion(GitVersion.AssemblySemVer) - .SetFileVersion(GitVersion.AssemblySemFileVer) - .SetInformationalVersion(GitVersion.InformationalVersion) + .SetAssemblyVersion(assemblyVersion) + .SetFileVersion(assemblyVersion) + .SetInformationalVersion(informationalVersion) .EnableNoRestore()); }); @@ -84,28 +89,16 @@ class Build : NukeBuild .EnableNoBuild() .EnableProcessLogOutput())); - Target AddNugetSource => _ => _ - .OnlyWhenStatic(() => GitRepository.IsOnMainBranch()) - .OnlyWhenStatic(() => CI != null) - .OnlyWhenStatic(() => !string.IsNullOrEmpty(NuGetUsername) && !string.IsNullOrEmpty(NuGetPassword)) - .ProceedAfterFailure() - .Executes(() => DotNetNuGetAddSource(s => s - .SetName(NuGetSourceName) - .SetSource($"https://gitlab.com/api/v4/projects/{CI.ProjectId}/packages/nuget/index.json") - .SetUsername(NuGetUsername) - .SetPassword(NuGetPassword) - .EnableStorePasswordInClearText())); - Target Pack => _ => _ .DependsOn(Compile) - .OnlyWhenStatic(() => GitRepository.IsOnMainBranch()) + .OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag)) .Executes(() => SourceDirectory .GlobFiles("**/*.csproj") .ForEach(csproj => DotNetPack(s => s .SetProject(csproj) .SetConfiguration(Configuration) .SetOutputDirectory(ArtifactsDirectory) - .SetVersion(GitVersion.FullSemVer) + .SetVersion(GitVersion?.FullSemVer ?? SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToNormalizedString()) .EnableIncludeSource() .EnableIncludeSymbols() .EnableNoRestore() @@ -113,9 +106,20 @@ class Build : NukeBuild .EnableProcessLogOutput() ))); + Target AddNugetSource => _ => _ + .OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag)) + .OnlyWhenStatic(() => !string.IsNullOrEmpty(NuGetUsername) && !string.IsNullOrEmpty(NuGetPassword)) + .ProceedAfterFailure() + .Executes(() => DotNetNuGetAddSource(s => s + .SetName(NuGetSourceName) + .SetSource($"https://gitlab.com/api/v4/projects/{CI?.ProjectId}/packages/nuget/index.json") + .SetUsername(NuGetUsername) + .SetPassword(NuGetPassword) + .EnableStorePasswordInClearText())); + Target NuGetPush => _ => _ .DependsOn(Pack, AddNugetSource) - .OnlyWhenStatic(() => GitRepository.IsOnMainBranch()) + .OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag)) .Executes(() => ArtifactsDirectory .GlobFiles("**/*.nupkg") .ForEach(nupkg => DotNetNuGetPush(s => s diff --git a/build/_build.csproj b/build/_build.csproj index 794a52b..6252f12 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -9,6 +9,7 @@ net6.0 latest 1 + enable -- 2.45.2 From 9191cbaa9f1afd060ea46e3ec44ac1c09cecaea3 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Thu, 27 Jan 2022 20:37:25 +0100 Subject: [PATCH 14/51] Extend docs and add missing constructors --- README.md | 22 +++++++++++++++++++++- src/INetMock.Client/Audit/Event.cs | 27 ++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a4677e9..31eaa80 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ -# client-dotnet +# INetMock .NET client library ## NuGet source +Due to limitations in GitLab one is required to be authenticated to use packages in GitLab NuGet registry. +The following credentials are `read_only` and allowed to be used by anyone. + ```shell dotnet nuget add source \ https://gitlab.com/api/v4/projects/24385200/packages/nuget/index.json \ @@ -10,3 +13,20 @@ dotnet nuget add source \ -p 3FLWym5gfajuJNhBKvWV \ --store-password-in-clear-text ``` + +## Reading audit files + +```c# +using System.IO; +using System.Threading.Tasks; +using INetMock.Client.Audit; +using INetMock.Client.Audit.Serialization; + +await using var auditFileStream = File.OpenRead("test.ima"); +await using IEventReader reader = new GenericReader(new ProtoReader(auditFileStream)); + +await foreach (var ev in reader.ReadAllAsync()) +{ + Console.WriteLine(ev.Application); +} +``` diff --git a/src/INetMock.Client/Audit/Event.cs b/src/INetMock.Client/Audit/Event.cs index 3eeb1ff..eda96fa 100644 --- a/src/INetMock.Client/Audit/Event.cs +++ b/src/INetMock.Client/Audit/Event.cs @@ -3,9 +3,9 @@ using System.Net; namespace INetMock.Client.Audit; -public abstract record EventBase +public abstract record EventBase() { - protected EventBase(EventEntity entity) + protected EventBase(EventEntity entity) : this() { if (entity == null) { @@ -24,18 +24,30 @@ public abstract record EventBase } public long Id { get; init; } - public DateTimeOffset Timestamp { get; init; } - public TransportProtocol Transport { get; init; } - public AppProtocol Application { get; init; } + + public DateTimeOffset Timestamp { get; init; } = DateTimeOffset.UnixEpoch; + + public TransportProtocol Transport { get; init; } = TransportProtocol.Unspecified; + + public AppProtocol Application { get; init; } = AppProtocol.Unspecified; + public IPAddress SourceIp { get; init; } = IPAddress.Any; + public IPAddress DestinationIp { get; init; } = IPAddress.Any; + public ushort SourcePort { get; init; } + public ushort DestinationPort { get; init; } + public TLSDetailsEntity TlsDetails { get; init; } = new(); } public record Event : EventBase { + public Event() + { + } + public Event(EventEntity entity) : base(entity) { Details = entity.ProtocolDetailsCase switch @@ -54,6 +66,11 @@ public record Event : EventBase public record Event : EventBase where T : EventDetails, new() { + public Event() + { + + } + public Event(EventEntity entity) : base(entity) { Details = entity.ProtocolDetailsCase switch -- 2.45.2 From 48a94cb1aa78ad33adfe47e3d8d3bd4e49dbdbf0 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Fri, 28 Jan 2022 07:29:44 +0100 Subject: [PATCH 15/51] Fix NuGet publish credentials --- .gitlab-ci.yml | 2 +- .nuke/build.schema.json | 8 -------- build/Build.cs | 15 +++------------ 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3474751..6f10418 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -58,4 +58,4 @@ nuget-publish: - tags script: - dotnet tool restore - - dotnet nuke NuGetPush --nuget-username "${NUGET_USERNAME}" --nuget-password "${NUGET_PASSWORD}" + - dotnet nuke NuGetPush diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index ed1030d..1828fb1 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -46,14 +46,6 @@ "type": "boolean", "description": "Disables displaying the NUKE logo" }, - "nuget-password": { - "type": "string", - "description": "Password to use for publishing NuGet packages" - }, - "nuget-username": { - "type": "string", - "description": "Username to use for publishing NuGet packages" - }, "Partition": { "type": "string", "description": "Partition to use on CI" diff --git a/build/Build.cs b/build/Build.cs index f559c63..c691524 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -1,5 +1,3 @@ -using System; -using JetBrains.Annotations; using NuGet.Versioning; using Nuke.Common; using Nuke.Common.CI; @@ -25,12 +23,6 @@ class Build : NukeBuild [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; - [Parameter("Username to use for publishing NuGet packages", Name = "nuget-username")] - string NuGetUsername { get; set; } = Environment.GetEnvironmentVariable("NUGET_USERNAME") ?? string.Empty; - - [Parameter("Password to use for publishing NuGet packages", Name = "nuget-password")] - string NuGetPassword { get; set; } = Environment.GetEnvironmentVariable("NUGET_PASSWORD") ?? string.Empty; - [Solution] readonly Solution? Solution; [GitRepository] readonly GitRepository? GitRepository; [GitVersion(NoFetch = true, Framework = "net6.0")] readonly GitVersion? GitVersion; @@ -107,14 +99,13 @@ class Build : NukeBuild ))); Target AddNugetSource => _ => _ - .OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag)) - .OnlyWhenStatic(() => !string.IsNullOrEmpty(NuGetUsername) && !string.IsNullOrEmpty(NuGetPassword)) + .OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag) && !string.IsNullOrEmpty(CI.JobToken)) .ProceedAfterFailure() .Executes(() => DotNetNuGetAddSource(s => s .SetName(NuGetSourceName) .SetSource($"https://gitlab.com/api/v4/projects/{CI?.ProjectId}/packages/nuget/index.json") - .SetUsername(NuGetUsername) - .SetPassword(NuGetPassword) + .SetUsername("gitlab-ci-token") + .SetPassword(CI!.JobToken) .EnableStorePasswordInClearText())); Target NuGetPush => _ => _ -- 2.45.2 From 19b3ae16cbec34deccc0d06664205d416911f7e1 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Fri, 28 Jan 2022 15:55:52 +0100 Subject: [PATCH 16/51] Fix nullability issue --- src/INetMock.Client/Audit/Event.cs | 4 +++- .../Audit/Serialization/GenericReaderTest.cs | 8 +++++--- .../INetMock.Client.IntegrationTest.csproj | 2 +- .../testdata/test2.ima | Bin 0 -> 8010 bytes 4 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 tests/INetMock.Client.IntegrationTest/testdata/test2.ima diff --git a/src/INetMock.Client/Audit/Event.cs b/src/INetMock.Client/Audit/Event.cs index eda96fa..724119d 100644 --- a/src/INetMock.Client/Audit/Event.cs +++ b/src/INetMock.Client/Audit/Event.cs @@ -39,7 +39,9 @@ public abstract record EventBase() public ushort DestinationPort { get; init; } - public TLSDetailsEntity TlsDetails { get; init; } = new(); + public TLSDetailsEntity? TlsDetails { get; init; } + + public bool IsTls => TlsDetails != null; } public record Event : EventBase diff --git a/tests/INetMock.Client.IntegrationTest/Audit/Serialization/GenericReaderTest.cs b/tests/INetMock.Client.IntegrationTest/Audit/Serialization/GenericReaderTest.cs index 1fc5cca..6c960ff 100644 --- a/tests/INetMock.Client.IntegrationTest/Audit/Serialization/GenericReaderTest.cs +++ b/tests/INetMock.Client.IntegrationTest/Audit/Serialization/GenericReaderTest.cs @@ -8,10 +8,12 @@ namespace INetMock.Client.IntegrationTest.Audit.Serialization; public class GenericReaderTest { - [Fact] - public async Task Test_ReadAllAsync_AuditFile() + [Theory] + [InlineData("test.ima")] + [InlineData("test2.ima")] + public async Task Test_ReadAllAsync_AuditFile(string testFile) { - await using var auditFileStream = File.OpenRead(Path.Join("testdata", "test.ima")); + await using var auditFileStream = File.OpenRead(Path.Join("testdata", testFile)); await using IEventReader reader = new GenericReader(new ProtoReader(auditFileStream)); var count = 0; diff --git a/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj b/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj index 99b230e..c93903e 100644 --- a/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj +++ b/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj @@ -28,7 +28,7 @@ - + PreserveNewest diff --git a/tests/INetMock.Client.IntegrationTest/testdata/test2.ima b/tests/INetMock.Client.IntegrationTest/testdata/test2.ima new file mode 100644 index 0000000000000000000000000000000000000000..caeee183425dfd49b57a8f977974882320b82db6 GIT binary patch literal 8010 zcmeHMdrVVT80Ugx^_EG!Iv<#9oqtU2)|OU57PG`golM=b1s3=mf)(9>^lai@HzkiO=J=H$w^;HY%BZ$#2)d2b{%*zOUnAyaqnys8u&{$GUg2~C6 zT@Fsj)TFYAjhcel)@}kex$FVVrL;76;t)z19(*b=IVz#R9WlNxV#;J$1T!LeT9R?n zgo%lh@OP5IIQ{M9M5AF+l2NBmFixKEjxj0GppT1>i3vO=FI7t+s33R5^wn}s8;@r+ zT$Y%e{GL{)(Wzo+dV-DTS+l^|cqWRbr?RYFZLo4*u&USSDD<1a@`5@!)6O!(=%E5T zQ_$M2CXOGcG^d*!PF8r+C8VhnR7#ruz{xt)1`E2MVQ9r<CAIF0hN%Kgu9c5ePn3TIXW zE~SgkT)t0U6*q{fx_(6I0X}*W^<%!*i;v$n1LyFG)WX5peR3iJ%_yZZWJkAWCk$(Q(O+g%8K6_ zo)!L{#QHXgAr}~y-0XCdGt`8dgbPpN`uF$6IDHEgMa}bSDdH-$b}v++*BKS6La(M; zO%8`CQ_Z>@HoMwxvsu+Tzr6$&)E!^qA3YDYp|1IVGwD_{c>^yf4(r&l&_~D3%iC^{ z=X>2c&{4^}gmjGIb?R93Hzu%l?h+rel?|0QdtEUM&|5}7(cTi4g|*vT2H}*;@?i}& ztUmoI@e;hVAEZlQ;*oTE-z8|W3ao=S3CP<7TaIAuntaD_);(*+|EsZk)^4x@g_vrR2q}NOa0?b;l_W4Y+8%)NO2(1K$v%(3SvGV+bQ%_HeyCJj~09sgW7LM1V zy@t!~a#(wp9E1L~>*<5Gw(+P>!KSBiwT~LLb-(A6TbjFKvBTTpXhxoHw`$VuU9Rs# ztabfK3B3?1Y1zulh2-e>MD%Fp1%%$$@)c*-*c=vY#!@i$dC#AsQ<@9dhdd`2lVi7u z*h87Y2z!9Z>dN3bjTskcb9$Gl{0OsD?3Y*;0LzhvpIgXT?u#r6rXOOVEg2@x+7%uE z_pWNkQ;^G+0QkQ4Is*0Qb9{74yckG%F9z zUUmZd{Nq_$$bIVN*@4IY366ThMhU$E(2th3=aIXo>|cWnUcm78Z)W4c%Vj?S{N33V zGl)auy#?sq^w{F*P;pj{7&MXh&c4GZ$dhTixPOpNhot_Z^Y7@vLafdPHo2@BX6Y?$ z9!qQ?=06*!Lr>%cD1K}(kBQ0+n8FiopJ-mFz4$e8&a`Di&OC}Kgw}c8Bjt~%XwBJ6 zyUAPU!k$PPIL*A&9XRj{d`D0t+})wAJnkdev9Rpgg%eAGDn-I6m;QH^_{ z)Cgf^dhGWC7>p+;WS5oMQSKJ2>v^bmyN}*3ByUOXB_UeU)fx%C71004ySSGeebdz- zEeX2yt&%z7;5z{R#@XyPa`?rb5QCpvC82i$`u05qRpkA&p)%Cq%jV{bgD=~KPY?IF zFLc9-)f@;scyLMCD*&CAEd%tWSKcQsyalU*3?0tfR$P#Vz8t`R=%`;r-jXY}0(^J9 z02~mtHlTv>Bw9PzZaii-GJ0e!6B10t{jEwg>d>dIPY5?g_?p7f3X{zXww z-|qzP?%jIFgbK|pT=*{(LNuc!=}r}IT0@>Q2aZF|Jc<{9?sKR_8pJBdpWKb7&ysha z@}6iab$UN}=B0ePkDohYLUfyJ5*QqDJ>`xYv3->2pgjI W Date: Fri, 28 Jan 2022 17:05:51 +0000 Subject: [PATCH 17/51] Update dependency Google.Protobuf to v3.19.4 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index d90bc6d..2dc98c4 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -9,7 +9,7 @@ - + -- 2.45.2 From eaf4e75b5c0c1e967b5a3c3f6d60bb5c0d210f90 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Wed, 2 Feb 2022 14:29:11 +0100 Subject: [PATCH 18/51] Support network monitor details --- api/proto/audit/v1/event_entity.proto | 2 ++ api/proto/audit/v1/netmon_details.proto | 8 ++++++++ src/INetMock.Client/Audit/Details.cs | 10 ++++++++++ src/INetMock.Client/Audit/Event.cs | 2 ++ src/INetMock.Client/INetMock.Client.csproj | 10 ++-------- .../Audit/Serialization/GenericReaderTest.cs | 1 + .../testdata/test3.ima | Bin 0 -> 429 bytes 7 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 api/proto/audit/v1/netmon_details.proto create mode 100644 tests/INetMock.Client.IntegrationTest/testdata/test3.ima diff --git a/api/proto/audit/v1/event_entity.proto b/api/proto/audit/v1/event_entity.proto index d0b09bd..1a5d3bd 100644 --- a/api/proto/audit/v1/event_entity.proto +++ b/api/proto/audit/v1/event_entity.proto @@ -6,6 +6,7 @@ import "google/protobuf/timestamp.proto"; import "audit/v1/http_details.proto"; import "audit/v1/dns_details.proto"; import "audit/v1/dhcp_details.proto"; +import "audit/v1/netmon_details.proto"; enum TransportProtocol { TRANSPORT_PROTOCOL_UNSPECIFIED = 0; @@ -52,5 +53,6 @@ message EventEntity { HTTPDetailsEntity http = 20; DNSDetailsEntity dns = 21; DHCPDetailsEntity dhcp = 22; + NetMonDetailsEntity net_mon = 23; } } diff --git a/api/proto/audit/v1/netmon_details.proto b/api/proto/audit/v1/netmon_details.proto new file mode 100644 index 0000000..7cb2d60 --- /dev/null +++ b/api/proto/audit/v1/netmon_details.proto @@ -0,0 +1,8 @@ + +syntax = "proto3"; + +package inetmock.audit.v1; + +message NetMonDetailsEntity { + string reverse_resolved_host = 1; +} diff --git a/src/INetMock.Client/Audit/Details.cs b/src/INetMock.Client/Audit/Details.cs index d5dea8c..0095d03 100644 --- a/src/INetMock.Client/Audit/Details.cs +++ b/src/INetMock.Client/Audit/Details.cs @@ -51,3 +51,13 @@ public record DhcpDetails() : EventDetails public DHCPOpCode OpCode { get; init; } = DHCPOpCode.Unspecified; public DHCPHwType HardwareType { get; init; } = DHCPHwType.Unspecified; } + +public record NetMonDetails() : EventDetails +{ + public NetMonDetails(NetMonDetailsEntity entity) : this() + { + ReverseResolvedHost = entity.ReverseResolvedHost; + } + + public string ReverseResolvedHost { get; init; } = string.Empty; +} diff --git a/src/INetMock.Client/Audit/Event.cs b/src/INetMock.Client/Audit/Event.cs index 724119d..646d892 100644 --- a/src/INetMock.Client/Audit/Event.cs +++ b/src/INetMock.Client/Audit/Event.cs @@ -57,6 +57,7 @@ public record Event : EventBase EventEntity.ProtocolDetailsOneofCase.Http => new HttpDetails(entity.Http), EventEntity.ProtocolDetailsOneofCase.Dns => new DnsDetails(entity.Dns), EventEntity.ProtocolDetailsOneofCase.Dhcp => new DhcpDetails(entity.Dhcp), + EventEntity.ProtocolDetailsOneofCase.NetMon => new NetMonDetails(entity.NetMon), _ => null }; } @@ -80,6 +81,7 @@ public record Event : EventBase where T : EventDetails, new() EventEntity.ProtocolDetailsOneofCase.Http => new HttpDetails(entity.Http) as T, EventEntity.ProtocolDetailsOneofCase.Dns => new DnsDetails(entity.Dns) as T, EventEntity.ProtocolDetailsOneofCase.Dhcp => new DhcpDetails(entity.Dhcp) as T, + EventEntity.ProtocolDetailsOneofCase.NetMon => new NetMonDetails(entity.NetMon) as T, _ => null }; } diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 2dc98c4..9aaf04f 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -18,13 +18,7 @@ - - - - - - - - + + diff --git a/tests/INetMock.Client.IntegrationTest/Audit/Serialization/GenericReaderTest.cs b/tests/INetMock.Client.IntegrationTest/Audit/Serialization/GenericReaderTest.cs index 6c960ff..d82dadf 100644 --- a/tests/INetMock.Client.IntegrationTest/Audit/Serialization/GenericReaderTest.cs +++ b/tests/INetMock.Client.IntegrationTest/Audit/Serialization/GenericReaderTest.cs @@ -11,6 +11,7 @@ public class GenericReaderTest [Theory] [InlineData("test.ima")] [InlineData("test2.ima")] + [InlineData("test3.ima")] public async Task Test_ReadAllAsync_AuditFile(string testFile) { await using var auditFileStream = File.OpenRead(Path.Join("testdata", testFile)); diff --git a/tests/INetMock.Client.IntegrationTest/testdata/test3.ima b/tests/INetMock.Client.IntegrationTest/testdata/test3.ima new file mode 100644 index 0000000000000000000000000000000000000000..7fd2eff0beee0c9d3f3f415d255b106bdf323bee GIT binary patch literal 429 zcmZQzU~u7RIMDFp@!S>HkPH-=d4rp^Fh_&X09ab3TF1=~{Ma zITIH5pqYc>9%qohjxCxGat}AhFR(eA7OdsOVvGx_b1;pWwh3y?Z?G{PhqsbtOxr`K OG5^5EJleC7Bx3+iL5+F< literal 0 HcmV?d00001 -- 2.45.2 From eb9d18235fba1cf398c7af52a504b9f816683453 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Fri, 25 Feb 2022 13:04:15 +0000 Subject: [PATCH 19/51] Update dependency dotnet-grpc to v2.43.0 --- .config/dotnet-tools.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 4b91376..4a0c1b8 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "dotnet-grpc": { - "version": "2.42.0", + "version": "2.43.0", "commands": [ "dotnet-grpc" ] -- 2.45.2 From 191e9af46ce61fbd4063da0201274149c5a05ee8 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Fri, 25 Feb 2022 18:03:39 +0000 Subject: [PATCH 20/51] Update dependency Grpc.Net.Client to v2.43.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 9aaf04f..0a762d5 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -10,7 +10,7 @@ - + all -- 2.45.2 From c4e860889b1378002c28f287f1def470930c85f2 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Mon, 28 Feb 2022 11:00:05 +0000 Subject: [PATCH 21/51] Update dependency Grpc.Net.ClientFactory to v2.43.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 0a762d5..4a9aa12 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- 2.45.2 From d58c1433f46712bdda24d26f2a448d9d01e6ea6c Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Mon, 28 Feb 2022 12:04:12 +0000 Subject: [PATCH 22/51] Update dependency Grpc.Tools to v2.44.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 4a9aa12..2ab1035 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- 2.45.2 From 663da87fea2c8f1a01d179c3dc67f2f47038f319 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Thu, 17 Mar 2022 17:04:21 +0000 Subject: [PATCH 23/51] Update dependency Grpc.Net.Client to v2.44.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 2ab1035..e470b33 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -10,7 +10,7 @@ - + all -- 2.45.2 From f3a6254a5d7ddb08f1b2408d38c458645de649d2 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Wed, 23 Mar 2022 12:04:40 +0000 Subject: [PATCH 24/51] Update dependency dotnet-grpc to v2.44.0 --- .config/dotnet-tools.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 4a0c1b8..2ce4699 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "dotnet-grpc": { - "version": "2.43.0", + "version": "2.44.0", "commands": [ "dotnet-grpc" ] -- 2.45.2 From 92a0ac5d6aa627d7f111154fe871bfade82bf22f Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Wed, 23 Mar 2022 12:04:36 +0000 Subject: [PATCH 25/51] Update dependency Grpc.Net.ClientFactory to v2.44.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index e470b33..0f50c4a 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- 2.45.2 From e9fe164be5235f980f9f5a26e2d7430df3b4b1d3 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Thu, 24 Mar 2022 12:26:57 +0000 Subject: [PATCH 26/51] Update dependency Grpc.Tools to v2.45.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 0f50c4a..04ad48b 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- 2.45.2 From 8b2f51748d792e6e39b156f10b4880303b6da864 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Wed, 30 Mar 2022 09:06:23 +0200 Subject: [PATCH 27/51] Minor patches --- .gitlab-ci.yml | 2 +- INetMock.sln | 1 + global.json | 2 +- .../INetMock.Client.IntegrationTest.csproj | 4 ++-- tests/INetMock.Client.Test/INetMock.Client.Test.csproj | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6f10418..d648e81 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,7 @@ test: - docker:dind before_script: - | - curl https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz | tar -xzv -C /usr/local/ + 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 \ diff --git a/INetMock.sln b/INetMock.sln index 1d04ae9..4f156f3 100644 --- a/INetMock.sln +++ b/INetMock.sln @@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt .gitlab-ci.yml = .gitlab-ci.yml .pre-commit-config.yaml = .pre-commit-config.yaml README.md = README.md + global.json = global.json EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{07100561-E3C0-4B95-92E1-D2D3BA12C3A6}" diff --git a/global.json b/global.json index 08fc58c..bac7434 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "6.0.100", + "version": "6.0.102", "rollForward": "latestMinor" } } \ No newline at end of file diff --git a/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj b/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj index c93903e..7df0678 100644 --- a/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj +++ b/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj @@ -11,13 +11,13 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/INetMock.Client.Test/INetMock.Client.Test.csproj b/tests/INetMock.Client.Test/INetMock.Client.Test.csproj index 138e18c..0d144c1 100644 --- a/tests/INetMock.Client.Test/INetMock.Client.Test.csproj +++ b/tests/INetMock.Client.Test/INetMock.Client.Test.csproj @@ -8,13 +8,13 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- 2.45.2 From dfbc9b8e3d813dd40047200b63a5f19ac5041b0c Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Sat, 2 Apr 2022 07:03:09 +0000 Subject: [PATCH 28/51] Update dependency Google.Protobuf to v3.20.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 04ad48b..f4bbd2b 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -9,7 +9,7 @@ - + -- 2.45.2 From ae66972b0409e20ab885180266b3956ba45c9c13 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Wed, 13 Apr 2022 07:04:55 +0000 Subject: [PATCH 29/51] Update dependency nuke.globaltool to v6.0.2 --- .config/dotnet-tools.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 2ce4699..3c21a6d 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -9,7 +9,7 @@ ] }, "nuke.globaltool": { - "version": "6.0.1", + "version": "6.0.2", "commands": [ "nuke" ] -- 2.45.2 From f7bb6bc60267b24b295e28783bf058860f2d48c6 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Fri, 22 Apr 2022 14:08:46 +0000 Subject: [PATCH 30/51] Update dependency Grpc.Net.Client to v2.45.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index f4bbd2b..f0455ee 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -10,7 +10,7 @@ - + all -- 2.45.2 From a6ac5686f8c8779bc616ed439b21d226dc55a19b Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Fri, 22 Apr 2022 14:08:44 +0000 Subject: [PATCH 31/51] Update dependency Nuke.Common to v6.0.2 --- build/_build.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/_build.csproj b/build/_build.csproj index 6252f12..3439e83 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -13,7 +13,7 @@ - + -- 2.45.2 From eb00497706c757c6b145cb4e96bc2c174887978f Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Fri, 22 Apr 2022 17:04:31 +0000 Subject: [PATCH 32/51] Update dependency dotnet-grpc to v2.45.0 --- .config/dotnet-tools.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 3c21a6d..e6479fe 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "dotnet-grpc": { - "version": "2.44.0", + "version": "2.45.0", "commands": [ "dotnet-grpc" ] -- 2.45.2 From 829477fe2e98ada30eef1009d7fc4aba540e218f Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Fri, 22 Apr 2022 17:04:29 +0000 Subject: [PATCH 33/51] Update dependency Grpc.Net.ClientFactory to v2.45.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index f0455ee..bbc7b67 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- 2.45.2 From a968ff213232f15453648a632fd8ba3a85f759ed Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Sat, 23 Apr 2022 17:04:57 +0000 Subject: [PATCH 34/51] Update dependency Google.Protobuf to v3.20.1 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index bbc7b67..eebf28e 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -9,7 +9,7 @@ - + -- 2.45.2 From 122487ea6d1145790be4657b697cf91870349d2d Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Tue, 26 Apr 2022 17:55:31 +0000 Subject: [PATCH 35/51] Add LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..536fca6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 inetmock + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. -- 2.45.2 From 59e6b93cc7184f1c30ccad8aee639646943cf2a2 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Thu, 2 Jun 2022 19:47:13 +0000 Subject: [PATCH 36/51] Update dependency Grpc.Net.Client to v2.46.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index eebf28e..6e13f0b 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -10,7 +10,7 @@ - + all -- 2.45.2 From dab0bc9b59063a40f4ea5ef99b400b2aadb77cf9 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Thu, 2 Jun 2022 19:56:17 +0000 Subject: [PATCH 37/51] Update dependency Nuke.Common to v6.0.3 --- build/_build.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/_build.csproj b/build/_build.csproj index 3439e83..c4263d3 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -13,7 +13,7 @@ - + -- 2.45.2 From d6293800bea9fe685e0ed8f56b962241d6d2b61b Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Thu, 2 Jun 2022 20:13:36 +0000 Subject: [PATCH 38/51] Update dependency Grpc.Tools to v2.46.3 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 6e13f0b..64e8306 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- 2.45.2 From c60378be9b6075465560f23ba88e9ac113eb7072 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Thu, 2 Jun 2022 19:56:20 +0000 Subject: [PATCH 39/51] Update dependency nuke.globaltool to v6.0.3 --- .config/dotnet-tools.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index e6479fe..a2cd149 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -9,7 +9,7 @@ ] }, "nuke.globaltool": { - "version": "6.0.2", + "version": "6.0.3", "commands": [ "nuke" ] -- 2.45.2 From 37e5e4c66b2a51388090d1e8c2d70b524d86bfed Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Thu, 2 Jun 2022 20:13:32 +0000 Subject: [PATCH 40/51] Update dependency Grpc.Net.ClientFactory to v2.46.0 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 64e8306..bfe120a 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- 2.45.2 From d9c26f788d213ffccd802552b54b88a807e734fe Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Sat, 4 Jun 2022 11:04:50 +0000 Subject: [PATCH 41/51] Update dependency dotnet-grpc to v2.46.0 --- .config/dotnet-tools.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index a2cd149..5d8c576 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "dotnet-grpc": { - "version": "2.45.0", + "version": "2.46.0", "commands": [ "dotnet-grpc" ] -- 2.45.2 From 6778e7f8a8e7a11bcba4f7e1086c2eb1702a1dc6 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Sat, 4 Jun 2022 12:04:13 +0000 Subject: [PATCH 42/51] Update dependency Google.Protobuf to v3.21.1 --- src/INetMock.Client/INetMock.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index bfe120a..1051980 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -9,7 +9,7 @@ - + -- 2.45.2 From a4812683bb07d2f33a3935036cf7c9cc81e7409f Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Mon, 26 Sep 2022 15:15:26 +0200 Subject: [PATCH 43/51] chore(ci): add Agola CI config --- .agola/config.yml | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .agola/config.yml diff --git a/.agola/config.yml b/.agola/config.yml new file mode 100644 index 0000000..237db17 --- /dev/null +++ b/.agola/config.yml @@ -0,0 +1,52 @@ +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 + - 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 \ No newline at end of file -- 2.45.2 From d8143ffd3aa5d9b072766fbe611452e994ffba01 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Mon, 26 Sep 2022 16:15:57 +0200 Subject: [PATCH 44/51] fix(tests): start container as part of test fixture --- .agola/config.yml | 1 + .../INetMock.Client.IntegrationTest.csproj | 1 + .../INetMockFixture.cs | 51 ++++++++++++++++--- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/.agola/config.yml b/.agola/config.yml index 237db17..4ae7e78 100644 --- a/.agola/config.yml +++ b/.agola/config.yml @@ -22,6 +22,7 @@ runs: 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: diff --git a/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj b/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj index 7df0678..fd30480 100644 --- a/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj +++ b/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj @@ -12,6 +12,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs b/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs index f4c6120..7379ce2 100644 --- a/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs +++ b/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs @@ -1,19 +1,56 @@ 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; -public class INetMockFixture +public class INetMockFixture : IAsyncLifetime { private const string DefaultINetMockSocketPath = "unix:///var/run/inetmock/inetmock.sock"; + private readonly ITestcontainersContainer _inetmockContainer; + + private readonly Stream _memStream = new MemoryStream(); + 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 TestcontainersBuilder() + .WithPrivileged(true) + .WithExposedPort(6767) + .WithPortBinding(6767, true) + .WithCreateContainerParametersModifier(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(); + } } -- 2.45.2 From d26b7ff041378838128f1d621ab0afbff6e7232e Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Mon, 26 Sep 2022 16:41:39 +0200 Subject: [PATCH 45/51] fix(ci): add GitVersion tool --- .config/dotnet-tools.json | 6 ++++++ build/Build.cs | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 5d8c576..5f7646a 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -13,6 +13,12 @@ "commands": [ "nuke" ] + }, + "gitversion.tool": { + "version": "5.10.3", + "commands": [ + "dotnet-gitversion" + ] } } } \ No newline at end of file diff --git a/build/Build.cs b/build/Build.cs index c691524..aa34697 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -25,7 +25,7 @@ class Build : NukeBuild [Solution] readonly Solution? Solution; [GitRepository] readonly GitRepository? GitRepository; - [GitVersion(NoFetch = true, Framework = "net6.0")] readonly GitVersion? GitVersion; + [GitVersion(Framework = "net6.0", NoFetch = true)] readonly GitVersion? GitVersion; GitLab? CI => GitLab.Instance; @@ -90,7 +90,7 @@ class Build : NukeBuild .SetProject(csproj) .SetConfiguration(Configuration) .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() .EnableIncludeSymbols() .EnableNoRestore() -- 2.45.2 From 2c45a41a0db5b964fd22caa14c699d9d71858f89 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Sun, 3 Jul 2022 07:04:22 +0000 Subject: [PATCH 46/51] Update dependency Nuke.Common to v6.1.2 --- build/_build.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/_build.csproj b/build/_build.csproj index c4263d3..398c479 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -13,7 +13,7 @@ - + -- 2.45.2 From 25ae369e6e2388f55dfa54370d99d3fa5daac8e8 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Sun, 3 Jul 2022 07:04:24 +0000 Subject: [PATCH 47/51] Update dependency nuke.globaltool to v6.1.2 --- .config/dotnet-tools.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 5f7646a..cb895fd 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -9,7 +9,7 @@ ] }, "nuke.globaltool": { - "version": "6.0.3", + "version": "6.1.2", "commands": [ "nuke" ] -- 2.45.2 From 222715b077169a11eff7c20c2835285d806c5ef8 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Mon, 26 Sep 2022 17:03:28 +0200 Subject: [PATCH 48/51] chore(deps): update to latest versions --- build/_build.csproj | 2 +- src/INetMock.Client/INetMock.Client.csproj | 8 ++++---- .../INetMock.Client.IntegrationTest.csproj | 6 +++--- tests/INetMock.Client.Test/INetMock.Client.Test.csproj | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build/_build.csproj b/build/_build.csproj index 398c479..ec393a2 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 1051980..04aedeb 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -9,10 +9,10 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj b/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj index fd30480..c03d1b0 100644 --- a/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj +++ b/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj @@ -11,10 +11,10 @@ - + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/INetMock.Client.Test/INetMock.Client.Test.csproj b/tests/INetMock.Client.Test/INetMock.Client.Test.csproj index 0d144c1..c03c65a 100644 --- a/tests/INetMock.Client.Test/INetMock.Client.Test.csproj +++ b/tests/INetMock.Client.Test/INetMock.Client.Test.csproj @@ -8,9 +8,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive -- 2.45.2 From 2061f6f684f28dc757f7db85bf6072a0afd77db8 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Fri, 15 Sep 2023 19:01:48 +0200 Subject: [PATCH 49/51] chore: update deps --- .editorconfig | 10 +++++++ .gitlab-ci.yml | 8 ++--- build/Build.cs | 13 ++++---- build/Configuration.cs | 5 +--- build/_build.csproj | 30 +++++++++---------- src/INetMock.Client/Audit/Event.cs | 1 - src/INetMock.Client/Audit/IEventReader.cs | 2 -- .../Audit/IProtoEventReader.cs | 1 - .../Audit/Serialization/ProtoReader.cs | 2 +- .../Audit/Serialization/TypedReader.cs | 12 ++++++-- src/INetMock.Client/INetMock.Client.csproj | 16 +++++----- .../PCAP/Client/PcapApiClient.cs | 18 +++++++++-- .../Audit/Serialization/TypedReaderTest.cs | 10 +++++-- .../INetMock.Client.IntegrationTest.csproj | 18 +++++------ .../INetMockFixture.cs | 7 ++--- .../PCAP/Client/PcapApiClientTests.cs | 4 +-- .../Audit/Serialization/GenericReaderTest.cs | 10 +++++-- .../Audit/Serialization/TypedReaderTest.cs | 10 +++++-- .../INetMock.Client.Test.csproj | 20 ++++++------- 19 files changed, 116 insertions(+), 81 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2a559ae..0202480 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,6 +14,16 @@ indent_size = 4 indent_size = 4 csharp_style_namespace_declarations = file_scoped: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 = never: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] indent_size = 2 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d648e81..4de04ea 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,10 +34,10 @@ test: done; after_script: - docker stop inetmock - variables: + variables: PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/docker INETMOCK_SOCKET: http://docker:6767 - script: + script: - dotnet tool restore - dotnet nuke Test @@ -45,7 +45,7 @@ protobuf-lint: stage: test image: name: docker.io/bufbuild/buf:latest - entrypoint: [""] + entrypoint: [ "" ] script: - cd api/proto/ - buf ls-files @@ -56,6 +56,6 @@ nuget-publish: only: refs: - tags - script: + script: - dotnet tool restore - dotnet nuke NuGetPush diff --git a/build/Build.cs b/build/Build.cs index aa34697..79f920f 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -2,7 +2,6 @@ using NuGet.Versioning; using Nuke.Common; using Nuke.Common.CI; using Nuke.Common.CI.GitLab; -using Nuke.Common.Execution; using Nuke.Common.Git; using Nuke.Common.IO; using Nuke.Common.ProjectModel; @@ -13,20 +12,19 @@ using Nuke.Common.Utilities.Collections; using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.Tools.DotNet.DotNetTasks; -[CheckBuildProjectConfigurations] [ShutdownDotNetAfterServerBuild] class Build : NukeBuild { - private const string NuGetSourceName = "GitLab"; - public static int Main() => Execute(x => x.Test); + const string NuGetSourceName = "GitLab"; [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; - [Solution] readonly Solution? Solution; [GitRepository] readonly GitRepository? GitRepository; [GitVersion(Framework = "net6.0", NoFetch = true)] readonly GitVersion? GitVersion; + [Solution] readonly Solution? Solution; + GitLab? CI => GitLab.Instance; @@ -90,7 +88,8 @@ class Build : NukeBuild .SetProject(csproj) .SetConfiguration(Configuration) .SetOutputDirectory(ArtifactsDirectory) - .SetVersion(GitVersion?.NuGetVersionV2 ?? SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToNormalizedString()) + .SetVersion(GitVersion?.NuGetVersionV2 ?? + SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToNormalizedString()) .EnableIncludeSource() .EnableIncludeSymbols() .EnableNoRestore() @@ -117,4 +116,6 @@ class Build : NukeBuild .SetSource(NuGetSourceName) .SetTargetPath(nupkg) .EnableProcessLogOutput()))); + + public static int Main() => Execute(x => x.Test); } diff --git a/build/Configuration.cs b/build/Configuration.cs index 78049f7..97663e9 100644 --- a/build/Configuration.cs +++ b/build/Configuration.cs @@ -7,8 +7,5 @@ public class Configuration : Enumeration public static Configuration Debug = new() { Value = nameof(Debug) }; public static Configuration Release = new() { Value = nameof(Release) }; - public static implicit operator string(Configuration configuration) - { - return configuration.Value; - } + public static implicit operator string(Configuration configuration) => configuration.Value; } diff --git a/build/_build.csproj b/build/_build.csproj index ec393a2..0dbad78 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -1,20 +1,20 @@ - - Exe - - CS0649;CS0169 - .. - .. - net6.0 - latest - 1 - enable - + + Exe + + CS0649;CS0169 + .. + .. + net6.0 + latest + 1 + enable + - - - - + + + + diff --git a/src/INetMock.Client/Audit/Event.cs b/src/INetMock.Client/Audit/Event.cs index 646d892..04a0b92 100644 --- a/src/INetMock.Client/Audit/Event.cs +++ b/src/INetMock.Client/Audit/Event.cs @@ -71,7 +71,6 @@ public record Event : EventBase where T : EventDetails, new() { public Event() { - } public Event(EventEntity entity) : base(entity) diff --git a/src/INetMock.Client/Audit/IEventReader.cs b/src/INetMock.Client/Audit/IEventReader.cs index 1e347f3..1bb5534 100644 --- a/src/INetMock.Client/Audit/IEventReader.cs +++ b/src/INetMock.Client/Audit/IEventReader.cs @@ -10,7 +10,6 @@ public interface IEventReader : IDisposable, IAsyncDisposable IAsyncEnumerable ReadAllAsync(CancellationToken token = default); /// - /// /// /// /// @@ -25,7 +24,6 @@ public interface IEventReader : IDisposable, IAsyncDisposable where T : Event IAsyncEnumerable> ReadAllAsync(CancellationToken token = default); /// - /// /// /// /// diff --git a/src/INetMock.Client/Audit/IProtoEventReader.cs b/src/INetMock.Client/Audit/IProtoEventReader.cs index 93d0cd9..4bb6edd 100644 --- a/src/INetMock.Client/Audit/IProtoEventReader.cs +++ b/src/INetMock.Client/Audit/IProtoEventReader.cs @@ -1,7 +1,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Inetmock.Audit.V1; namespace INetMock.Client.Audit; diff --git a/src/INetMock.Client/Audit/Serialization/ProtoReader.cs b/src/INetMock.Client/Audit/Serialization/ProtoReader.cs index c6728cf..d58c90d 100644 --- a/src/INetMock.Client/Audit/Serialization/ProtoReader.cs +++ b/src/INetMock.Client/Audit/Serialization/ProtoReader.cs @@ -9,9 +9,9 @@ namespace INetMock.Client.Audit.Serialization; public sealed class ProtoReader : IProtoEventReader { + private readonly bool _keepStreamOpen; private readonly MemoryPool _memoryPool; private readonly Stream _sourceStream; - private readonly bool _keepStreamOpen; public ProtoReader(Stream sourceStream, bool keepStreamOpen = false) { diff --git a/src/INetMock.Client/Audit/Serialization/TypedReader.cs b/src/INetMock.Client/Audit/Serialization/TypedReader.cs index 4c0127f..70da03d 100644 --- a/src/INetMock.Client/Audit/Serialization/TypedReader.cs +++ b/src/INetMock.Client/Audit/Serialization/TypedReader.cs @@ -27,8 +27,8 @@ public enum DropMode public sealed class TypedReader : IEventReader where T : EventDetails, new() { - private readonly IProtoEventReader _reader; private readonly DropMode _dropMode; + private readonly IProtoEventReader _reader; public TypedReader(IProtoEventReader reader, DropMode dropMode = DropMode.DropDetails) { @@ -76,7 +76,13 @@ public sealed class TypedReader : IEventReader where T : EventDetails, new } while (true); } - public void Dispose() => _reader.Dispose(); + public void Dispose() + { + _reader.Dispose(); + } - public ValueTask DisposeAsync() => _reader.DisposeAsync(); + public ValueTask DisposeAsync() + { + return _reader.DisposeAsync(); + } } diff --git a/src/INetMock.Client/INetMock.Client.csproj b/src/INetMock.Client/INetMock.Client.csproj index 04aedeb..30164b6 100644 --- a/src/INetMock.Client/INetMock.Client.csproj +++ b/src/INetMock.Client/INetMock.Client.csproj @@ -5,20 +5,20 @@ latest - - + + - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/src/INetMock.Client/PCAP/Client/PcapApiClient.cs b/src/INetMock.Client/PCAP/Client/PcapApiClient.cs index 38f7344..544fd98 100644 --- a/src/INetMock.Client/PCAP/Client/PcapApiClient.cs +++ b/src/INetMock.Client/PCAP/Client/PcapApiClient.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Google.Protobuf.WellKnownTypes; using Grpc.Core; using Grpc.Net.Client; -using ChannelFactory = INetMock.Client.Grpc.ChannelFactory; +using INetMock.Client.Grpc; namespace INetMock.Client.PCAP.Client; @@ -32,7 +32,13 @@ public class PcapApiClient : IPcapApiClient public async Task> 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 .Select(d => new RecordingDevice( d.Name, @@ -46,7 +52,13 @@ public class PcapApiClient : IPcapApiClient public async Task> 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 .Select(consumerKey => new Subscription(consumerKey)) .ToList(); diff --git a/tests/INetMock.Client.IntegrationTest/Audit/Serialization/TypedReaderTest.cs b/tests/INetMock.Client.IntegrationTest/Audit/Serialization/TypedReaderTest.cs index 274bbc9..f803162 100644 --- a/tests/INetMock.Client.IntegrationTest/Audit/Serialization/TypedReaderTest.cs +++ b/tests/INetMock.Client.IntegrationTest/Audit/Serialization/TypedReaderTest.cs @@ -20,6 +20,7 @@ public class TypedReaderTest Assert.NotNull(ev); count++; } + Assert.True(count > 0); } @@ -27,7 +28,8 @@ public class TypedReaderTest public async Task Test_ReadAllAsync_DropEntity_AuditFile_HTTPEvents() { await using var fileStream = File.OpenRead(Path.Join("testdata", "test.ima")); - await using IEventReader httpReader = new TypedReader(new ProtoReader(fileStream), DropMode.DropEntity); + await using IEventReader httpReader = + new TypedReader(new ProtoReader(fileStream), DropMode.DropEntity); var count = 0; await foreach (var ev in httpReader.ReadAllAsync()) @@ -36,6 +38,7 @@ public class TypedReaderTest Assert.NotNull(ev.Details); count++; } + Assert.True(count > 0); } @@ -51,6 +54,7 @@ public class TypedReaderTest Assert.NotNull(ev); count++; } + Assert.True(count > 0); } @@ -58,7 +62,8 @@ public class TypedReaderTest public async Task Test_ReadAllAsync_DropEntity_AuditFile_DNSEvents() { await using var fileStream = File.OpenRead(Path.Join("testdata", "test.ima")); - await using IEventReader httpReader = new TypedReader(new ProtoReader(fileStream), DropMode.DropEntity); + await using IEventReader httpReader = + new TypedReader(new ProtoReader(fileStream), DropMode.DropEntity); var count = 0; await foreach (var ev in httpReader.ReadAllAsync()) @@ -66,6 +71,7 @@ public class TypedReaderTest Assert.NotNull(ev); count++; } + Assert.True(count > 0); } } diff --git a/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj b/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj index c03d1b0..bc77eec 100644 --- a/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj +++ b/tests/INetMock.Client.IntegrationTest/INetMock.Client.IntegrationTest.csproj @@ -11,27 +11,27 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + - - PreserveNewest - + + PreserveNewest + diff --git a/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs b/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs index 7379ce2..dee07f7 100644 --- a/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs +++ b/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs @@ -11,7 +11,7 @@ namespace INetMock.Client.IntegrationTest; public class INetMockFixture : IAsyncLifetime { private const string DefaultINetMockSocketPath = "unix:///var/run/inetmock/inetmock.sock"; - private readonly ITestcontainersContainer _inetmockContainer; + private readonly IContainer _inetmockContainer; private readonly Stream _memStream = new MemoryStream(); @@ -20,12 +20,11 @@ public class INetMockFixture : IAsyncLifetime { AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - - _inetmockContainer = new TestcontainersBuilder() + _inetmockContainer = new ContainerBuilder() .WithPrivileged(true) .WithExposedPort(6767) .WithPortBinding(6767, true) - .WithCreateContainerParametersModifier(parameters => { parameters.User = "root"; }) + .WithCreateParameterModifier(parameters => { parameters.User = "root"; }) .WithEnvironment("INETMOCK_API_LISTEN", "tcp://0.0.0.0:6767") .WithImage("registry.gitlab.com/inetmock/inetmock:latest") .WithName("inetmock") diff --git a/tests/INetMock.Client.IntegrationTest/PCAP/Client/PcapApiClientTests.cs b/tests/INetMock.Client.IntegrationTest/PCAP/Client/PcapApiClientTests.cs index bf135d1..4073f7d 100644 --- a/tests/INetMock.Client.IntegrationTest/PCAP/Client/PcapApiClientTests.cs +++ b/tests/INetMock.Client.IntegrationTest/PCAP/Client/PcapApiClientTests.cs @@ -8,8 +8,8 @@ namespace INetMock.Client.IntegrationTest.PCAP.Client; public class PcapApiClientTests : IClassFixture { - private readonly ITestOutputHelper _outputHelper; private readonly IPcapApiClient _apiClient; + private readonly ITestOutputHelper _outputHelper; public PcapApiClientTests(ITestOutputHelper testOutputHelper, INetMockFixture inetMockFixture) { @@ -48,7 +48,7 @@ public class PcapApiClientTests : IClassFixture } 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(); Assert.Contains(subscriptions, subscription => diff --git a/tests/INetMock.Client.Test/Audit/Serialization/GenericReaderTest.cs b/tests/INetMock.Client.Test/Audit/Serialization/GenericReaderTest.cs index 80c20f3..a2dbad0 100644 --- a/tests/INetMock.Client.Test/Audit/Serialization/GenericReaderTest.cs +++ b/tests/INetMock.Client.Test/Audit/Serialization/GenericReaderTest.cs @@ -8,11 +8,15 @@ namespace INetMock.Client.Test.Audit.Serialization; public class GenericReaderTest { - private const string HttpEventPayload = "000000a7120b088092b8c398feffffff01180120022a047f00000132047f00000138d8fc0140504a3308041224544c535f45434448455f45434453415f574954485f4145535f3235365f4342435f5348411a096c6f63616c686f7374a2014c080112096c6f63616c686f73741a15687474703a2f2f6c6f63616c686f73742f6173646622084854545020312e312a1c0a0641636365707412120a106170706c69636174696f6e2f6a736f6e"; - private const string DnsEventPayload = "0000004e120b088092b8c398feffffff01180220012a100000000000000000000000000000000132100000000000000000000000000000000138d8fc014050aa0110120e0801120a6769746c61622e636f6d"; + private const string HttpEventPayload = + "000000a7120b088092b8c398feffffff01180120022a047f00000132047f00000138d8fc0140504a3308041224544c535f45434448455f45434453415f574954485f4145535f3235365f4342435f5348411a096c6f63616c686f7374a2014c080112096c6f63616c686f73741a15687474703a2f2f6c6f63616c686f73742f6173646622084854545020312e312a1c0a0641636365707412120a106170706c69636174696f6e2f6a736f6e"; + + private const string DnsEventPayload = + "0000004e120b088092b8c398feffffff01180220012a100000000000000000000000000000000132100000000000000000000000000000000138d8fc014050aa0110120e0801120a6769746c61622e636f6d"; + + private readonly byte[] _dnsEventPayloadBytes; private readonly byte[] _httpEventPayloadBytes; - private readonly byte[] _dnsEventPayloadBytes; public GenericReaderTest() { diff --git a/tests/INetMock.Client.Test/Audit/Serialization/TypedReaderTest.cs b/tests/INetMock.Client.Test/Audit/Serialization/TypedReaderTest.cs index f638ff3..2ce4ace 100644 --- a/tests/INetMock.Client.Test/Audit/Serialization/TypedReaderTest.cs +++ b/tests/INetMock.Client.Test/Audit/Serialization/TypedReaderTest.cs @@ -8,11 +8,15 @@ namespace INetMock.Client.Test.Audit.Serialization; public class TypedReaderTest { - private const string HttpEventPayload = "000000e5120b088092b8c398feffffff01180120022a047f00000132047f00000138d8fc0140504a3308041224544c535f45434448455f45434453415f574954485f4145535f3235365f4342435f5348411a096c6f63616c686f7374528a010a3c747970652e676f6f676c65617069732e636f6d2f696e65746d6f636b2e61756469742e64657461696c732e4854545044657461696c73456e74697479124a12096c6f63616c686f73741a15687474703a2f2f6c6f63616c686f73742f6173646622084854545020312e312a1c0a0641636365707412120a106170706c69636174696f6e2f6a736f6e"; - private const string DnsEventPayload = "0000003b120b088092b8c398feffffff01180120012a100000000000000000000000000000000132100000000000000000000000000000000138d8fc014050"; + private const string HttpEventPayload = + "000000e5120b088092b8c398feffffff01180120022a047f00000132047f00000138d8fc0140504a3308041224544c535f45434448455f45434453415f574954485f4145535f3235365f4342435f5348411a096c6f63616c686f7374528a010a3c747970652e676f6f676c65617069732e636f6d2f696e65746d6f636b2e61756469742e64657461696c732e4854545044657461696c73456e74697479124a12096c6f63616c686f73741a15687474703a2f2f6c6f63616c686f73742f6173646622084854545020312e312a1c0a0641636365707412120a106170706c69636174696f6e2f6a736f6e"; + + private const string DnsEventPayload = + "0000003b120b088092b8c398feffffff01180120012a100000000000000000000000000000000132100000000000000000000000000000000138d8fc014050"; + + private readonly byte[] _dnsEventPayloadBytes; private readonly byte[] _httpEventPayloadBytes; - private readonly byte[] _dnsEventPayloadBytes; public TypedReaderTest() { diff --git a/tests/INetMock.Client.Test/INetMock.Client.Test.csproj b/tests/INetMock.Client.Test/INetMock.Client.Test.csproj index c03c65a..facbef4 100644 --- a/tests/INetMock.Client.Test/INetMock.Client.Test.csproj +++ b/tests/INetMock.Client.Test/INetMock.Client.Test.csproj @@ -8,20 +8,20 @@ - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive - - all - runtime; build; native; contentfiles; analyzers; buildtransitive + + all + runtime; build; native; contentfiles; analyzers; buildtransitive - + - + -- 2.45.2 From 980414b794155778559ddd51ae0c4acf7481e039 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Fri, 15 Sep 2023 19:40:34 +0200 Subject: [PATCH 50/51] ci: migrate to Drone CI --- .drone.yml | 24 ++++++++++++++++ .gitlab-ci.yml | 61 ----------------------------------------- .nuke/build.schema.json | 9 +++--- INetMock.sln | 1 - build/_build.csproj | 4 +++ 5 files changed, 33 insertions(+), 66 deletions(-) create mode 100644 .drone.yml delete mode 100644 .gitlab-ci.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..57701a7 --- /dev/null +++ b/.drone.yml @@ -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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 4de04ea..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -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 diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 1828fb1..a311343 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -1,7 +1,7 @@ { "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Build Schema", "$ref": "#/definitions/build", + "title": "Build Schema", "definitions": { "build": { "type": "object", @@ -29,6 +29,7 @@ "AppVeyor", "AzurePipelines", "Bamboo", + "Bitbucket", "Bitrise", "GitHubActions", "GitLab", @@ -38,8 +39,8 @@ "TeamCity", "Terminal", "TravisCI", - "VisualStudio", - "VSCode" + "VSCode", + "VisualStudio" ] }, "NoLogo": { @@ -116,4 +117,4 @@ } } } -} \ No newline at end of file +} diff --git a/INetMock.sln b/INetMock.sln index 4f156f3..57e7881 100644 --- a/INetMock.sln +++ b/INetMock.sln @@ -7,7 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig .gitignore = .gitignore - .gitlab-ci.yml = .gitlab-ci.yml .pre-commit-config.yaml = .pre-commit-config.yaml README.md = README.md global.json = global.json diff --git a/build/_build.csproj b/build/_build.csproj index 0dbad78..18299d1 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -17,4 +17,8 @@ + + + + -- 2.45.2 From b642b7bc9bb3ab40ee2bfc1bbcfdf8f8ade97de2 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Sun, 17 Sep 2023 11:12:17 +0200 Subject: [PATCH 51/51] refactor: use Husky.NET instead of pre-commit --- .config/dotnet-tools.json | 18 +++++-- .editorconfig | 3 +- .husky/pre-commit | 4 ++ .husky/task-runner.json | 34 ++++++++++++ .pre-commit-config.yaml | 13 ----- INetMock.sln | 1 - .../Audit/Client/AuditApiClient.cs | 6 +-- .../Audit/Serialization/GenericReader.cs | 5 +- .../Audit/Serialization/TypedReader.cs | 10 +--- .../INetMockFixture.cs | 5 +- tests/INetMock.Client.Test/Hex/Converter.cs | 6 +-- .../INetMock.Client.Test.csproj | 54 +++++++++---------- 12 files changed, 91 insertions(+), 68 deletions(-) create mode 100755 .husky/pre-commit create mode 100644 .husky/task-runner.json delete mode 100644 .pre-commit-config.yaml diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index cb895fd..e919e28 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,22 +3,34 @@ "isRoot": true, "tools": { "dotnet-grpc": { - "version": "2.46.0", + "version": "2.57.0", "commands": [ "dotnet-grpc" ] }, "nuke.globaltool": { - "version": "6.1.2", + "version": "7.0.5", "commands": [ "nuke" ] }, "gitversion.tool": { - "version": "5.10.3", + "version": "5.12.0", "commands": [ "dotnet-gitversion" ] + }, + "husky": { + "version": "0.6.1", + "commands": [ + "husky" + ] + }, + "jetbrains.resharper.globaltools": { + "version": "2023.2.1", + "commands": [ + "jb" + ] } } } \ No newline at end of file diff --git a/.editorconfig b/.editorconfig index 0202480..7236ae2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,6 +6,7 @@ end_of_line = lf charset = utf-8 insert_final_newline = true max_line_length = 120 +indent_size = 4 [*.xml] indent_size = 4 @@ -18,7 +19,7 @@ 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 = never:warning +dotnet_style_require_accessibility_modifiers = omit_if_default:warning csharp_style_expression_bodied_methods = true:silent csharp_style_expression_bodied_properties = true:warning diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..6937b36 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +dotnet husky run --group pre-commit diff --git a/.husky/task-runner.json b/.husky/task-runner.json new file mode 100644 index 0000000..4f173be --- /dev/null +++ b/.husky/task-runner.json @@ -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" + ] + } + ] +} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 9cbe814..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -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 diff --git a/INetMock.sln b/INetMock.sln index 57e7881..dca24f4 100644 --- a/INetMock.sln +++ b/INetMock.sln @@ -7,7 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig .gitignore = .gitignore - .pre-commit-config.yaml = .pre-commit-config.yaml README.md = README.md global.json = global.json EndProjectSection diff --git a/src/INetMock.Client/Audit/Client/AuditApiClient.cs b/src/INetMock.Client/Audit/Client/AuditApiClient.cs index 0d5113d..d1ecd62 100644 --- a/src/INetMock.Client/Audit/Client/AuditApiClient.cs +++ b/src/INetMock.Client/Audit/Client/AuditApiClient.cs @@ -48,9 +48,9 @@ public class AuditApiClient : IAuditApiClient public async Task RemoveFileSinkAsync(string targetPath, CancellationToken token = default) { var resp = await _auditClient.RemoveFileSinkAsync(new RemoveFileSinkRequest - { - TargetPath = targetPath - }, + { + TargetPath = targetPath + }, Metadata.Empty, null, token diff --git a/src/INetMock.Client/Audit/Serialization/GenericReader.cs b/src/INetMock.Client/Audit/Serialization/GenericReader.cs index 9682a61..110f0fb 100644 --- a/src/INetMock.Client/Audit/Serialization/GenericReader.cs +++ b/src/INetMock.Client/Audit/Serialization/GenericReader.cs @@ -37,8 +37,5 @@ public sealed class GenericReader : IEventReader public ValueTask DisposeAsync() => _reader.DisposeAsync(); - public void Dispose() - { - _reader.Dispose(); - } + public void Dispose() => _reader.Dispose(); } diff --git a/src/INetMock.Client/Audit/Serialization/TypedReader.cs b/src/INetMock.Client/Audit/Serialization/TypedReader.cs index 70da03d..1a7c080 100644 --- a/src/INetMock.Client/Audit/Serialization/TypedReader.cs +++ b/src/INetMock.Client/Audit/Serialization/TypedReader.cs @@ -76,13 +76,7 @@ public sealed class TypedReader : IEventReader where T : EventDetails, new } while (true); } - public void Dispose() - { - _reader.Dispose(); - } + public void Dispose() => _reader.Dispose(); - public ValueTask DisposeAsync() - { - return _reader.DisposeAsync(); - } + public ValueTask DisposeAsync() => _reader.DisposeAsync(); } diff --git a/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs b/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs index dee07f7..11c73e4 100644 --- a/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs +++ b/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs @@ -48,8 +48,5 @@ public class INetMockFixture : IAsyncLifetime INetMockSocketPath = $"http://{_inetmockContainer.Hostname}:{_inetmockContainer.GetMappedPublicPort(6767)}"; } - public async Task DisposeAsync() - { - await _inetmockContainer.StopAsync(); - } + public async Task DisposeAsync() => await _inetmockContainer.StopAsync(); } diff --git a/tests/INetMock.Client.Test/Hex/Converter.cs b/tests/INetMock.Client.Test/Hex/Converter.cs index d34abac..cd5d785 100644 --- a/tests/INetMock.Client.Test/Hex/Converter.cs +++ b/tests/INetMock.Client.Test/Hex/Converter.cs @@ -5,11 +5,9 @@ namespace INetMock.Client.Test.Hex; public static class Converter { - public static byte[] HexToByteArray(this string hex) - { - return Enumerable.Range(0, hex.Length) + public static byte[] HexToByteArray(this string hex) => + Enumerable.Range(0, hex.Length) .Where(x => x % 2 == 0) .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) .ToArray(); - } } diff --git a/tests/INetMock.Client.Test/INetMock.Client.Test.csproj b/tests/INetMock.Client.Test/INetMock.Client.Test.csproj index facbef4..c9c1f6e 100644 --- a/tests/INetMock.Client.Test/INetMock.Client.Test.csproj +++ b/tests/INetMock.Client.Test/INetMock.Client.Test.csproj @@ -1,27 +1,27 @@ - - - - net6.0 - false - latest - enable - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - + + + net6.0 + false + latest + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + \ No newline at end of file -- 2.45.2