Skip to content

Commit cbcb7c8

Browse files
author
Lee Fine
committed
initial-integration-tests
1 parent a4e3f34 commit cbcb7c8

File tree

5 files changed

+46
-14
lines changed

5 files changed

+46
-14
lines changed

RemoteFileIntegrationTests/BaseRFPEMTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private void CreateCertificateAndKey()
4444
AsymmetricCipherKeyPair keyPair = keyGen.GenerateKeyPair();
4545

4646
// Define certificate attributes
47-
var certName = new X509Name(Environment.GetEnvironmentVariable("CertificateSubjectDN"));
47+
var certName = new X509Name(EnvironmentVariables.CertificateSubjectDN);
4848
BigInteger serialNumber = BigInteger.ProbablePrime(120, new Random());
4949

5050
// Validity period

RemoteFileIntegrationTests/BaseTest.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ public BaseTest()
4747
if (Connection != null)
4848
return;
4949

50-
string userId = Environment.GetEnvironmentVariable("LinuxUserId")!;
50+
string userId = EnvironmentVariables.LinuxUserId!;
5151
KeyboardInteractiveAuthenticationMethod keyboardAuthentication = new KeyboardInteractiveAuthenticationMethod(userId);
52-
Connection = new ConnectionInfo(Environment.GetEnvironmentVariable("LinuxServer"), userId, new PasswordAuthenticationMethod(userId, Environment.GetEnvironmentVariable("LinuxUserPassword")), keyboardAuthentication);
53-
Client = new SshClient(Connection);
52+
Connection = new ConnectionInfo(EnvironmentVariables.LinuxServer, userId, new PasswordAuthenticationMethod(userId, EnvironmentVariables.LinuxUserPassword), keyboardAuthentication);
5453

5554
SetUp();
5655
}
@@ -104,7 +103,7 @@ private void CreateFileLinux(string fileName, byte[] contents)
104103

105104
using (MemoryStream stream = new MemoryStream(contents))
106105
{
107-
client.Upload(stream, Environment.GetEnvironmentVariable("LinuxStorePath") + fileName);
106+
client.Upload(stream, EnvironmentVariables.LinuxStorePath + fileName);
108107
}
109108
}
110109
finally
@@ -127,7 +126,7 @@ private void RemoveFileLinux(string fileName)
127126
{
128127
client.OperationTimeout = System.TimeSpan.FromSeconds(60);
129128
client.Connect();
130-
client.DeleteFile(Environment.GetEnvironmentVariable("LinuxStorePath") + fileName);
129+
client.DeleteFile(EnvironmentVariables.LinuxStorePath + fileName);
131130
}
132131
finally
133132
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace RemoteFileIntegrationTests
8+
{
9+
internal class EnvironmentVariables
10+
{
11+
public static string? LinuxServer { get { return Environment.GetEnvironmentVariable("LinuxServer"); } }
12+
public static string? LinuxStorePath { get { return Environment.GetEnvironmentVariable("LinuxStorePath"); } }
13+
public static string? LinuxUserId { get { return Environment.GetEnvironmentVariable("LinuxUserId"); } }
14+
public static string? LinuxUserPassword { get { return Environment.GetEnvironmentVariable("LinuxUserPassword"); } }
15+
public static string? WindowsServer { get { return Environment.GetEnvironmentVariable("WindowsServer"); } }
16+
public static string? WindowsStorePath { get { return Environment.GetEnvironmentVariable("WindowsStorePath"); } }
17+
public static string? StorePassword { get { return Environment.GetEnvironmentVariable("StorePassword"); } }
18+
public static string? CertificateSubjectDN { get { return Environment.GetEnvironmentVariable("CertificateSubjectDN"); } }
19+
}
20+
}

RemoteFileIntegrationTests/RFPEMInventoryTests.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
using Keyfactor.Orchestrators.Common.Enums;
33
using Keyfactor.Orchestrators.Extensions;
44
using Keyfactor.Orchestrators.Extensions.Interfaces;
5+
56
using Moq;
67

