initial commit
This commit is contained in:
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,24 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Pulsar.Common.Video.Compression;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Pulsar.Common.Tests.Compression
|
||||
{
|
||||
[TestClass]
|
||||
public class JpgCompressionTests
|
||||
{
|
||||
[TestMethod, TestCategory("Compression")]
|
||||
public void CompressionTest()
|
||||
{
|
||||
var quality = Int64.MaxValue;
|
||||
var jpg = new JpgCompression(quality);
|
||||
var bitmap = new Bitmap(200, 200);
|
||||
|
||||
var result = jpg.Compress(bitmap);
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
CollectionAssert.AllItemsAreNotNull(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Pulsar.Common.Cryptography;
|
||||
using Pulsar.Common.Helpers;
|
||||
using System.Text;
|
||||
|
||||
namespace Pulsar.Common.Tests.Cryptography
|
||||
{
|
||||
[TestClass]
|
||||
public class Aes128Tests
|
||||
{
|
||||
[TestMethod, TestCategory("Cryptography")]
|
||||
public void EncryptAndDecryptStringTest()
|
||||
{
|
||||
var input = StringHelper.GetRandomString(100);
|
||||
var password = StringHelper.GetRandomString(50);
|
||||
|
||||
var aes = new Aes256(password);
|
||||
|
||||
var encrypted = aes.Encrypt(input);
|
||||
|
||||
Assert.IsNotNull(encrypted);
|
||||
Assert.AreNotEqual(encrypted, input);
|
||||
|
||||
var decrypted = aes.Decrypt(encrypted);
|
||||
|
||||
Assert.AreEqual(input, decrypted);
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("Cryptography")]
|
||||
public void EncryptAndDecryptByteArrayTest()
|
||||
{
|
||||
var input = StringHelper.GetRandomString(100);
|
||||
var inputByte = Encoding.UTF8.GetBytes(input);
|
||||
var password = StringHelper.GetRandomString(50);
|
||||
|
||||
var aes = new Aes256(password);
|
||||
|
||||
var encryptedByte = aes.Encrypt(inputByte);
|
||||
|
||||
Assert.IsNotNull(encryptedByte);
|
||||
CollectionAssert.AllItemsAreNotNull(encryptedByte);
|
||||
CollectionAssert.AreNotEqual(encryptedByte, inputByte);
|
||||
|
||||
var decryptedByte = aes.Decrypt(encryptedByte);
|
||||
|
||||
CollectionAssert.AreEqual(inputByte, decryptedByte);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Pulsar.Common.Cryptography;
|
||||
using Pulsar.Common.Helpers;
|
||||
|
||||
namespace Pulsar.Common.Tests.Cryptography
|
||||
{
|
||||
[TestClass]
|
||||
public class Sha256Tests
|
||||
{
|
||||
[TestMethod, TestCategory("Cryptography")]
|
||||
public void ComputeHashTest()
|
||||
{
|
||||
var input = StringHelper.GetRandomString(100);
|
||||
var result = Sha256.ComputeHash(input);
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreNotEqual(result, input);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Pulsar.Common.Helpers;
|
||||
|
||||
namespace Pulsar.Common.Tests.Helpers
|
||||
{
|
||||
[TestClass]
|
||||
public class FileHelperTests
|
||||
{
|
||||
[TestMethod, TestCategory("Helpers")]
|
||||
public void RandomFilenameTest()
|
||||
{
|
||||
int length = 100;
|
||||
var name = FileHelper.GetRandomFilename(length);
|
||||
|
||||
Assert.IsNotNull(name);
|
||||
Assert.IsTrue(name.Length == length);
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("Helpers")]
|
||||
public void ValidateExecutableTest()
|
||||
{
|
||||
var bytes = new byte[] { 77, 90 };
|
||||
|
||||
Assert.IsTrue(FileHelper.HasExecutableIdentifier(bytes));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("Helpers")]
|
||||
public void ValidateExecutableTest2()
|
||||
{
|
||||
var bytes = new byte[] { 22, 93 };
|
||||
|
||||
Assert.IsFalse(FileHelper.HasExecutableIdentifier(bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Pulsar.Common.Messages.Other;
|
||||
using Pulsar.Common.Networking;
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace Pulsar.Common.Tests.Networking
|
||||
{
|
||||
[TestClass]
|
||||
public class SecureMessageEnvelopeTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void WrapAndUnwrap_RoundTrip_ReturnsOriginalMessage()
|
||||
{
|
||||
using (var rsa = RSA.Create(2048))
|
||||
{
|
||||
var request = new CertificateRequest("CN=SecureMessageEnvelopeTests", rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||
using (var certificate = request.CreateSelfSigned(DateTimeOffset.UtcNow.AddDays(-1), DateTimeOffset.UtcNow.AddDays(30)))
|
||||
{
|
||||
var original = new ClientIdentification
|
||||
{
|
||||
Version = "1.0",
|
||||
OperatingSystem = "Windows",
|
||||
AccountType = "Admin",
|
||||
Country = "Wonderland",
|
||||
CountryCode = "WL",
|
||||
ImageIndex = 3,
|
||||
Id = new string('A', 64),
|
||||
Username = "tester",
|
||||
PcName = "test-pc",
|
||||
Tag = "tag",
|
||||
EncryptionKey = "key",
|
||||
Signature = new byte[] { 0x01, 0x02, 0x03 },
|
||||
PublicIP = "127.0.0.1"
|
||||
};
|
||||
|
||||
var envelope = SecureMessageEnvelopeHelper.Wrap(original, certificate);
|
||||
|
||||
Assert.IsNotNull(envelope);
|
||||
Assert.IsNotNull(envelope.Payload);
|
||||
Assert.AreNotEqual(0, envelope.Payload.Length);
|
||||
|
||||
var roundTrip = SecureMessageEnvelopeHelper.Unwrap(envelope, certificate) as ClientIdentification;
|
||||
|
||||
Assert.IsNotNull(roundTrip);
|
||||
Assert.AreEqual(original.Username, roundTrip.Username);
|
||||
Assert.AreEqual(original.Id, roundTrip.Id);
|
||||
Assert.AreEqual(original.PublicIP, roundTrip.PublicIP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("Pulsar Common Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Pulsar")]
|
||||
[assembly: AssemblyCopyright("Copyright © PulsarTeam 2025")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
[assembly: Guid("cfda6d2e-8ab3-4349-b89a-33e1f0dab32b")]
|
||||
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.4.5")]
|
||||
[assembly: AssemblyFileVersion("2.4.5")]
|
||||
@@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<Configurations>Debug;Release;ReleaseWithDonut</Configurations>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<OutputPath>..\bin\Debug\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<OutputPath>..\bin\Release\</OutputPath>
|
||||
<DebugType>none</DebugType>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithDonut|AnyCPU'">
|
||||
<OutputPath>..\bin\Release\</OutputPath>
|
||||
<DebugType>none</DebugType>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="9.0.7" />
|
||||
<PackageReference Include="System.Security.Cryptography.X509Certificates" Version="4.3.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pulsar.Common\Pulsar.Common.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user