4
4
using System ;
5
5
using System . Collections . Generic ;
6
6
using System . Diagnostics ;
7
- using System . IdentityModel . Tokens . Jwt ;
8
7
using System . IO ;
9
8
using System . Linq ;
10
9
using System . Net . Http ;
15
14
using Microsoft . AspNetCore . Builder ;
16
15
using Microsoft . AspNetCore . Hosting ;
17
16
using Microsoft . AspNetCore . TestHost ;
18
- using Microsoft . Azure . Web . DataProtection ;
19
17
using Microsoft . Azure . WebJobs . Host . Executors ;
20
18
using Microsoft . Azure . WebJobs . Script . ExtensionBundle ;
19
+ using Microsoft . Azure . WebJobs . Script . Grpc ;
21
20
using Microsoft . Azure . WebJobs . Script . Models ;
22
21
using Microsoft . Azure . WebJobs . Script . WebHost ;
23
- using Microsoft . Azure . WebJobs . Script . WebHost . Authentication ;
24
22
using Microsoft . Azure . WebJobs . Script . WebHost . DependencyInjection ;
25
23
using Microsoft . Azure . WebJobs . Script . WebHost . Middleware ;
26
24
using Microsoft . Azure . WebJobs . Script . WebHost . Models ;
34
32
using Microsoft . Extensions . Logging ;
35
33
using Microsoft . Extensions . Logging . Abstractions ;
36
34
using Microsoft . Extensions . Options ;
37
- using Microsoft . IdentityModel . Tokens ;
38
35
using Microsoft . WebJobs . Script . Tests ;
39
36
using Newtonsoft . Json . Linq ;
40
37
using IApplicationLifetime = Microsoft . AspNetCore . Hosting . IApplicationLifetime ;
@@ -62,10 +59,9 @@ public TestFunctionHost(string scriptPath,
62
59
Action < IWebJobsBuilder > configureScriptHostWebJobsBuilder = null ,
63
60
Action < IConfigurationBuilder > configureScriptHostAppConfiguration = null ,
64
61
Action < ILoggingBuilder > configureScriptHostLogging = null ,
65
- Action < IServiceCollection > configureScriptHostServices = null ,
66
- Action < IConfigurationBuilder > configureWebHostAppConfiguration = null )
62
+ Action < IServiceCollection > configureScriptHostServices = null )
67
63
: this ( scriptPath , Path . Combine ( Path . GetTempPath ( ) , @"Functions" ) , configureWebHostServices , configureScriptHostWebJobsBuilder ,
68
- configureScriptHostAppConfiguration , configureScriptHostLogging , configureScriptHostServices , configureWebHostAppConfiguration )
64
+ configureScriptHostAppConfiguration , configureScriptHostLogging , configureScriptHostServices )
69
65
{
70
66
}
71
67
@@ -74,9 +70,7 @@ public TestFunctionHost(string scriptPath, string logPath,
74
70
Action < IWebJobsBuilder > configureScriptHostWebJobsBuilder = null ,
75
71
Action < IConfigurationBuilder > configureScriptHostAppConfiguration = null ,
76
72
Action < ILoggingBuilder > configureScriptHostLogging = null ,
77
- Action < IServiceCollection > configureScriptHostServices = null ,
78
- Action < IConfigurationBuilder > configureWebHostAppConfiguration = null ,
79
- bool addTestSettings = true )
73
+ Action < IServiceCollection > configureScriptHostServices = null )
80
74
{
81
75
_appRoot = scriptPath ;
82
76
@@ -132,10 +126,7 @@ public TestFunctionHost(string scriptPath, string logPath,
132
126
} )
133
127
. ConfigureScriptHostAppConfiguration ( scriptHostConfigurationBuilder =>
134
128
{
135
- if ( addTestSettings )
136
- {
137
- scriptHostConfigurationBuilder . AddTestSettings ( ) ;
138
- }
129
+ scriptHostConfigurationBuilder . AddTestSettings ( ) ;
139
130
configureScriptHostAppConfiguration ? . Invoke ( scriptHostConfigurationBuilder ) ;
140
131
} )
141
132
. ConfigureScriptHostLogging ( scriptHostLoggingBuilder =>
@@ -158,11 +149,7 @@ public TestFunctionHost(string scriptPath, string logPath,
158
149
}
159
150
160
151
config . Add ( new ScriptEnvironmentVariablesConfigurationSource ( ) ) ;
161
- if ( addTestSettings )
162
- {
163
- config . AddTestSettings ( ) ;
164
- }
165
- configureWebHostAppConfiguration ? . Invoke ( config ) ;
152
+ config . AddTestSettings ( ) ;
166
153
} )
167
154
. UseStartup < TestStartup > ( ) ;
168
155
@@ -198,9 +185,7 @@ public TestFunctionHost(string scriptPath, string logPath,
198
185
199
186
public ScriptJobHostOptions ScriptOptions => JobHostServices . GetService < IOptions < ScriptJobHostOptions > > ( ) . Value ;
200
187
201
- public ISecretManagerProvider SecretManagerProvider => _testServer . Host . Services . GetService < ISecretManagerProvider > ( ) ;
202
-
203
- public ISecretManager SecretManager => SecretManagerProvider . Current ;
188
+ public ISecretManager SecretManager => _testServer . Host . Services . GetService < ISecretManagerProvider > ( ) . Current ;
204
189
205
190
public string LogPath => _hostOptions . LogPath ;
206
191
@@ -210,11 +195,6 @@ public TestFunctionHost(string scriptPath, string logPath,
210
195
211
196
public async Task < string > GetMasterKeyAsync ( )
212
197
{
213
- if ( ! SecretManagerProvider . SecretsEnabled )
214
- {
215
- return null ;
216
- }
217
-
218
198
HostSecretsInfo secrets = await SecretManager . GetHostSecretsAsync ( ) ;
219
199
return secrets . MasterKey ;
220
200
}
@@ -368,44 +348,13 @@ public async Task<FunctionStatus> GetFunctionStatusAsync(string functionName)
368
348
369
349
public async Task < HostStatus > GetHostStatusAsync ( )
370
350
{
371
- HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Get , "admin/host/status" ) ;
372
-
373
- if ( SecretManagerProvider . SecretsEnabled )
374
- {
375
- // use admin key
376
- HostSecretsInfo secrets = await SecretManager . GetHostSecretsAsync ( ) ;
377
- request . Headers . Add ( AuthenticationLevelHandler . FunctionsKeyHeaderName , secrets . MasterKey ) ;
378
- }
379
- else
380
- {
381
- // use admin jwt token
382
- string token = GenerateAdminJwtToken ( ) ;
383
- request . Headers . Authorization = new System . Net . Http . Headers . AuthenticationHeaderValue ( "Bearer" , token ) ;
384
- }
385
-
386
- HttpResponseMessage response = await HttpClient . SendAsync ( request ) ;
351
+ HostSecretsInfo secrets = await SecretManager . GetHostSecretsAsync ( ) ;
352
+ string uri = $ "admin/host/status?code={ secrets . MasterKey } ";
353
+ HttpResponseMessage response = await HttpClient . GetAsync ( uri ) ;
387
354
response . EnsureSuccessStatusCode ( ) ;
388
355
return await response . Content . ReadAsAsync < HostStatus > ( ) ;
389
356
}
390
357
391
- public string GenerateAdminJwtToken ( )
392
- {
393
- var tokenHandler = new JwtSecurityTokenHandler ( ) ;
394
- string defaultKey = Util . GetDefaultKeyValue ( ) ;
395
- var key = Encoding . ASCII . GetBytes ( defaultKey ) ;
396
- var tokenDescriptor = new SecurityTokenDescriptor
397
- {
398
- Audience = string . Format ( ScriptConstants . AdminJwtValidAudienceFormat , Environment . GetEnvironmentVariable ( EnvironmentSettingNames . AzureWebsiteName ) ) ,
399
- Issuer = string . Format ( ScriptConstants . AdminJwtValidIssuerFormat , Environment . GetEnvironmentVariable ( EnvironmentSettingNames . AzureWebsiteName ) ) ,
400
- Expires = DateTime . UtcNow . AddHours ( 1 ) ,
401
- SigningCredentials = new SigningCredentials ( new SymmetricSecurityKey ( key ) , SecurityAlgorithms . HmacSha256Signature )
402
- } ;
403
- var token = tokenHandler . CreateToken ( tokenDescriptor ) ;
404
- string tokenHeaderValue = tokenHandler . WriteToken ( token ) ;
405
-
406
- return tokenHeaderValue ;
407
- }
408
-
409
358
public void Dispose ( )
410
359
{
411
360
if ( ! _isDisposed )
0 commit comments