8+
using Org.BouncyCastle.X509;
9+
using Org.BouncyCastle.Utilities.IO.Pem;
10+
711
namespace RemoteFileIntegrationTests
812
{
913
public class RFPEMInventoryTests : BaseRFPEMTest
@@ -12,11 +16,11 @@ public class RFPEMInventoryTests : BaseRFPEMTest
1216
public void RFPEM_Inventory_InternalPrivateKey_EmptyStore_Linux_Test0001()
1317
{
1418
InventoryJobConfiguration config = BuildBaseInventoryConfig();
15-
config.CertificateStoreDetails.ClientMachine = Environment.GetEnvironmentVariable("LinuxServer");
16-
config.CertificateStoreDetails.StorePath = Environment.GetEnvironmentVariable("LinuxStorePath");
19+
config.CertificateStoreDetails.ClientMachine = EnvironmentVariables.LinuxServer;
20+
config.CertificateStoreDetails.StorePath = EnvironmentVariables.LinuxStorePath;
1721
config.CertificateStoreDetails.Properties = "{}";
1822
//config.CertificateStoreDetails.Properties = JsonConvert.SerializeObject(new Dictionary<string, string?>() { { "SeparatePrivateKeyFilePath", Environment.GetEnvironmentVariable("LinuxStorePath") + "Test0001.key" } });
19-
config.CertificateStoreDetails.ClientMachine = Environment.GetEnvironmentVariable("LinuxServer");
23+
config.CertificateStoreDetails.ClientMachine = EnvironmentVariables.LinuxServer;
2024

2125
Mock<IPAMSecretResolver> secretResolver = GetMockSecretResolver(config);
2226

@@ -30,7 +34,16 @@ public void RFPEM_Inventory_InternalPrivateKey_EmptyStore_Linux_Test0001()
3034
IInvocation invocation = submitInventoryUpdate.Invocations[0];
3135
List<CurrentInventoryItem> inventoryItems = (List<CurrentInventoryItem>)invocation.Arguments[0];
3236
Assert.Single(inventoryItems);
33-
inventoryItems[0].Certificates).
37+
38+
using (StringReader rdr = new StringReader(inventoryItems[0].Certificates.First()))
39+
{
40+
PemReader pemReader = new PemReader(rdr);
41+
PemObject pemObject = pemReader.ReadPemObject();
42+
X509CertificateParser parser = new X509CertificateParser();
43+
X509Certificate certificate = parser.ReadCertificate(pemObject.Content);
44+
45+
Assert.Equal(EnvironmentVariables.CertificateSubjectDN, certificate.SubjectDN.ToString());
46+
}
3447

3548
}
3649

@@ -57,8 +70,8 @@ private InventoryJobConfiguration BuildBaseInventoryConfig()
5770
config.CertificateStoreDetails = new CertificateStore();
5871
config.JobId = new Guid();
5972
config.JobProperties = new Dictionary<string, object>();
60-
config.ServerUsername = Environment.GetEnvironmentVariable("LinuxUserId");
61-
config.ServerPassword = Environment.GetEnvironmentVariable("LinuxUserPassword");
73+
config.ServerUsername = EnvironmentVariables.LinuxUserId;
74+
config.ServerPassword = EnvironmentVariables.LinuxUserPassword;
6275

6376
return config;
6477
}

RemoteFileIntegrationTests/RemoteFileIntegrationTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
13+
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" />
1414
<PackageReference Include="coverlet.collector" Version="6.0.0" />
15-
<PackageReference Include="Keyfactor.Orchestrators.IOrchestratorJobExtensions" Version="0.7.0" />
15+
<PackageReference Include="Keyfactor.Orchestrators.IOrchestratorJobExtensions" Version="1.0.0" />
1616
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
1717
<PackageReference Include="Moq" Version="4.20.72" />
1818
<PackageReference Include="SSH.NET" Version="2024.0.0" />

0 commit comments

Comments
 (0)