7
7
using System . Linq ;
8
8
using System . Security . Cryptography ;
9
9
using System . Threading . Tasks ;
10
+ using Microsoft . Azure . WebJobs . Extensions . Http ;
10
11
using Microsoft . Azure . WebJobs . Logging ;
11
12
using Microsoft . Azure . WebJobs . Script . Diagnostics ;
12
13
using Microsoft . Azure . WebJobs . Script . WebHost ;
@@ -63,8 +64,8 @@ public async Task CachedSecrets_UsedWhenPresent()
63
64
var functionSecrets = await secretManager . GetFunctionSecretsAsync ( "function1" , true ) ;
64
65
65
66
Assert . Equal ( 4 , functionSecrets . Count ) ;
66
- Assert . Equal ( "function1value " , functionSecrets [ "test-function -1" ] ) ;
67
- Assert . Equal ( "function2value " , functionSecrets [ "test-function -2" ] ) ;
67
+ Assert . Equal ( "function1value1 " , functionSecrets [ "test-function1 -1" ] ) ;
68
+ Assert . Equal ( "function1value2 " , functionSecrets [ "test-function1 -2" ] ) ;
68
69
Assert . Equal ( "hostfunction1value" , functionSecrets [ "test-host-function-1" ] ) ;
69
70
Assert . Equal ( "hostfunction2value" , functionSecrets [ "test-host-function-2" ] ) ;
70
71
@@ -87,6 +88,46 @@ public async Task CachedSecrets_UsedWhenPresent()
87
88
}
88
89
}
89
90
91
+ [ Theory ]
92
+ [ InlineData ( "function1value1" , "test-function1-1" , "function1" , AuthorizationLevel . Function ) ]
93
+ [ InlineData ( "function1value2" , "test-function1-2" , "function1" , AuthorizationLevel . Function ) ]
94
+ [ InlineData ( "function2value1" , "test-function2-1" , "function2" , AuthorizationLevel . Function ) ]
95
+ [ InlineData ( "function2value2" , "test-function2-2" , "function2" , AuthorizationLevel . Function ) ]
96
+ [ InlineData ( "function2value1" , null , "function1" , AuthorizationLevel . Anonymous ) ]
97
+ [ InlineData ( "function1value1" , null , "function2" , AuthorizationLevel . Anonymous ) ]
98
+ [ InlineData ( "invalid" , null , "function1" , AuthorizationLevel . Anonymous ) ]
99
+ [ InlineData ( "invalid" , null , "function2" , AuthorizationLevel . Anonymous ) ]
100
+ [ InlineData ( "hostfunction1value" , "test-host-function-1" , "function1" , AuthorizationLevel . Function ) ]
101
+ [ InlineData ( "hostfunction2value" , "test-host-function-2" , "function1" , AuthorizationLevel . Function ) ]
102
+ [ InlineData ( "hostfunction1value" , "test-host-function-1" , "function2" , AuthorizationLevel . Function ) ]
103
+ [ InlineData ( "hostfunction2value" , "test-host-function-2" , "function2" , AuthorizationLevel . Function ) ]
104
+ [ InlineData ( "test-master-key" , "master" , "function1" , AuthorizationLevel . Admin ) ]
105
+ [ InlineData ( "test-master-key" , "master" , "function2" , AuthorizationLevel . Admin ) ]
106
+ [ InlineData ( "test-master-key" , "master" , null , AuthorizationLevel . Admin ) ]
107
+ [ InlineData ( "system1value" , "test-system-1" , null , AuthorizationLevel . System ) ]
108
+ [ InlineData ( "system2value" , "test-system-2" , null , AuthorizationLevel . System ) ]
109
+ public async Task GetAuthorizationLevelOrNullAsync_ReturnsExpectedResult ( string keyValue , string expectedKeyName , string functionName , AuthorizationLevel expectedLevel )
110
+ {
111
+ using ( var directory = new TempDirectory ( ) )
112
+ {
113
+ string startupContextPath = Path . Combine ( directory . Path , Guid . NewGuid ( ) . ToString ( ) ) ;
114
+ _testEnvironment . SetEnvironmentVariable ( EnvironmentSettingNames . AzureWebsiteStartupContextCache , startupContextPath ) ;
115
+ _testEnvironment . SetEnvironmentVariable ( EnvironmentSettingNames . WebSiteAuthEncryptionKey , TestEncryptionKey ) ;
116
+
117
+ WriteStartContextCache ( startupContextPath ) ;
118
+
119
+ using ( var secretManager = CreateSecretManager ( directory . Path ) )
120
+ {
121
+ for ( int i = 0 ; i < 3 ; i ++ )
122
+ {
123
+ ( string , AuthorizationLevel ) result = await secretManager . GetAuthorizationLevelOrNullAsync ( keyValue , functionName ) ;
124
+ Assert . Equal ( result . Item2 , expectedLevel ) ;
125
+ Assert . Equal ( result . Item1 , expectedKeyName ) ;
126
+ }
127
+ }
128
+ }
129
+ }
130
+
90
131
private FunctionAppSecrets WriteStartContextCache ( string path )
91
132
{
92
133
var secrets = new FunctionAppSecrets ( ) ;
@@ -111,17 +152,17 @@ private FunctionAppSecrets WriteStartContextCache(string path)
111
152
Name = "function1" ,
112
153
Secrets = new Dictionary < string , string >
113
154
{
114
- { "test-function -1" , "function1value " } ,
115
- { "test-function -2" , "function2value " }
155
+ { "test-function1 -1" , "function1value1 " } ,
156
+ { "test-function1 -2" , "function1value2 " }
116
157
}
117
158
} ,
118
159
new FunctionAppSecrets . FunctionSecrets
119
160
{
120
161
Name = "function2" ,
121
162
Secrets = new Dictionary < string , string >
122
163
{
123
- { "test-function -1" , "function1value " } ,
124
- { "test-function -2" , "function2value " }
164
+ { "test-function2 -1" , "function2value1 " } ,
165
+ { "test-function2 -2" , "function2value2 " }
125
166
}
126
167
}
127
168
} ;
0 commit comments