public async Task Assigns_Context_From_CONTAINER_START_CONTEXT() { var containerEncryptionKey = TestHelpers.GenerateKeyHexString(); var hostAssignmentContext = GetHostAssignmentContext(); var encryptedHostAssignmentContext = GetEncryptedHostAssignmentContext(hostAssignmentContext, containerEncryptionKey); var serializedContext = JsonConvert.SerializeObject(new { encryptedContext = encryptedHostAssignmentContext }); var vars = new Dictionary <string, string> { { EnvironmentSettingNames.ContainerStartContext, serializedContext }, { EnvironmentSettingNames.ContainerEncryptionKey, containerEncryptionKey }, }; // Enable Linux Container AddLinuxContainerSettings(vars); _instanceManagerMock.Setup(manager => manager.StartAssignment(It.Is <HostAssignmentContext>(context => hostAssignmentContext.Equals(context)))).Returns(true); using (var env = new TestScopedEnvironmentVariable(vars)) { await _initializationHostService.StartAsync(CancellationToken.None); } _instanceManagerMock.Verify(manager => manager.StartAssignment(It.Is <HostAssignmentContext>(context => hostAssignmentContext.Equals(context))), Times.Once); }
public async Task Does_Not_Assign_If_Context_Not_Available() { var initializationHostService = new LinuxContainerInitializationHostService(_environment, _instanceManagerMock.Object, NullLogger <LinuxContainerInitializationHostService> .Instance, _startupContextProvider); await initializationHostService.StartAsync(CancellationToken.None); _instanceManagerMock.Verify(manager => manager.StartAssignment(It.IsAny <HostAssignmentContext>()), Times.Never); }
public async Task Runs_In_Linux_Container_Mode_Only() { _environment.SetEnvironmentVariable(ContainerName, null); _environment.SetEnvironmentVariable(AzureWebsiteInstanceId, null); Assert.False(_environment.IsLinuxConsumption()); var initializationHostService = new LinuxContainerInitializationHostService(_environment, _instanceManagerMock.Object, NullLogger <LinuxContainerInitializationHostService> .Instance, _startupContextProvider); await initializationHostService.StartAsync(CancellationToken.None); }
public async Task Runs_In_Linux_Container_Mode_Only() { var settingsManagerMock = new Mock <ScriptSettingsManager>(MockBehavior.Strict, null); var initializationHostService = new LinuxContainerInitializationHostService(settingsManagerMock.Object, _instanceManagerMock.Object, NullLoggerFactory.Instance); settingsManagerMock.Setup(manager => manager.IsLinuxContainerEnvironment).Returns(false); await initializationHostService.StartAsync(CancellationToken.None); settingsManagerMock.Verify(settingsManager => settingsManager.GetSetting(It.IsAny <string>()), Times.Never); }
public async Task Does_Not_Assign_If_Context_Not_Available() { var vars = new Dictionary <string, string>(); AddLinuxContainerSettings(vars); var environment = new TestEnvironment(vars); var initializationHostService = new LinuxContainerInitializationHostService(environment, _instanceManagerMock.Object, NullLogger <LinuxContainerInitializationHostService> .Instance); await initializationHostService.StartAsync(CancellationToken.None); _instanceManagerMock.Verify(manager => manager.StartAssignment(It.IsAny <HostAssignmentContext>(), It.Is <bool>(w => !w)), Times.Never); }
public async Task Runs_In_Linux_Container_Mode_Only() { // These settings being null will cause IsLinuxContainerEnvironment to return false. var environmentMock = new Mock <IEnvironment>(MockBehavior.Strict); environmentMock.Setup(env => env.GetEnvironmentVariable(ContainerName)).Returns <string>(null); environmentMock.Setup(env => env.GetEnvironmentVariable(AzureWebsiteInstanceId)).Returns <string>(null); var initializationHostService = new LinuxContainerInitializationHostService(environmentMock.Object, _instanceManagerMock.Object, NullLogger <LinuxContainerInitializationHostService> .Instance); await initializationHostService.StartAsync(CancellationToken.None); // Make sure no other environment variables were checked environmentMock.Verify(env => env.GetEnvironmentVariable(It.Is <string>(p => p != ContainerName && p != AzureWebsiteInstanceId)), Times.Never); }
public async Task Assigns_Context_From_CONTAINER_START_CONTEXT() { var containerEncryptionKey = TestHelpers.GenerateKeyHexString(); var hostAssignmentContext = GetHostAssignmentContext(); var secrets = new FunctionAppSecrets(); secrets.Host = new FunctionAppSecrets.HostSecrets { Master = "test-key", Function = new Dictionary <string, string> { { "host-function-key-1", "test-key" } }, System = new Dictionary <string, string> { { "host-system-key-1", "test-key" } } }; hostAssignmentContext.Secrets = secrets; hostAssignmentContext.MSIContext = new MSIContext(); var encryptedHostAssignmentContext = GetEncryptedHostAssignmentContext(hostAssignmentContext, containerEncryptionKey); var serializedContext = JsonConvert.SerializeObject(new { encryptedContext = encryptedHostAssignmentContext }); _environment.SetEnvironmentVariable(ContainerStartContext, serializedContext); _environment.SetEnvironmentVariable(ContainerEncryptionKey, containerEncryptionKey); AddLinuxConsumptionSettings(_environment); _instanceManagerMock.Setup(m => m.SpecializeMSISidecar(It.Is <HostAssignmentContext>(context => hostAssignmentContext.Equals(context) && !context.IsWarmupRequest))).Returns(Task.FromResult(string.Empty)); _instanceManagerMock.Setup(manager => manager.StartAssignment(It.Is <HostAssignmentContext>(context => hostAssignmentContext.Equals(context) && !context.IsWarmupRequest))).Returns(true); var initializationHostService = new LinuxContainerInitializationHostService(_environment, _instanceManagerMock.Object, NullLogger <LinuxContainerInitializationHostService> .Instance, _startupContextProvider); await initializationHostService.StartAsync(CancellationToken.None); _instanceManagerMock.Verify(m => m.SpecializeMSISidecar(It.Is <HostAssignmentContext>(context => hostAssignmentContext.Equals(context) && !context.IsWarmupRequest)), Times.Once); _instanceManagerMock.Verify(manager => manager.StartAssignment(It.Is <HostAssignmentContext>(context => hostAssignmentContext.Equals(context) && !context.IsWarmupRequest)), Times.Once); var hostSecrets = _startupContextProvider.GetHostSecretsOrNull(); Assert.Equal("test-key", hostSecrets.MasterKey); }