public DefaultScriptWebHookProviderTests() { _mockSecretManager = new Mock <ISecretManager>(MockBehavior.Strict); _hostSecrets = new HostSecretsInfo(); _mockSecretManager.Setup(p => p.GetHostSecretsAsync()).ReturnsAsync(_hostSecrets); var mockSecretManagerProvider = new Mock <ISecretManagerProvider>(MockBehavior.Strict); mockSecretManagerProvider.Setup(p => p.Current).Returns(_mockSecretManager.Object); _webHookProvider = new DefaultScriptWebHookProvider(mockSecretManagerProvider.Object); }
public DefaultScriptWebHookProviderTests() { _mockSecretManager = new Mock <ISecretManager>(MockBehavior.Strict); _hostSecrets = new HostSecretsInfo(); _mockSecretManager.Setup(p => p.GetHostSecretsAsync()).ReturnsAsync(_hostSecrets); var mockSecretManagerProvider = new Mock <ISecretManagerProvider>(MockBehavior.Strict); mockSecretManagerProvider.Setup(p => p.Current).Returns(_mockSecretManager.Object); var loggerProvider = new TestLoggerProvider(); var loggerFactory = new LoggerFactory(); loggerFactory.AddProvider(loggerProvider); var testEnvironment = new TestEnvironment(); testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHostName, TestHostName); var hostNameProvider = new HostNameProvider(testEnvironment); _webHookProvider = new DefaultScriptWebHookProvider(mockSecretManagerProvider.Object, hostNameProvider); }
public async Task <IActionResult> ExtensionWebHookHandler(string extensionName, CancellationToken token, [FromServices] IScriptWebHookProvider provider) { if (provider.TryGetHandler(extensionName, out HttpHandler handler)) { var requestMessage = new HttpRequestMessageFeature(this.HttpContext).HttpRequestMessage; HttpResponseMessage response = await handler.ConvertAsync(requestMessage, token); var result = new ObjectResult(response); result.Formatters.Add(new HttpResponseMessageOutputFormatter()); return(result); } return(NotFound()); }
public async Task <IActionResult> ExtensionWebHookHandler(string name, CancellationToken token, [FromServices] IScriptWebHookProvider provider) { if (provider.TryGetHandler(name, out HttpHandler handler)) { // must either be authorized at the admin level, or system level with // a matching key name string keyName = DefaultScriptWebHookProvider.GetKeyName(name); if (!AuthUtility.PrincipalHasAuthLevelClaim(User, AuthorizationLevel.System, keyName)) { return(Unauthorized()); } var requestMessage = new HttpRequestMessageFeature(this.HttpContext).HttpRequestMessage; HttpResponseMessage response = await handler.ConvertAsync(requestMessage, token); var result = new ObjectResult(response); result.Formatters.Add(new HttpResponseMessageOutputFormatter()); return(result); } return(NotFound()); }
public async Task <IActionResult> ExtensionWebHookHandler(string name, CancellationToken token, [FromServices] IScriptWebHookProvider provider) { if (provider.TryGetHandler(name, out HttpHandler handler)) { string keyName = DefaultScriptWebHookProvider.GetKeyName(name); var authResult = await _authorizationService.AuthorizeAsync(User, keyName, PolicyNames.SystemAuthLevel); if (!authResult.Succeeded) { return(Unauthorized()); } var requestMessage = new HttpRequestMessageFeature(this.HttpContext).HttpRequestMessage; HttpResponseMessage response = await handler.ConvertAsync(requestMessage, token); var result = new ObjectResult(response); result.Formatters.Add(new HttpResponseMessageOutputFormatter()); return(result); } return(NotFound()); }