14
14
using System . Threading . Tasks ;
15
15
using System . Web . Http ;
16
16
using System . Xml . Linq ;
17
+ using Autofac ;
17
18
using Microsoft . Azure . WebJobs . Host ;
18
19
using Microsoft . Azure . WebJobs . Script . Config ;
19
20
using Microsoft . Azure . WebJobs . Script . Tests . Properties ;
20
21
using Microsoft . Azure . WebJobs . Script . WebHost ;
21
22
using Microsoft . Azure . WebJobs . Script . WebHost . Filters ;
23
+ using Microsoft . Azure . WebJobs . Script . WebHost . Management ;
22
24
using Microsoft . Azure . WebJobs . Script . WebHost . Models ;
23
25
using Microsoft . ServiceBus ;
24
26
using Microsoft . ServiceBus . Messaging ;
25
27
using Microsoft . WindowsAzure . Storage ;
26
28
using Microsoft . WindowsAzure . Storage . Blob ;
27
29
using Microsoft . WindowsAzure . Storage . Queue ;
28
30
using Microsoft . WindowsAzure . Storage . Table ;
31
+ using Moq ;
29
32
using Newtonsoft . Json ;
30
33
using Newtonsoft . Json . Linq ;
31
34
using Xunit ;
@@ -37,6 +40,7 @@ namespace Microsoft.Azure.WebJobs.Script.Tests
37
40
public class SamplesEndToEndTests : IClassFixture < SamplesEndToEndTests . TestFixture >
38
41
{
39
42
internal const string MasterKey = "t8laajal0a1ajkgzoqlfv5gxr4ebhqozebw4qzdy" ;
43
+ private const string TestInstanceId = "a03948aa41d0c354ce659d273031a12c9b5755727cb9f66c1b4792a0cd3c5998" ;
40
44
41
45
private readonly ScriptSettingsManager _settingsManager ;
42
46
private TestFixture _fixture ;
@@ -226,6 +230,37 @@ public async Task Home_Get_InAzureEnvironment_AsInternalRequest_ReturnsNoContent
226
230
}
227
231
}
228
232
233
+ [ Fact ]
234
+ public async Task SyncTriggers_AdminAuth_Succeeds ( )
235
+ {
236
+ string uri = "admin/host/synctriggers" ;
237
+ HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Post , uri ) ;
238
+ request . Headers . Add ( AuthorizationLevelAttribute . FunctionsKeyHeaderName , MasterKey ) ;
239
+ HttpResponseMessage response = await this . _fixture . HttpClient . SendAsync ( request ) ;
240
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
241
+ }
242
+
243
+ [ Fact ]
244
+ public async Task SyncTriggers_InternalAuth_Succeeds ( )
245
+ {
246
+ using ( new TestScopedSettings ( _settingsManager , EnvironmentSettingNames . AzureWebsiteInstanceId , "testinstance" ) )
247
+ {
248
+ string uri = "admin/host/synctriggers" ;
249
+ HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Post , uri ) ;
250
+ HttpResponseMessage response = await this . _fixture . HttpClient . SendAsync ( request ) ;
251
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
252
+ }
253
+ }
254
+
255
+ [ Fact ]
256
+ public async Task SyncTriggers_ExternalUnauthorized_ReturnsUnauthorized ( )
257
+ {
258
+ string uri = "admin/host/synctriggers" ;
259
+ HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Post , uri ) ;
260
+ HttpResponseMessage response = await this . _fixture . HttpClient . SendAsync ( request ) ;
261
+ Assert . Equal ( HttpStatusCode . Unauthorized , response . StatusCode ) ;
262
+ }
263
+
229
264
[ Fact ]
230
265
public async Task HttpTrigger_CSharp_Poco_Post_Succeeds ( )
231
266
{
@@ -1178,7 +1213,12 @@ public TestFixture()
1178
1213
SecretsPath = Path . Combine ( Environment . CurrentDirectory , @"..\..\..\..\src\WebJobs.Script.WebHost\App_Data\Secrets" ) ,
1179
1214
TraceWriter = _traceWriter
1180
1215
} ;
1181
- WebApiConfig . Register ( _config , _settingsManager , HostSettings ) ;
1216
+ WebApiConfig . Register ( _config , _settingsManager , HostSettings , ( builder , settings ) =>
1217
+ {
1218
+ var syncManagerMock = new Mock < IFunctionsSyncManager > ( MockBehavior . Strict ) ;
1219
+ syncManagerMock . Setup ( p => p . TrySyncTriggersAsync ( It . IsAny < bool > ( ) ) ) . ReturnsAsync ( new SyncTriggersResult { Success = true } ) ;
1220
+ builder . Register < IFunctionsSyncManager > ( _ => syncManagerMock . Object ) ;
1221
+ } ) ;
1182
1222
1183
1223
HttpServer = new HttpServer ( _config ) ;
1184
1224
HttpClient = new HttpClient ( HttpServer ) ;
0 commit comments