public async Task VerifyDurableTaskHubNameIsAdded()
        {
            var vars = new Dictionary <string, string>
            {
                { EnvironmentSettingNames.WebSiteAuthEncryptionKey, TestHelpers.GenerateKeyHexString() },
                { EnvironmentSettingNames.AzureWebsiteHostName, "appName.azurewebsites.net" }
            };

            using (var env = new TestScopedEnvironmentVariable(vars))
            {
                // Setup
                const string expectedSyncTriggersPayload = "[{\"authLevel\":\"anonymous\",\"type\":\"httpTrigger\",\"direction\":\"in\",\"name\":\"req\",\"functionName\":\"function1\"}," +
                                                           "{\"name\":\"myQueueItem\",\"type\":\"orchestrationTrigger\",\"direction\":\"in\",\"queueName\":\"myqueue-items\",\"connection\":\"DurableStorage\",\"functionName\":\"function2\",\"taskHubName\":\"TestHubValue\"}," +
                                                           "{\"name\":\"myQueueItem\",\"type\":\"activityTrigger\",\"direction\":\"in\",\"queueName\":\"myqueue-items\",\"connection\":\"DurableStorage\",\"functionName\":\"function3\",\"taskHubName\":\"TestHubValue\"}]";
                var settings       = CreateWebSettings();
                var fileSystem     = CreateFileSystem(settings.ScriptPath);
                var loggerFactory  = MockNullLogerFactory.CreateLoggerFactory();
                var contentBuilder = new StringBuilder();
                var httpClient     = CreateHttpClient(contentBuilder);
                var webManager     = new WebFunctionsManager(new OptionsWrapper <ScriptApplicationHostOptions>(settings), new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient);

                FileUtility.Instance = fileSystem;

                // Act
                (var success, var error) = await webManager.TrySyncTriggers();

                var content = contentBuilder.ToString();

                // Assert
                Assert.True(success, "SyncTriggers should return success true");
                Assert.True(string.IsNullOrEmpty(error), "Error should be null or empty");
                Assert.Equal(expectedSyncTriggersPayload, content);
            }
        }
