1414using System . Threading . Tasks ;
1515using System . Web . Http ;
1616using System . Xml . Linq ;
17+ using Autofac ;
1718using Microsoft . Azure . WebJobs . Host ;
1819using Microsoft . Azure . WebJobs . Script . Config ;
1920using Microsoft . Azure . WebJobs . Script . Tests . Properties ;
2021using Microsoft . Azure . WebJobs . Script . WebHost ;
2122using Microsoft . Azure . WebJobs . Script . WebHost . Filters ;
23+ using Microsoft . Azure . WebJobs . Script . WebHost . Management ;
2224using Microsoft . Azure . WebJobs . Script . WebHost . Models ;
2325using Microsoft . ServiceBus ;
2426using Microsoft . ServiceBus . Messaging ;
2527using Microsoft . WindowsAzure . Storage ;
2628using Microsoft . WindowsAzure . Storage . Blob ;
2729using Microsoft . WindowsAzure . Storage . Queue ;
2830using Microsoft . WindowsAzure . Storage . Table ;
31+ using Moq ;
2932using Newtonsoft . Json ;
3033using Newtonsoft . Json . Linq ;
3134using Xunit ;
@@ -37,6 +40,7 @@ namespace Microsoft.Azure.WebJobs.Script.Tests
3740 public class SamplesEndToEndTests : IClassFixture < SamplesEndToEndTests . TestFixture >
3841 {
3942 internal const string MasterKey = "t8laajal0a1ajkgzoqlfv5gxr4ebhqozebw4qzdy" ;
43+ private const string TestInstanceId = "a03948aa41d0c354ce659d273031a12c9b5755727cb9f66c1b4792a0cd3c5998" ;
4044
4145 private readonly ScriptSettingsManager _settingsManager ;
4246 private TestFixture _fixture ;
@@ -226,6 +230,37 @@ public async Task Home_Get_InAzureEnvironment_AsInternalRequest_ReturnsNoContent
226230 }
227231 }
228232
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+
229264 [ Fact ]
230265 public async Task HttpTrigger_CSharp_Poco_Post_Succeeds ( )
231266 {
@@ -1178,7 +1213,12 @@ public TestFixture()
11781213 SecretsPath = Path . Combine ( Environment . CurrentDirectory , @"..\..\..\..\src\WebJobs.Script.WebHost\App_Data\Secrets" ) ,
11791214 TraceWriter = _traceWriter
11801215 } ;
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+ } ) ;
11821222
11831223 HttpServer = new HttpServer ( _config ) ;
11841224 HttpClient = new HttpClient ( HttpServer ) ;
0 commit comments