Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into renovate/nunit-4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
kayoub5 committed Mar 2, 2025
2 parents 4ae1178 + 4e9464d commit f6ab2f8
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 26 deletions.
5 changes: 0 additions & 5 deletions Test/RemotePcapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using static Test.TestHelper;
using System.ComponentModel;
using CategoryAttribute = NUnit.Framework.CategoryAttribute;
using System.Runtime.Versioning;

namespace Test
{
Expand Down Expand Up @@ -64,10 +63,6 @@ public void NpcapDeviceListNullAuthTest()
/// if the test gets too long, it would be moved to its own file
/// </summary>
[Test]
[Platform("Win")]
#if NET
[SupportedOSPlatform("windows")]
#endif
public void PwdAuthTest()
{
try
Expand Down
4 changes: 3 additions & 1 deletion Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ SPDX-License-Identifier: MIT
<CoverletOutputFormat>opencover</CoverletOutputFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Mono.Posix" Version="7.1.0-final.1.21458.1" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.4.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.6.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="JunitXml.TestLogger" Version="6.0.0" />
Expand Down
74 changes: 57 additions & 17 deletions Test/TestUser.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,83 @@
// Copyright 2020-2021 Ayoub Kaanich <[email protected]>
// SPDX-License-Identifier: MIT

using NUnit.Framework;
using System;
using System.Diagnostics;
using System.DirectoryServices.AccountManagement;
using System.Runtime.Versioning;
using System.Runtime.InteropServices;

namespace Test
{
#if NET
[SupportedOSPlatform("windows")]
#endif
public static class TestUser
{
public const string Username = "SharpPcap.Test.User";
public const string Username = "sharppcaptestuser";
public const string Password = "password";

public static bool Create()
{
try
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Delete();
var ctx = new PrincipalContext(ContextType.Machine);
using (var user = new UserPrincipal(ctx, Username, Password, true))
try
{
user.Save();
Delete();
var ctx = new PrincipalContext(ContextType.Machine);
using (var user = new UserPrincipal(ctx, Username, Password, true))
{
user.Save();
}
return true;
}
catch (PrincipalException)
{
return false;
}
return true;
}
catch (PrincipalException)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return false;
Bash("useradd", Username, "--groups", "sudo");
Bash("bash", "-c", $"\"echo -e {Username}:{Password} | chpasswd\"");
}
// OS not supported
return false;
}

private static void Bash(string cmd, params string[] args)
{
var arguments = string.Join(" ", args);
var info = new ProcessStartInfo
{
FileName = cmd,
Arguments = arguments,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
var process = Process.Start(info);

process.OutputDataReceived += (s, e) => Console.Out.WriteLine(e.Data);
process.ErrorDataReceived += (s, e) => Console.Error.WriteLine(e.Data);

process.BeginOutputReadLine();
process.BeginErrorReadLine();
if (!process.WaitForExit(10000))
{
throw new TimeoutException($"Command '{cmd} {arguments}' timed out");
}
Assert.That(process.ExitCode, Is.Zero);
}

public static void Delete()
{
var ctx = new PrincipalContext(ContextType.Machine);
var user = UserPrincipal.FindByIdentity(ctx, Username);
user?.Delete();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var ctx = new PrincipalContext(ContextType.Machine);
var user = UserPrincipal.FindByIdentity(ctx, Username);
user?.Delete();
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Bash("userdel", Username);
}
}
}
}
4 changes: 2 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ codecov:
# Allow collecting coverage even if some CIs fail
require_ci_to_pass: false
notify:
# 4 for appveyor
# 3 for appveyor
# 3 for azure pipelines
# 1 for circleci
# Total = 8
# Tolerate one of the services being down (worst case appveyor)
after_n_builds: 4
after_n_builds: 3
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Copyright 2023 Ayoub Kaanich <[email protected]>
# SPDX-License-Identifier: MIT
reuse==5.0.0
reuse==5.0.2

0 comments on commit f6ab2f8

Please sign in to comment.