7
7
using System . Linq ;
8
8
using System . Security . Cryptography ;
9
9
using System . Threading . Tasks ;
10
+ using Microsoft . Azure . WebJobs . Logging ;
10
11
using Microsoft . Azure . WebJobs . Script . Config ;
11
12
using Microsoft . Azure . WebJobs . Script . WebHost ;
12
13
using Microsoft . Azure . WebJobs . Script . WebHost . Properties ;
14
+ using Microsoft . Extensions . Logging ;
13
15
using Microsoft . Extensions . Logging . Abstractions ;
16
+ using Microsoft . WebJobs . Script . Tests ;
14
17
using Moq ;
15
18
using Newtonsoft . Json ;
16
19
using WebJobs . Script . Tests ;
@@ -548,7 +551,8 @@ public async Task GetHostSecrets_WhenTooManyBackups_ThrowsException()
548
551
using ( var directory = new TempDirectory ( ) )
549
552
{
550
553
string functionName = "testfunction" ;
551
- string expectedTraceMessage = string . Format ( Resources . ErrorTooManySecretBackups , ScriptConstants . MaximumSecretBackupCount , functionName ) ;
554
+ string expectedTraceMessage = string . Format ( Resources . ErrorTooManySecretBackups , ScriptConstants . MaximumSecretBackupCount , functionName ,
555
+ string . Format ( Resources . ErrorSameSecrets , "test0,test1" ) ) ;
552
556
string functionSecretsJson =
553
557
@"{
554
558
'keys': [
@@ -564,13 +568,17 @@ public async Task GetHostSecrets_WhenTooManyBackups_ThrowsException()
564
568
}
565
569
]
566
570
}" ;
567
-
571
+ ILoggerFactory loggerFactory = new LoggerFactory ( ) ;
572
+ TestLoggerProvider loggerProvider = new TestLoggerProvider ( ) ;
573
+ loggerFactory . AddProvider ( loggerProvider ) ;
574
+ var logger = loggerFactory . CreateLogger ( LogCategories . CreateFunctionCategory ( "Test1" ) ) ;
568
575
IDictionary < string , string > functionSecrets ;
569
576
ISecretsRepository repository = new FileSystemSecretsRepository ( directory . Path ) ;
570
577
571
- using ( var secretManager = new SecretManager ( _settingsManager , repository , null ) )
578
+ using ( var secretManager = new SecretManager ( _settingsManager , repository , logger ) )
572
579
{
573
- await Assert . ThrowsAsync < InvalidOperationException > ( async ( ) =>
580
+ InvalidOperationException ioe = null ;
581
+ try
574
582
{
575
583
for ( int i = 0 ; i < ScriptConstants . MaximumSecretBackupCount + 20 ; i ++ )
576
584
{
@@ -582,12 +590,26 @@ await Assert.ThrowsAsync<InvalidOperationException>(async () =>
582
590
await Task . Delay ( 500 ) ;
583
591
}
584
592
593
+ string hostName = "test" + ( i % 2 ) . ToString ( ) ;
594
+ _settingsManager . SetSetting ( EnvironmentSettingNames . AzureWebsiteHostName , hostName ) ;
585
595
functionSecrets = await secretManager . GetFunctionSecretsAsync ( functionName ) ;
586
596
}
587
- } ) ;
597
+ }
598
+ catch ( InvalidOperationException ex )
599
+ {
600
+ ioe = ex ;
601
+ }
602
+ finally
603
+ {
604
+ _settingsManager . SetSetting ( EnvironmentSettingNames . AzureWebsiteHostName , null ) ;
605
+ }
588
606
}
589
607
590
608
Assert . True ( Directory . GetFiles ( directory . Path , $ "{ functionName } .{ ScriptConstants . Snapshot } *") . Length >= ScriptConstants . MaximumSecretBackupCount ) ;
609
+ Assert . True ( loggerProvider . GetAllLogMessages ( ) . Any (
610
+ t => t . Level == LogLevel . Debug && t . FormattedMessage . IndexOf ( expectedTraceMessage , StringComparison . OrdinalIgnoreCase ) > - 1 ) ,
611
+ "Expected Trace message not found" ) ;
612
+
591
613
}
592
614
}
593
615
0 commit comments