示例#2
0
        public async Task VerifyDurableTaskHubNameIsAdded()
        {
            // Setup
            const string expectedSyncTriggersPayload = "[{\"authLevel\":\"anonymous\",\"type\":\"httpTrigger\",\"direction\":\"in\",\"name\":\"req\",\"functionName\":\"function1\"}," +
                                                       "{\"name\":\"myQueueItem\",\"type\":\"orchestrationTrigger\",\"direction\":\"in\",\"queueName\":\"myqueue-items\",\"connection\":\"DurableStorage\",\"functionName\":\"function2\",\"taskHubName\":\"TestHubValue\"}," +
                                                       "{\"name\":\"myQueueItem\",\"type\":\"activityTrigger\",\"direction\":\"in\",\"queueName\":\"myqueue-items\",\"connection\":\"DurableStorage\",\"functionName\":\"function3\",\"taskHubName\":\"TestHubValue\"}]";
            var settings       = CreateWebSettings();
            var fileSystem     = CreateFileSystem(settings.ScriptPath);
            var loggerFactory  = MockNullLogerFactory.CreateLoggerFactory();
            var contentBuilder = new StringBuilder();
            var httpClient     = CreateHttpClient(contentBuilder);
            var webManager     = new WebFunctionsManager(settings, loggerFactory, httpClient);

            FileUtility.Instance = fileSystem;

            Environment.SetEnvironmentVariable(EnvironmentSettingNames.WebSiteAuthEncryptionKey, TestHelpers.GenerateKeyHexString());
            Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", "appName");

            // Act
            (var success, var error) = await webManager.TrySyncTriggers();

            var content = contentBuilder.ToString();

            // Assert
            Assert.True(success, "SyncTriggers should return success true");
            Assert.True(string.IsNullOrEmpty(error), "Error should be null or empty");
            Assert.Equal(expectedSyncTriggersPayload, content);
        }
        public WebFunctionsManagerTests()
        {
            _testRootScriptPath     = Path.GetTempPath();
            _testHostConfigFilePath = Path.Combine(_testRootScriptPath, ScriptConstants.HostMetadataFileName);
            FileUtility.DeleteFileSafe(_testHostConfigFilePath);

            _hostOptions = new ScriptApplicationHostOptions
            {
                ScriptPath   = @"x:\root",
                IsSelfHost   = false,
                LogPath      = @"x:\tmp\log",
                SecretsPath  = @"x:\secrets",
                TestDataPath = @"x:\test"
            };

            string functionsPath = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\..\sample");

            var fileSystem                = CreateFileSystem(_hostOptions);
            var loggerFactory             = MockNullLoggerFactory.CreateLoggerFactory();
            var contentBuilder            = new StringBuilder();
            var httpClient                = CreateHttpClient(contentBuilder);
            var factory                   = new TestOptionsFactory <ScriptApplicationHostOptions>(_hostOptions);
            var tokenSource               = new TestChangeTokenSource <ScriptApplicationHostOptions>();
            var changeTokens              = new[] { tokenSource };
            var optionsMonitor            = new OptionsMonitor <ScriptApplicationHostOptions>(factory, changeTokens, factory);
            var secretManagerProviderMock = new Mock <ISecretManagerProvider>(MockBehavior.Strict);
            var secretManagerMock         = new Mock <ISecretManager>(MockBehavior.Strict);

            secretManagerProviderMock.SetupGet(p => p.Current).Returns(secretManagerMock.Object);
            var hostSecretsInfo = new HostSecretsInfo();

            secretManagerMock.Setup(p => p.GetHostSecretsAsync()).ReturnsAsync(hostSecretsInfo);
            Dictionary <string, string> functionSecrets = new Dictionary <string, string>();

            secretManagerMock.Setup(p => p.GetFunctionSecretsAsync("httptrigger", false)).ReturnsAsync(functionSecrets);

            var configurationMock      = new Mock <IConfiguration>(MockBehavior.Strict);
            var hostIdProviderMock     = new Mock <IHostIdProvider>(MockBehavior.Strict);
            var mockWebHostEnvironment = new Mock <IScriptWebHostEnvironment>(MockBehavior.Strict);

            mockWebHostEnvironment.SetupGet(p => p.InStandbyMode).Returns(false);
            _mockEnvironment = new Mock <IEnvironment>(MockBehavior.Strict);
            _mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteContainerReady)).Returns("1");
            _mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.CoreToolsEnvironment)).Returns((string)null);
            _mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHostName)).Returns(TestHostName);
            var hostNameProvider = new HostNameProvider(_mockEnvironment.Object, loggerFactory.CreateLogger <HostNameProvider>());

            var workerOptions = new LanguageWorkerOptions();

            FileUtility.Instance = fileSystem;
            _fileSystem          = fileSystem;
            var languageWorkerOptions = new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings());
            var metadataProvider      = new FunctionMetadataProvider(optionsMonitor, languageWorkerOptions, NullLogger <FunctionMetadataProvider> .Instance, new TestMetricsLogger());
            var functionsSyncManager  = new FunctionsSyncManager(configurationMock.Object, hostIdProviderMock.Object, optionsMonitor, loggerFactory.CreateLogger <FunctionsSyncManager>(), httpClient, secretManagerProviderMock.Object, mockWebHostEnvironment.Object, _mockEnvironment.Object, hostNameProvider, metadataProvider);

            _webFunctionsManager = new WebFunctionsManager(optionsMonitor, new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient, secretManagerProviderMock.Object, functionsSyncManager, hostNameProvider, metadataProvider);
        }
示例#4
0
        public async Task GetRoutePrefix_Succeeds(string content, string expected)
        {
            if (content != null)
            {
                File.WriteAllText(_testHostConfigFilePath, content);
            }

            string prefix = await WebFunctionsManager.GetRoutePrefix(_testRootScriptPath);
            Assert.Equal(expected, prefix);
        }
