Skip to content

Commit 8532de2

Browse files
author
Lee Fine
committed
initial-integration-tests
1 parent b9401c8 commit 8532de2

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

RemoteFileIntegrationTests/BaseRFPEMTest.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Org.BouncyCastle.Crypto.Operators;
55
using Org.BouncyCastle.Math;
66
using Org.BouncyCastle.OpenSsl;
7+
using Org.BouncyCastle.Pkcs;
78
using Org.BouncyCastle.Security;
89
using Org.BouncyCastle.X509;
910

@@ -16,18 +17,12 @@ public abstract class BaseRFPEMTest : BaseTest
1617
private static string pemCertificate = string.Empty;
1718
private static string pemKey = string.Empty;
1819

19-
public BaseRFPEMTest()
20-
{
21-
if (pemCertificate == null)
22-
CreateCertificateAndKey();
23-
}
24-
2520
public void CreateStore(string fileName, bool withExtKeyFile, bool withCertificate, STORE_ENVIRONMENT_ENUM storeEnvironment)
2621
{
2722
string storeContents = withCertificate ? (withExtKeyFile ? pemCertificate : pemCertificate + System.Environment.NewLine + pemKey) : string.Empty;
2823
CreateFile($"{fileName}.pem", Encoding.ASCII.GetBytes(storeContents), storeEnvironment);
2924
if (withExtKeyFile)
30-
CreateFile($"{fileName}.key", Encoding.ASCII.GetBytes(pemKey), storeEnvironment);
25+
CreateFile($"{fileName}.key", Encoding.ASCII.GetBytes(withCertificate ? pemKey : string.Empty), storeEnvironment);
3126
}
3227

3328
public void RemoveStore(string fileName, bool withExtKeyFile, STORE_ENVIRONMENT_ENUM storeEnvironment)
@@ -37,8 +32,11 @@ public void RemoveStore(string fileName, bool withExtKeyFile, STORE_ENVIRONMENT_
3732
RemoveFile($"{fileName}.key", storeEnvironment);
3833
}
3934

40-
private void CreateCertificateAndKey()
35+
public void CreateCertificateAndKey()
4136
{
37+
if (!string.IsNullOrEmpty(pemCertificate))
38+
return;
39+
4240
var keyGen = new RsaKeyPairGenerator();
4341
keyGen.Init(new KeyGenerationParameters(new SecureRandom(), 2048));
4442
AsymmetricCipherKeyPair keyPair = keyGen.GenerateKeyPair();
@@ -76,7 +74,7 @@ private void CreateCertificateAndKey()
7674
using (var sw = new StringWriter())
7775
{
7876
var pw = new PemWriter(sw);
79-
pw.WriteObject(keyPair.Private);
77+
pw.WriteObject((new Pkcs8Generator(keyPair.Private)).Generate());
8078
pw.Writer.Flush();
8179
pemKey = sw.ToString();
8280
}

RemoteFileIntegrationTests/RFPEMInventoryTests.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void RFPEM_Inventory_InternalPrivateKey_EmptyStore_Linux_Test0001()
1717
{
1818
InventoryJobConfiguration config = BuildBaseInventoryConfig();
1919
config.CertificateStoreDetails.ClientMachine = EnvironmentVariables.LinuxServer;
20-
config.CertificateStoreDetails.StorePath = EnvironmentVariables.LinuxStorePath;
20+
config.CertificateStoreDetails.StorePath = EnvironmentVariables.LinuxStorePath + "Test0001.pem";
2121
config.CertificateStoreDetails.Properties = "{}";
2222
//config.CertificateStoreDetails.Properties = JsonConvert.SerializeObject(new Dictionary<string, string?>() { { "SeparatePrivateKeyFilePath", Environment.GetEnvironmentVariable("LinuxStorePath") + "Test0001.key" } });
2323
config.CertificateStoreDetails.ClientMachine = EnvironmentVariables.LinuxServer;
@@ -31,6 +31,30 @@ public void RFPEM_Inventory_InternalPrivateKey_EmptyStore_Linux_Test0001()
3131

3232
Assert.Equal(OrchestratorJobStatusJobResult.Success, result.Result);
3333

34+
IInvocation invocation = submitInventoryUpdate.Invocations[0];
35+
List<CurrentInventoryItem> inventoryItems = (List<CurrentInventoryItem>)invocation.Arguments[0];
36+
Assert.Empty(inventoryItems);
37+
}
38+
39+
[Fact]
40+
public void RFPEM_Inventory_InternalPrivateKey_WithCert_Linux_Test0002()
41+
{
42+
InventoryJobConfiguration config = BuildBaseInventoryConfig();
43+
config.CertificateStoreDetails.ClientMachine = EnvironmentVariables.LinuxServer;
44+
config.CertificateStoreDetails.StorePath = EnvironmentVariables.LinuxStorePath + "Test0002.pem";
45+
config.CertificateStoreDetails.Properties = "{}";
46+
//config.CertificateStoreDetails.Properties = JsonConvert.SerializeObject(new Dictionary<string, string?>() { { "SeparatePrivateKeyFilePath", Environment.GetEnvironmentVariable("LinuxStorePath") + "Test0001.key" } });
47+
config.CertificateStoreDetails.ClientMachine = EnvironmentVariables.LinuxServer;
48+
49+
Mock<IPAMSecretResolver> secretResolver = GetMockSecretResolver(config);
50+
51+
Mock<SubmitInventoryUpdate> submitInventoryUpdate = new Mock<SubmitInventoryUpdate>();
52+
53+
Inventory inventory = new Inventory(secretResolver.Object);
54+
JobResult result = inventory.ProcessJob(config, submitInventoryUpdate.Object);
55+
56+
Assert.Equal(OrchestratorJobStatusJobResult.Success, result.Result);
57+
3458
IInvocation invocation = submitInventoryUpdate.Invocations[0];
3559
List<CurrentInventoryItem> inventoryItems = (List<CurrentInventoryItem>)invocation.Arguments[0];
3660
Assert.Single(inventoryItems);
@@ -44,11 +68,12 @@ public void RFPEM_Inventory_InternalPrivateKey_EmptyStore_Linux_Test0001()
4468

4569
Assert.Equal(EnvironmentVariables.CertificateSubjectDN, certificate.SubjectDN.ToString());
4670
}
47-
4871
}
4972

5073
public override void SetUp()
5174
{
75+
CreateCertificateAndKey();
76+
5277
CreateStore("Test0001", false, false, STORE_ENVIRONMENT_ENUM.LINUX);
5378
CreateStore("Test0002", false, true, STORE_ENVIRONMENT_ENUM.LINUX);
5479
CreateStore("Test0003", true, false, STORE_ENVIRONMENT_ENUM.LINUX);

0 commit comments

Comments
 (0)