public void DisableRemoteDesktopForWebAndWorkerRoles()
 {
     using (FileSystemHelper files = new FileSystemHelper(this))
     {
         files.CreateAzureSdkDirectoryAndImportPublishSettings();
         string rootPath = files.CreateNewService("NEW_SERVICE");
         addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WebRole" };
         addNodeWebCmdlet.ExecuteCmdlet();
         addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WorkerRole" };
         addNodeWorkerCmdlet.ExecuteCmdlet();
         disableRDCmdlet.DisableRemoteDesktop();
     }
 }
        public void SetupTest()
        {
            GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir;
            CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();
            mockCommandRuntime = new MockCommandRuntime();

            addNodeWebCmdlet = new AddAzureNodeWebRoleCommand();
            addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand();
            cmdlet = new SaveAzureServiceProjectPackageCommand();

            addNodeWorkerCmdlet.CommandRuntime = mockCommandRuntime;
            addNodeWebCmdlet.CommandRuntime = mockCommandRuntime;
            cmdlet.CommandRuntime = mockCommandRuntime;
        }
        public void AddAzureNodeWebRoleProcess()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string roleName = "WebRole1";
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime };
                string expectedVerboseMessage = string.Format(Resources.AddRoleMessageCreateNode, rootPath, roleName);

                addNodeWebCmdlet.ExecuteCmdlet();

                AzureAssert.ScaffoldingExists(Path.Combine(rootPath, roleName), Path.Combine(Resources.NodeScaffolding, Resources.WebRole));
                Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).GetVariableValue<string>(Parameters.RoleName));
                Assert.AreEqual<string>(expectedVerboseMessage, mockCommandRuntime.VerboseStream[0]);
            }
        }
        public void EnableAzureMemcacheRoleProcess()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                string cacheRoleName = "WorkerRole";
                string webRoleName = "WebRole";
                string expectedMessage = string.Format(Resources.EnableMemcacheMessage, webRoleName, cacheRoleName, Resources.MemcacheEndpointPort);

                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
                addNodeWebCmdlet.ExecuteCmdlet();
                addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
                mockCommandRuntime.ResetPipelines();
                enableCacheCmdlet.PassThru = true;
                enableCacheCmdlet.CacheRuntimeVersion = "1.8.0";
                enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath);

                AssertCachingEnabled(files, serviceName, rootPath, webRoleName, expectedMessage);
            }
        }
 public void EnableDisableEnableRemoteDesktopForWebAndWorkerRoles()
 {
     using (FileSystemHelper files = new FileSystemHelper(this))
     {
         files.CreateAzureSdkDirectoryAndImportPublishSettings();
         string rootPath = files.CreateNewService("NEW_SERVICE");
         addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WebRole" };
         addNodeWebCmdlet.ExecuteCmdlet();
         addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WorkerRole" };
         addNodeWorkerCmdlet.ExecuteCmdlet();
         EnableAzureRemoteDesktopCommandTest.EnableRemoteDesktop("user", "GoodPassword!");
         disableRDCmdlet.DisableRemoteDesktop();
         EnableAzureRemoteDesktopCommandTest.EnableRemoteDesktop("user", "GoodPassword!");
         // Verify the roles have been setup with forwarding, access,
         // and certs
         AzureService service = new AzureService(rootPath, null);
         EnableAzureRemoteDesktopCommandTest.VerifyWebRole(service.Components.Definition.WebRole[0], false);
         EnableAzureRemoteDesktopCommandTest.VerifyWorkerRole(service.Components.Definition.WorkerRole[0], true);
         EnableAzureRemoteDesktopCommandTest.VerifyRoleSettings(service);
     }
 }
        public void DisableRemoteDesktopForWebRole()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                files.CreateAzureSdkDirectoryAndImportPublishSettings();
                string rootPath = files.CreateNewService("NEW_SERVICE");
                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WebRole" };
                addNodeWebCmdlet.ExecuteCmdlet();
                disableRDCmdlet.PassThru = true;
                disableRDCmdlet.DisableRemoteDesktop();

                Assert.IsTrue((bool)mockCommandRuntime.OutputPipeline[1]);
            }
        }
        public void TestResolveRuntimePackageUrls()
        {
            // Create a temp directory that we'll use to "publish" our service
            using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true })
            {
                // Import our default publish settings
                files.CreateAzureSdkDirectoryAndImportPublishSettings();

                // Create a new service that we're going to publish
                string serviceName = "TEST_SERVICE_NAME";

                string rootPath = files.CreateNewService(serviceName);

                // Add web and worker roles
                string defaultWebRoleName = "WebRoleDefault";
                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = defaultWebRoleName, Instances = 2 };
                addNodeWebCmdlet.ExecuteCmdlet();

                string defaultWorkerRoleName = "WorkerRoleDefault";
                addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = defaultWorkerRoleName, Instances = 2 };
                addNodeWorkerCmdlet.ExecuteCmdlet();

                AddAzureNodeWebRoleCommand matchWebRole = addNodeWebCmdlet;
                string matchWebRoleName = "WebRoleExactMatch";
                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = matchWebRoleName, Instances = 2 };
                addNodeWebCmdlet.ExecuteCmdlet();

                AddAzureNodeWorkerRoleCommand matchWorkerRole = addNodeWorkerCmdlet;
                string matchWorkerRoleName = "WorkerRoleExactMatch";
                addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = matchWorkerRoleName, Instances = 2 };
                addNodeWorkerCmdlet.ExecuteCmdlet();

                AddAzureNodeWebRoleCommand overrideWebRole = addNodeWebCmdlet;
                string overrideWebRoleName = "WebRoleOverride";
                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = overrideWebRoleName, Instances = 2 };
                addNodeWebCmdlet.ExecuteCmdlet();

                AddAzureNodeWorkerRoleCommand overrideWorkerRole = addNodeWorkerCmdlet;
                string overrideWorkerRoleName = "WorkerRoleOverride";
                addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = overrideWorkerRoleName, Instances = 2 };
                addNodeWorkerCmdlet.ExecuteCmdlet();

                string cacheWebRoleName = "cacheWebRole";
                string cacheRuntimeVersion = "1.7.0";
                AddAzureNodeWebRoleCommand addAzureWebRole = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = cacheWebRoleName };
                addAzureWebRole.ExecuteCmdlet();

                CloudServiceProject testService = new CloudServiceProject(rootPath, null);
                RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, matchWebRoleName, testService.Paths, version: "0.8.2");
                RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, matchWorkerRoleName, testService.Paths, version: "0.8.2");
                RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, overrideWebRoleName, testService.Paths, overrideUrl: "http://OVERRIDE");
                RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, overrideWorkerRoleName, testService.Paths, overrideUrl: "http://OVERRIDE");
                testService.AddRoleRuntime(testService.Paths, cacheWebRoleName, Resources.CacheRuntimeValue, cacheRuntimeVersion, RuntimePackageHelper.GetTestManifest(files));
                testService.Components.Save(testService.Paths);

                // Get the publishing process started by creating the package
                testService.ResolveRuntimePackageUrls(RuntimePackageHelper.GetTestManifest(files));

                CloudServiceProject updatedService = new CloudServiceProject(testService.Paths.RootPath, null);

                RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, defaultWebRoleName, "http://cdn/node/default.exe;http://cdn/iisnode/default.exe", null);
                RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, defaultWorkerRoleName, "http://cdn/node/default.exe", null);
                RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, matchWorkerRoleName, "http://cdn/node/foo.exe", null);
                RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, matchWebRoleName, "http://cdn/node/foo.exe;http://cdn/iisnode/default.exe", null);
                RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, overrideWebRoleName, null, "http://OVERRIDE");
                RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, overrideWorkerRoleName, null, "http://OVERRIDE");
                RuntimePackageHelper.ValidateRoleRuntimeVariable(updatedService.Components.GetRoleStartup(cacheWebRoleName), Resources.CacheRuntimeVersionKey, cacheRuntimeVersion);
            }
        }
        public void EnableAzureMemcacheRoleProcessAlreadyEnabledFail()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                string cacheRoleName = "WorkerRole";
                string webRoleName = "WebRole";
                string expected = string.Format(Resources.CacheAlreadyEnabledMessage, webRoleName);

                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
                addNodeWebCmdlet.ExecuteCmdlet();
                addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
                enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath);

                Testing.AssertThrows<Exception>(() => enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath));
            }
        }
        public void EnableAzureMemcacheWithNoCacheWorkerRolesFail()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                string webRoleName = "WebRole";
                string expectedMessage = string.Format(Resources.NoCacheWorkerRoles);

                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
                addNodeWebCmdlet.ExecuteCmdlet();
                addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WorkerRole" };
                addNodeWorkerCmdlet.ExecuteCmdlet();
                mockCommandRuntime.ResetPipelines();
                enableCacheCmdlet.PassThru = true;
                enableCacheCmdlet.CacheRuntimeVersion = "1.8.0";

                Testing.AssertThrows<Exception>(() => enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, null, rootPath), expectedMessage);
            }
        }
 public void EnableRemoteDesktopUnicodeAndShortPasswordFails()
 {
     using (FileSystemHelper files = new FileSystemHelper(this))
     {
         files.CreateAzureSdkDirectoryAndImportPublishSettings();
         string rootPath = files.CreateNewService("NEW_SERVICE");
         addNodeWebCmdlet = new AddAzureNodeWebRoleCommand()
         {
             RootPath = rootPath,
             CommandRuntime = mockCommandRuntime,
             Name = "WebRole",
             Instances = 1
         };
         addNodeWebCmdlet.ExecuteCmdlet();
         Testing.AssertThrows<ArgumentException>(() => EnableRemoteDesktop("㯑䲘䄂㮉", "㯑䲘"));
     }
 }
        public void EnableRemoteDesktopUnicode()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                files.CreateAzureSdkDirectoryAndImportPublishSettings();
                string rootPath = files.CreateNewService("NEW_SERVICE");
                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand()
                {
                    RootPath = rootPath,
                    CommandRuntime = mockCommandRuntime,
                    Name = "WebRole",
                    Instances = 1
                };
                addNodeWebCmdlet.ExecuteCmdlet();
                EnableRemoteDesktop("㯑䲘䄂㮉", "㯑䲘䄂㮉㮉㮉㮉L");

                // Verify the role has been setup with forwarding, access,
                // and certs
                CloudServiceProject service = new CloudServiceProject(rootPath, null);
                VerifyWebRole(service.Components.Definition.WebRole[0], true);
                VerifyRoleSettings(service);
            }
        }
        public void EnableRemoteDesktopForWebAndWorkerRoles()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                files.CreateAzureSdkDirectoryAndImportPublishSettings();
                string rootPath = files.CreateNewService("NEW_SERVICE");
                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WebRole", Instances = 1 };
                addNodeWebCmdlet.ExecuteCmdlet();
                addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WorkerRole", Instances = 1 };
                addNodeWorkerCmdlet.ExecuteCmdlet();
                mockCommandRuntime.ResetPipelines();
                EnableRemoteDesktop("user", "GoodPassword!");

                // Verify the roles have been setup with forwarding, access,
                // and certs
                CloudServiceProject service = new CloudServiceProject(rootPath, null);
                VerifyWebRole(service.Components.Definition.WebRole[0], false);
                VerifyWorkerRole(service.Components.Definition.WorkerRole[0], true);
                VerifyRoleSettings(service);
                Assert.AreEqual<int>(0, mockCommandRuntime.OutputPipeline.Count);
            }
        }