@@ -507,12 +507,15 @@ public async Task GetHostSecrets_WhenNonDecryptedHostSecrets_SavesAndRefreshes()
507507 [ Fact ]
508508 public async Task GetFunctiontSecrets_WhenNonDecryptedSecrets_SavesAndRefreshes ( )
509509 {
510- using ( var directory = new TempDirectory ( ) )
510+ string key = TestHelpers . GenerateKeyHexString ( ) ;
511+ using ( new TestScopedEnvironmentVariable ( EnvironmentSettingNames . WebSiteAuthEncryptionKey , key ) )
511512 {
512- string functionName = "testfunction" ;
513- string expectedTraceMessage = string . Format ( Resources . TraceNonDecryptedFunctionSecretRefresh , functionName ) ;
514- string functionSecretsJson =
515- @"{
513+ using ( var directory = new TempDirectory ( ) )
514+ {
515+ string functionName = "testfunction" ;
516+ string expectedTraceMessage = string . Format ( Resources . TraceNonDecryptedFunctionSecretRefresh , functionName , string . Empty ) ;
517+ string functionSecretsJson =
518+ @"{
516519 'keys': [
517520 {
518521 'name': 'Key1',
@@ -526,21 +529,27 @@ public async Task GetFunctiontSecrets_WhenNonDecryptedSecrets_SavesAndRefreshes(
526529 }
527530 ]
528531}" ;
529- File . WriteAllText ( Path . Combine ( directory . Path , functionName + ".json" ) , functionSecretsJson ) ;
530- Mock < IKeyValueConverterFactory > mockValueConverterFactory = GetConverterFactoryMock ( true , false ) ;
531- IDictionary < string , string > functionSecrets ;
532- ISecretsRepository repository = new FileSystemSecretsRepository ( directory . Path ) ;
532+ File . WriteAllText ( Path . Combine ( directory . Path , functionName + ".json" ) , functionSecretsJson ) ;
533+ Mock < IKeyValueConverterFactory > mockValueConverterFactory = GetConverterFactoryMock ( true , false ) ;
534+ IDictionary < string , string > functionSecrets ;
535+ ISecretsRepository repository = new FileSystemSecretsRepository ( directory . Path ) ;
533536
534- using ( var secretManager = new SecretManager ( repository , mockValueConverterFactory . Object , null , new TestMetricsLogger ( ) ) )
535- {
536- functionSecrets = await secretManager . GetFunctionSecretsAsync ( functionName ) ;
537- }
537+ using ( var secretManager = new SecretManager ( repository , mockValueConverterFactory . Object , null , new TestMetricsLogger ( ) ) )
538+ {
539+ functionSecrets = await secretManager . GetFunctionSecretsAsync ( functionName ) ;
540+ }
538541
539- Assert . NotNull ( functionSecrets ) ;
540- Assert . NotEqual ( functionSecrets [ "Key1" ] , "cryptoError" ) ;
541- var result = JsonConvert . DeserializeObject < FunctionSecrets > ( File . ReadAllText ( Path . Combine ( directory . Path , functionName + ".json" ) ) ) ;
542- Assert . Equal ( result . GetFunctionKey ( "Key1" , functionName ) . Value , "!" + functionSecrets [ "Key1" ] ) ;
543- Assert . Equal ( 1 , Directory . GetFiles ( directory . Path , $ "{ functionName } .{ ScriptConstants . Snapshot } *") . Length ) ;
542+ Assert . NotNull ( functionSecrets ) ;
543+ Assert . NotEqual ( functionSecrets [ "Key1" ] , "cryptoError" ) ;
544+ var result = JsonConvert . DeserializeObject < FunctionSecrets > ( File . ReadAllText ( Path . Combine ( directory . Path , functionName + ".json" ) ) ) ;
545+ Assert . Equal ( result . GetFunctionKey ( "Key1" , functionName ) . Value , "!" + functionSecrets [ "Key1" ] ) ;
546+ Assert . Equal ( 1 , Directory . GetFiles ( directory . Path , $ "{ functionName } .{ ScriptConstants . Snapshot } *") . Length ) ;
547+
548+ result = JsonConvert . DeserializeObject < FunctionSecrets > ( File . ReadAllText ( Path . Combine ( directory . Path , functionName + ".json" ) ) ) ;
549+ string snapShotFileName = Directory . GetFiles ( directory . Path , $ "{ functionName } .{ ScriptConstants . Snapshot } *") [ 0 ] ;
550+ result = JsonConvert . DeserializeObject < FunctionSecrets > ( File . ReadAllText ( Path . Combine ( directory . Path , snapShotFileName ) ) ) ;
551+ Assert . NotEqual ( result . DecryptionKeyId , key ) ;
552+ }
544553 }
545554 }
546555
@@ -780,7 +789,6 @@ public async Task GetFunctiontSecrets_AddsMetrics()
780789 using ( var directory = new TempDirectory ( ) )
781790 {
782791 string functionName = "testfunction" ;
783- string expectedTraceMessage = string . Format ( Resources . TraceNonDecryptedFunctionSecretRefresh , functionName ) ;
784792 string functionSecretsJson =
785793 @"{
786794 'keys': [
0 commit comments