1313using Org . BouncyCastle . Pkcs ;
1414using Keyfactor . PKI . Extensions ;
1515using Microsoft . VisualStudio . TestPlatform . ObjectModel . Client ;
16+ using System . Text ;
1617
1718namespace RemoteFileIntegrationTests
1819{
@@ -45,7 +46,8 @@ public void RFPEM_ManagementAdd_NewAlias_ExternalKey_EmptyStore_NoOverwrite()
4546 [ Fact ]
4647 public void RFPEM_ManagementAdd_ExistingAlias_InternalKey_NonEmptyStore_NoOverwrite ( )
4748 {
48- RunTest ( TestConfigs [ 2 ] , OrchestratorJobStatusJobResult . Warning , "" ) ;
49+ RunTest ( TestConfigs [ 2 ] , OrchestratorJobStatusJobResult . Failure ,
50+ $ "Alias { ExistingAlias } already exists in store { EnvironmentVariables . LinuxStorePath } { TestConfigs [ 2 ] . FileName } .pem and overwrite is set to False.") ;
4951 }
5052
5153 [ Fact ]
@@ -63,13 +65,13 @@ public void RFPEM_ManagementAdd_ExistingAlias_ExternalKey_NonEmptyStore_YesOverw
6365 [ Fact ]
6466 public void RFPEM_ManagementAdd_NewAlias_InternalKey_NonEmptyStore_NoOverwrite ( )
6567 {
66- RunTest ( TestConfigs [ 5 ] , OrchestratorJobStatusJobResult . Success , string . Empty ) ;
68+ RunTest ( TestConfigs [ 5 ] , OrchestratorJobStatusJobResult . Failure , "Cannot add a new certificate to a PEM store that already contains a certificate/key entry." ) ;
6769 }
6870
6971 [ Fact ]
7072 public void RFPEM_ManagementAdd_NewAlias_ExternalKey_NonEmptyStore_YesOverwrite ( )
7173 {
72- RunTest ( TestConfigs [ 6 ] , OrchestratorJobStatusJobResult . Success , string . Empty ) ;
74+ RunTest ( TestConfigs [ 6 ] , OrchestratorJobStatusJobResult . Failure , "Cannot add a new certificate to a PEM store that already contains a certificate/key entry." ) ;
7375 }
7476
7577 private void RunTest ( ManagementAddTestConfig testConfig , OrchestratorJobStatusJobResult expectedResult , string expectedMessage )
@@ -80,6 +82,7 @@ private void RunTest(ManagementAddTestConfig testConfig, OrchestratorJobStatusJo
8082 config . JobId = new Guid ( ) ;
8183 config . ServerUsername = EnvironmentVariables . LinuxUserId ;
8284 config . ServerPassword = EnvironmentVariables . LinuxUserPassword ;
85+ config . Overwrite = testConfig . Overwrite ;
8386
8487 config . JobProperties = new Dictionary < string , object > ( ) ;
8588
@@ -105,13 +108,13 @@ private void RunTest(ManagementAddTestConfig testConfig, OrchestratorJobStatusJo
105108
106109 Assert . Equal ( expectedResult , result . Result ) ;
107110 if ( ! string . IsNullOrEmpty ( expectedMessage ) )
108- Assert . Equal ( expectedMessage , result . FailureMessage ) ;
111+ Assert . Contains ( expectedMessage , result . FailureMessage ) ;
109112
110113 if ( expectedResult == OrchestratorJobStatusJobResult . Success )
111114 {
112115 byte [ ] certificateBytes = ReadFile ( testConfig . FileName + ".pem" , testConfig . StoreEnvironment ) ;
113116 byte [ ] keyBytes = testConfig . HasSeparatePrivateKey ? ReadFile ( testConfig . FileName + ".key" , testConfig . StoreEnvironment ) : [ ] ;
114- string certificatePEM = Convert . ToBase64String ( certificateBytes ) + ( keyBytes . Length > 0 ? Convert . ToBase64String ( keyBytes ) : string . Empty ) ;
117+ string certificatePEM = Encoding . ASCII . GetString ( certificateBytes ) + ( keyBytes . Length > 0 ? Encoding . ASCII . GetString ( keyBytes ) : string . Empty ) ;
115118 Assert . Equal ( 1 , certificatePEM . Split ( new string [ ] { "BEGIN CERTIFICATE" } , StringSplitOptions . None ) . Length - 1 ) ;
116119 Assert . Equal ( 1 , certificatePEM . Split ( new string [ ] { "BEGIN PRIVATE KEY" } , StringSplitOptions . None ) . Length - 1 ) ;
117120
0 commit comments