Skip to content

Commit d6ffa2b

Browse files
author
Lee Fine
committed
initial-integration-tests
1 parent c68553c commit d6ffa2b

File tree

2 files changed

+63
-42
lines changed

2 files changed

+63
-42
lines changed

RemoteFileIntegrationTests/BaseRFPEMTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace RemoteFileIntegrationTests
1414
{
15-
public abstract class BaseRFPEMTest : BaseTest
15+
public class BaseRFPEMTest : BaseTest
1616
{
1717
private static string pemCertificate = string.Empty;
1818
private static string pemKey = string.Empty;

RemoteFileIntegrationTests/RFPEMInventoryTests.cs

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,57 @@
55

66
using Moq;
77

8+
using Newtonsoft.Json;
9+
810
using Org.BouncyCastle.X509;
911
using Org.BouncyCastle.Utilities.IO.Pem;
10-
using static RemoteFileIntegrationTests.BaseTest;
12+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
1113

1214
namespace RemoteFileIntegrationTests
1315
{
1416
public class RFPEMInventoryTests : BaseRFPEMTest, IClassFixture<RFPEMInventoryTestsFixture>
1517
{
18+
public static TestConfig[] TestConfigs = {
19+
new TestConfig() { FileName = "Test0001", HasSeparatePrivateKey = false, WithCertificate = false, StoreEnvironment = STORE_ENVIRONMENT_ENUM.LINUX},
20+
new TestConfig() { FileName = "Test0002", HasSeparatePrivateKey = false, WithCertificate = true, StoreEnvironment = STORE_ENVIRONMENT_ENUM.LINUX},
21+
new TestConfig() { FileName = "Test0003", HasSeparatePrivateKey = true, WithCertificate = false, StoreEnvironment = STORE_ENVIRONMENT_ENUM.LINUX},
22+
new TestConfig() { FileName = "Test0004", HasSeparatePrivateKey = true, WithCertificate = true, StoreEnvironment = STORE_ENVIRONMENT_ENUM.LINUX},
23+
};
24+
1625
[Fact]
1726
public void RFPEM_Inventory_InternalPrivateKey_EmptyStore_Linux_Test0001()
1827
{
19-
InventoryJobConfiguration config = BuildBaseInventoryConfig();
20-
config.CertificateStoreDetails.ClientMachine = EnvironmentVariables.LinuxServer;
21-
config.CertificateStoreDetails.StorePath = EnvironmentVariables.LinuxStorePath + "Test0001.pem";
22-
config.CertificateStoreDetails.Properties = "{}";
23-
//config.CertificateStoreDetails.Properties = JsonConvert.SerializeObject(new Dictionary<string, string?>() { { "SeparatePrivateKeyFilePath", Environment.GetEnvironmentVariable("LinuxStorePath") + "Test0001.key" } });
24-
config.CertificateStoreDetails.ClientMachine = EnvironmentVariables.LinuxServer;
25-
26-
Mock<IPAMSecretResolver> secretResolver = GetMockSecretResolver(config);
27-
28-
Mock<SubmitInventoryUpdate> submitInventoryUpdate = new Mock<SubmitInventoryUpdate>();
28+
RunTest(TestConfigs[0]);
29+
}
2930

30-
Inventory inventory = new Inventory(secretResolver.Object);
31-
JobResult result = inventory.ProcessJob(config, submitInventoryUpdate.Object);
31+
[Fact]
32+
public void RFPEM_Inventory_InternalPrivateKey_WithCert_Linux_Test0002()
33+
{
34+
RunTest(TestConfigs[1]);
35+
}
3236

33-
Assert.Equal(OrchestratorJobStatusJobResult.Success, result.Result);
34-
35-
IInvocation invocation = submitInventoryUpdate.Invocations[0];
36-
List<CurrentInventoryItem> inventoryItems = (List<CurrentInventoryItem>)invocation.Arguments[0];
37-
Assert.Empty(inventoryItems);
37+
[Fact]
38+
public void RFPEM_Inventory_InternalPrivateKey_EmptyStore_Linux_Test0003()
39+
{
40+
RunTest(TestConfigs[2]);
3841
}
3942

4043
[Fact]
41-
public void RFPEM_Inventory_InternalPrivateKey_WithCert_Linux_Test0002()
44+
public void RFPEM_Inventory_InternalPrivateKey_WithCert_Linux_Test0004()
45+
{
46+
RunTest(TestConfigs[3]);
47+
}
48+
49+
private void RunTest(TestConfig testConfig)
4250
{
4351
InventoryJobConfiguration config = BuildBaseInventoryConfig();
4452
config.CertificateStoreDetails.ClientMachine = EnvironmentVariables.LinuxServer;
45-
config.CertificateStoreDetails.StorePath = EnvironmentVariables.LinuxStorePath + "Test0002.pem";
53+
config.CertificateStoreDetails.StorePath = EnvironmentVariables.LinuxStorePath + $"{testConfig.FileName}.pem";
4654
config.CertificateStoreDetails.Properties = "{}";
47-
//config.CertificateStoreDetails.Properties = JsonConvert.SerializeObject(new Dictionary<string, string?>() { { "SeparatePrivateKeyFilePath", Environment.GetEnvironmentVariable("LinuxStorePath") + "Test0001.key" } });
48-
config.CertificateStoreDetails.ClientMachine = EnvironmentVariables.LinuxServer;
55+
if (testConfig.HasSeparatePrivateKey)
56+
config.CertificateStoreDetails.Properties = JsonConvert.SerializeObject(new Dictionary<string, string?>() { { "SeparatePrivateKeyFilePath", Environment.GetEnvironmentVariable("LinuxStorePath") + $"{testConfig.FileName}.key" } });
57+
else
58+
config.CertificateStoreDetails.ClientMachine = EnvironmentVariables.LinuxServer;
4959

5060
Mock<IPAMSecretResolver> secretResolver = GetMockSecretResolver(config);
5161

@@ -56,18 +66,21 @@ public void RFPEM_Inventory_InternalPrivateKey_WithCert_Linux_Test0002()
5666

5767
Assert.Equal(OrchestratorJobStatusJobResult.Success, result.Result);
5868

59-
IInvocation invocation = submitInventoryUpdate.Invocations[0];
60-
List<CurrentInventoryItem> inventoryItems = (List<CurrentInventoryItem>)invocation.Arguments[0];
61-
Assert.Single(inventoryItems);
62-
63-
using (StringReader rdr = new StringReader(inventoryItems[0].Certificates.First()))
69+
if (testConfig.WithCertificate)
6470
{
65-
PemReader pemReader = new PemReader(rdr);
66-
PemObject pemObject = pemReader.ReadPemObject();
67-
X509CertificateParser parser = new X509CertificateParser();
68-
X509Certificate certificate = parser.ReadCertificate(pemObject.Content);
69-
70-
Assert.Equal(EnvironmentVariables.CertificateSubjectDN, certificate.SubjectDN.ToString());
71+
IInvocation invocation = submitInventoryUpdate.Invocations[0];
72+
List<CurrentInventoryItem> inventoryItems = (List<CurrentInventoryItem>)invocation.Arguments[0];
73+
Assert.Single(inventoryItems);
74+
75+
using (StringReader rdr = new StringReader(inventoryItems[0].Certificates.First()))
76+
{
77+
PemReader pemReader = new PemReader(rdr);
78+
PemObject pemObject = pemReader.ReadPemObject();
79+
X509CertificateParser parser = new X509CertificateParser();
80+
X509Certificate certificate = parser.ReadCertificate(pemObject.Content);
81+
82+
Assert.Equal(EnvironmentVariables.CertificateSubjectDN, certificate.SubjectDN.ToString());
83+
}
7184
}
7285
}
7386

@@ -83,6 +96,14 @@ private InventoryJobConfiguration BuildBaseInventoryConfig()
8396

8497
return config;
8598
}
99+
100+
public class TestConfig
101+
{
102+
internal string FileName { get; set; }
103+
internal bool HasSeparatePrivateKey { get; set; }
104+
internal bool WithCertificate { get; set; }
105+
internal BaseTest.STORE_ENVIRONMENT_ENUM StoreEnvironment { get; set; }
106+
}
86107
}
87108

88109
public class RFPEMInventoryTestsFixture : IDisposable
@@ -101,18 +122,18 @@ private void SetUp()
101122
{
102123
BaseRFPEMTest.CreateCertificateAndKey();
103124

104-
BaseRFPEMTest.CreateStore("Test0001", false, false, STORE_ENVIRONMENT_ENUM.LINUX);
105-
BaseRFPEMTest.CreateStore("Test0002", false, true, STORE_ENVIRONMENT_ENUM.LINUX);
106-
BaseRFPEMTest.CreateStore("Test0003", true, false, STORE_ENVIRONMENT_ENUM.LINUX);
107-
BaseRFPEMTest.CreateStore("Test0004", true, true, STORE_ENVIRONMENT_ENUM.LINUX);
125+
BaseRFPEMTest.CreateStore(RFPEMInventoryTests.TestConfigs[0].FileName, RFPEMInventoryTests.TestConfigs[0].HasSeparatePrivateKey, RFPEMInventoryTests.TestConfigs[0].WithCertificate, RFPEMInventoryTests.TestConfigs[0].StoreEnvironment);
126+
BaseRFPEMTest.CreateStore(RFPEMInventoryTests.TestConfigs[1].FileName, RFPEMInventoryTests.TestConfigs[1].HasSeparatePrivateKey, RFPEMInventoryTests.TestConfigs[1].WithCertificate, RFPEMInventoryTests.TestConfigs[1].StoreEnvironment);
127+
BaseRFPEMTest.CreateStore(RFPEMInventoryTests.TestConfigs[2].FileName, RFPEMInventoryTests.TestConfigs[2].HasSeparatePrivateKey, RFPEMInventoryTests.TestConfigs[2].WithCertificate, RFPEMInventoryTests.TestConfigs[2].StoreEnvironment);
128+
BaseRFPEMTest.CreateStore(RFPEMInventoryTests.TestConfigs[3].FileName, RFPEMInventoryTests.TestConfigs[3].HasSeparatePrivateKey, RFPEMInventoryTests.TestConfigs[3].WithCertificate, RFPEMInventoryTests.TestConfigs[3].StoreEnvironment);
108129
}
109130

110131
private void TearDown()
111132
{
112-
BaseRFPEMTest.RemoveStore("Test0001", false, STORE_ENVIRONMENT_ENUM.LINUX);
113-
BaseRFPEMTest.RemoveStore("Test0002", false, STORE_ENVIRONMENT_ENUM.LINUX);
114-
BaseRFPEMTest.RemoveStore("Test0003", true, STORE_ENVIRONMENT_ENUM.LINUX);
115-
BaseRFPEMTest.RemoveStore("Test0004", true, STORE_ENVIRONMENT_ENUM.LINUX);
133+
BaseRFPEMTest.RemoveStore(RFPEMInventoryTests.TestConfigs[0].FileName, RFPEMInventoryTests.TestConfigs[0].HasSeparatePrivateKey, RFPEMInventoryTests.TestConfigs[0].StoreEnvironment);
134+
BaseRFPEMTest.RemoveStore(RFPEMInventoryTests.TestConfigs[1].FileName, RFPEMInventoryTests.TestConfigs[1].HasSeparatePrivateKey, RFPEMInventoryTests.TestConfigs[1].StoreEnvironment);
135+
BaseRFPEMTest.RemoveStore(RFPEMInventoryTests.TestConfigs[2].FileName, RFPEMInventoryTests.TestConfigs[2].HasSeparatePrivateKey, RFPEMInventoryTests.TestConfigs[2].StoreEnvironment);
136+
BaseRFPEMTest.RemoveStore(RFPEMInventoryTests.TestConfigs[3].FileName, RFPEMInventoryTests.TestConfigs[3].HasSeparatePrivateKey, RFPEMInventoryTests.TestConfigs[3].StoreEnvironment);
116137
}
117138
}
118139

0 commit comments

Comments
 (0)