示例#5
0
        public void Disables_Ssl_If_SkipSslValidation_Enabled(int skipSslValidation, string syncTriggersUri)
        {
            var vars = new Dictionary <string, string>
            {
                { EnvironmentSettingNames.SkipSslValidation, skipSslValidation.ToString() },
                { EnvironmentSettingNames.AzureWebsiteHostName, "sitename" },
            };

            using (var env = new TestScopedEnvironmentVariable(vars))
            {
                var httpRequest = WebFunctionsManager.BuildSyncTriggersRequest();
                Assert.Equal(syncTriggersUri, httpRequest.RequestUri.AbsoluteUri);
                Assert.Equal(HttpMethod.Post, httpRequest.Method);
            }
        }
        public void ReadFunctionsMetadataSucceeds()
        {
            string functionsPath = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\..\sample");
            // Setup
            var fileSystem                = CreateFileSystem(_hostOptions.ScriptPath);
            var loggerFactory             = MockNullLoggerFactory.CreateLoggerFactory();
            var contentBuilder            = new StringBuilder();
            var httpClient                = CreateHttpClient(contentBuilder);
            var factory                   = new TestOptionsFactory <ScriptApplicationHostOptions>(_hostOptions);
            var tokenSource               = new TestChangeTokenSource();
            var changeTokens              = new[] { tokenSource };
            var optionsMonitor            = new OptionsMonitor <ScriptApplicationHostOptions>(factory, changeTokens, factory);
            var secretManagerProviderMock = new Mock <ISecretManagerProvider>(MockBehavior.Strict);
            var secretManagerMock         = new Mock <ISecretManager>(MockBehavior.Strict);

            secretManagerProviderMock.SetupGet(p => p.Current).Returns(secretManagerMock.Object);
            var hostSecretsInfo = new HostSecretsInfo();

            secretManagerMock.Setup(p => p.GetHostSecretsAsync()).ReturnsAsync(hostSecretsInfo);
            Dictionary <string, string> functionSecrets = new Dictionary <string, string>();

            secretManagerMock.Setup(p => p.GetFunctionSecretsAsync("httptrigger", false)).ReturnsAsync(functionSecrets);

            var configurationMock      = new Mock <IConfiguration>(MockBehavior.Strict);
            var hostIdProviderMock     = new Mock <IHostIdProvider>(MockBehavior.Strict);
            var mockWebHostEnvironment = new Mock <IScriptWebHostEnvironment>(MockBehavior.Strict);

            mockWebHostEnvironment.SetupGet(p => p.InStandbyMode).Returns(false);
            var mockEnvironment = new Mock <IEnvironment>(MockBehavior.Strict);

            mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteContainerReady)).Returns("1");
            mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.CoreToolsEnvironment)).Returns((string)null);
            var functionsSyncManager = new FunctionsSyncManager(configurationMock.Object, hostIdProviderMock.Object, optionsMonitor, new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient, secretManagerProviderMock.Object, mockWebHostEnvironment.Object, mockEnvironment.Object);
            var webManager           = new WebFunctionsManager(optionsMonitor, new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient, secretManagerProviderMock.Object, functionsSyncManager);

            FileUtility.Instance = fileSystem;
            IEnumerable <FunctionMetadata> metadata = webManager.GetFunctionsMetadata();
            var jsFunctions      = metadata.Where(funcMetadata => funcMetadata.Language == LanguageWorkerConstants.NodeLanguageWorkerName).ToList();
            var unknownFunctions = metadata.Where(funcMetadata => string.IsNullOrEmpty(funcMetadata.Language)).ToList();

            Assert.Equal(2, jsFunctions.Count());
            Assert.Equal(1, unknownFunctions.Count());
        }
        public static void ReadFunctionsMetadataSucceeds()
        {
            string functionsPath = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\..\sample");
            // Setup
            var settings       = CreateWebSettings();
            var fileSystem     = CreateFileSystem(settings.ScriptPath);
            var loggerFactory  = MockNullLogerFactory.CreateLoggerFactory();
            var contentBuilder = new StringBuilder();
            var httpClient     = CreateHttpClient(contentBuilder);
            var webManager     = new WebFunctionsManager(new OptionsWrapper <ScriptApplicationHostOptions>(settings), new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient);

            FileUtility.Instance = fileSystem;
            IEnumerable <FunctionMetadata> metadata = webManager.GetFunctionsMetadata();
            var jsFunctions      = metadata.Where(funcMetadata => funcMetadata.Language == LanguageWorkerConstants.NodeLanguageWorkerName).ToList();
            var unknownFunctions = metadata.Where(funcMetadata => string.IsNullOrEmpty(funcMetadata.Language)).ToList();

            Assert.Equal(2, jsFunctions.Count());
            Assert.Equal(1, unknownFunctions.Count());
        }