Example #1
0
        public void PullApiTestBitbucketFormat()
        {
            string bitbucketPayload = @"{ ""canon_url"": ""https://github.com"", ""commits"": [ { ""author"": ""davidebbo"", ""branch"": ""master"", ""files"": [ { ""file"": ""Mvc3Application/Views/Home/Index.cshtml"", ""type"": ""modified"" } ], ""message"": ""Blah2\n"", ""node"": ""e550351c5188"", ""parents"": [ ""297fcc65308c"" ], ""raw_author"": ""davidebbo <*****@*****.**>"", ""raw_node"": ""e550351c5188681a9ed889e07bc1fbc0bd51a0f2"", ""revision"": null, ""size"": -1, ""timestamp"": ""2012-09-20 03:11:20"", ""utctimestamp"": ""2012-09-20 01:11:20+00:00"" } ], ""repository"": { ""absolute_url"": ""/KuduApps/SimpleWebApplication"", ""fork"": false, ""is_private"": false, ""name"": ""Mvc3Application"", ""owner"": ""davidebbo"", ""scm"": ""git"", ""slug"": ""mvc3application"", ""website"": """" }, ""user"": ""davidebbo"" }";
            string appName          = KuduUtils.GetRandomWebsiteName("PullApiTestBitbucketFormat");

            ApplicationManager.Run(appName, appManager =>
            {
                var handler = new HttpClientHandler
                {
                    Credentials = appManager.DeploymentManager.Credentials
                };

                var client = new HttpClient(handler)
                {
                    BaseAddress = new Uri(appManager.ServiceUrl),
                    Timeout     = TimeSpan.FromMinutes(5)
                };

                client.DefaultRequestHeaders.Add("User-Agent", "Bitbucket.org");

                var post = new Dictionary <string, string>
                {
                    { "payload", bitbucketPayload }
                };

                client.PostAsync("deploy", new FormUrlEncodedContent(post)).Wait();

                var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                Assert.Equal(1, results.Count);
                Assert.Equal(DeployStatus.Success, results[0].Status);
                KuduAssert.VerifyUrl(appManager.SiteUrl, "Welcome to ASP.NET!");
            });
        }
Example #2
0
        public void PullApiTestGenericFormat()
        {
            string payload = @"{ ""oldRef"": ""0000000000000000000"", ""newRef"": ""7e2a599e2d28665047ec347ab36731c905c95e8b"", ""url"": ""https://github.com/KuduApps/SimpleWebApplication.git"", ""deployer"" : ""me!"" }";
            string appName = KuduUtils.GetRandomWebsiteName("PullApiTestGenericFormat");

            ApplicationManager.Run(appName, appManager =>
            {
                var handler = new HttpClientHandler
                {
                    Credentials = appManager.DeploymentManager.Credentials
                };

                var client = new HttpClient(handler)
                {
                    BaseAddress = new Uri(appManager.ServiceUrl),
                    Timeout     = TimeSpan.FromMinutes(5)
                };

                var post = new Dictionary <string, string>
                {
                    { "payload", payload }
                };

                client.PostAsync("deploy", new FormUrlEncodedContent(post)).Wait();

                var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                Assert.Equal(1, results.Count);
                Assert.Equal(DeployStatus.Success, results[0].Status);
                KuduAssert.VerifyUrl(appManager.SiteUrl, "Welcome to ASP.NET!");
                Assert.Equal("me!", results[0].Deployer);
            });
        }
Example #3
0
        public void PullApiTestGitHubFormat()
        {
            string githubPayload = @"{ ""after"": ""7e2a599e2d28665047ec347ab36731c905c95e8b"", ""before"": ""7e2a599e2d28665047ec347ab36731c905c95e8b"", ""commits"": [], ""compare"": ""https://github.com/KuduApps/GitHookTest/compare/7e2a599e2d28...7e2a599e2d28"", ""created"": false, ""deleted"": false, ""forced"": false, ""head_commit"": { ""added"": [ "".gitignore"", ""SimpleWebApplication.sln"", ""SimpleWebApplication/About.aspx"", ""SimpleWebApplication/About.aspx.cs"", ""SimpleWebApplication/About.aspx.designer.cs"", ""SimpleWebApplication/Account/ChangePassword.aspx"", ""SimpleWebApplication/Account/ChangePassword.aspx.cs"", ""SimpleWebApplication/Account/ChangePassword.aspx.designer.cs"", ""SimpleWebApplication/Account/ChangePasswordSuccess.aspx"", ""SimpleWebApplication/Account/ChangePasswordSuccess.aspx.cs"", ""SimpleWebApplication/Account/ChangePasswordSuccess.aspx.designer.cs"", ""SimpleWebApplication/Account/Login.aspx"", ""SimpleWebApplication/Account/Login.aspx.cs"", ""SimpleWebApplication/Account/Login.aspx.designer.cs"", ""SimpleWebApplication/Account/Register.aspx"", ""SimpleWebApplication/Account/Register.aspx.cs"", ""SimpleWebApplication/Account/Register.aspx.designer.cs"", ""SimpleWebApplication/Account/Web.config"", ""SimpleWebApplication/Default.aspx"", ""SimpleWebApplication/Default.aspx.cs"", ""SimpleWebApplication/Default.aspx.designer.cs"", ""SimpleWebApplication/Global.asax"", ""SimpleWebApplication/Global.asax.cs"", ""SimpleWebApplication/Properties/AssemblyInfo.cs"", ""SimpleWebApplication/Scripts/jquery-1.4.1-vsdoc.js"", ""SimpleWebApplication/Scripts/jquery-1.4.1.js"", ""SimpleWebApplication/Scripts/jquery-1.4.1.min.js"", ""SimpleWebApplication/SimpleWebApplication.csproj"", ""SimpleWebApplication/Site.Master"", ""SimpleWebApplication/Site.Master.cs"", ""SimpleWebApplication/Site.Master.designer.cs"", ""SimpleWebApplication/Styles/Site.css"", ""SimpleWebApplication/Web.Debug.config"", ""SimpleWebApplication/Web.Release.config"", ""SimpleWebApplication/Web.config"" ], ""author"": { ""email"": ""*****@*****.**"", ""name"": ""davidebbo"", ""username"": ""davidebbo"" }, ""committer"": { ""email"": ""*****@*****.**"", ""name"": ""davidebbo"", ""username"": ""davidebbo"" }, ""distinct"": false, ""id"": ""7e2a599e2d28665047ec347ab36731c905c95e8b"", ""message"": ""Initial"", ""modified"": [], ""removed"": [], ""timestamp"": ""2011-11-21T23:07:42-08:00"", ""url"": ""https://github.com/KuduApps/GitHookTest/commit/7e2a599e2d28665047ec347ab36731c905c95e8b"" }, ""pusher"": { ""name"": ""none"" }, ""ref"": ""refs/heads/master"", ""repository"": { ""created_at"": ""2012-06-28T00:07:55-07:00"", ""description"": """", ""fork"": false, ""forks"": 1, ""has_downloads"": true, ""has_issues"": true, ""has_wiki"": true, ""language"": ""ASP"", ""name"": ""GitHookTest"", ""open_issues"": 0, ""organization"": ""KuduApps"", ""owner"": { ""email"": ""*****@*****.**"", ""name"": ""KuduApps"" }, ""private"": false, ""pushed_at"": ""2012-06-28T00:11:48-07:00"", ""size"": 188, ""url"": ""https://github.com/KuduApps/SimpleWebApplication"", ""watchers"": 1 } }";
            string appName       = KuduUtils.GetRandomWebsiteName("PullApiTestGitHubFormat");

            ApplicationManager.Run(appName, appManager =>
            {
                var handler = new HttpClientHandler
                {
                    Credentials = appManager.DeploymentManager.Credentials
                };

                var client = new HttpClient(handler)
                {
                    BaseAddress = new Uri(appManager.ServiceUrl),
                    Timeout     = TimeSpan.FromMinutes(5)
                };

                var post = new Dictionary <string, string>
                {
                    { "payload", githubPayload }
                };

                client.PostAsync("deploy", new FormUrlEncodedContent(post)).Wait();

                var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                Assert.Equal(1, results.Count);
                Assert.Equal(DeployStatus.Success, results[0].Status);
                KuduAssert.VerifyUrl(appManager.SiteUrl, "Welcome to ASP.NET!");
            });
        }
        public void PushSimpleWapWithCustomDeploymentScript()
        {
            // Arrange
            string repositoryName = "WapWithCustomDeploymentScript";
            string appName        = KuduUtils.GetRandomWebsiteName("WapWithCustomDeploymentScript");
            string cloneUrl       = "https://github.com/KuduApps/CustomBuildScript.git";

            using (var repo = Git.Clone(repositoryName, cloneUrl))
            {
                repo.WriteFile(".deployment", @"
[config]
command = deploy.cmd");
                Git.Commit(repo.PhysicalPath, "Custom build script added");

                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    GitDeploymentResult deployResult = appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, "DEBUG");
                });
            }
        }
        public void PushSimpleWapWithInlineCommand()
        {
            // Arrange
            string repositoryName = "PushSimpleWapWithInlineCommand";
            string appName        = KuduUtils.GetRandomWebsiteName("PushSimpleWapWithInlineCommand");
            string cloneUrl       = "https://github.com/KuduApps/CustomBuildScript.git";

            using (var repo = Git.Clone(repositoryName, cloneUrl))
            {
                repo.WriteFile(".deployment", @"
[config]
command = msbuild SimpleWebApplication/SimpleWebApplication.csproj /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir=""%DEPLOYMENT_TARGET%"";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Debug;SolutionDir=""%DEPLOYMENT_SOURCE%""");
                Git.Commit(repo.PhysicalPath, "Custom build command added");

                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    GitDeploymentResult deployResult = appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, "DEBUG");
                });
            }
        }
Example #6
0
        public void DeployingBranchThatExists()
        {
            string payload = @"{ ""oldRef"": ""0000000000000000000"", ""newRef"": ""ad21595c668f3de813463df17c04a3b23065fedc"", ""url"": ""https://github.com/KuduApps/RepoWithMultipleBranches.git"", ""deployer"" : ""me!"", branch: ""test"" }";
            string appName = KuduUtils.GetRandomWebsiteName("DeployingBranchThatExists");

            ApplicationManager.Run(appName, appManager =>
            {
                var handler = new HttpClientHandler
                {
                    Credentials = appManager.DeploymentManager.Credentials
                };

                var client = new HttpClient(handler)
                {
                    BaseAddress = new Uri(appManager.ServiceUrl),
                    Timeout     = TimeSpan.FromMinutes(5)
                };

                var post = new Dictionary <string, string>
                {
                    { "payload", payload }
                };

                client.PostAsync("deploy", new FormUrlEncodedContent(post)).Wait();

                var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                Assert.Equal(1, results.Count);
                Assert.Equal(DeployStatus.Success, results[0].Status);
                KuduAssert.VerifyUrl(appManager.SiteUrl, "Master branch");
                Assert.Equal("me!", results[0].Deployer);
            });
        }
Example #7
0
        public void DeletesToRepositoryArePropagatedForNonWaps()
        {
            string repositoryName = "Bakery10";
            string appName        = KuduUtils.GetRandomWebsiteName("DeleteForNonWaps");

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    string deletePath = Path.Combine(repo.PhysicalPath, @"Styles");

                    // Act
                    appManager.GitDeploy(repo.PhysicalPath);

                    // Assert
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl + "Styles/Site.css", statusCode: HttpStatusCode.OK);


                    Directory.Delete(deletePath, recursive: true);
                    Git.Commit(repo.PhysicalPath, "Deleted all styles");

                    appManager.GitDeploy(repo.PhysicalPath);
                    results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(2, results.Count);
                    Assert.Equal(DeployStatus.Success, results[1].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl + "Styles/Site.css", statusCode: HttpStatusCode.NotFound);
                });
            }
        }
Example #8
0
        public void SetGetDeleteValue()
        {
            // Arrange
            string repositoryName = "Mvc3Application";
            string appName        = KuduUtils.GetRandomWebsiteName("SetValue");

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    appManager.SettingsManager.SetValue("x", "1").Wait();

                    // Assert
                    string result = appManager.SettingsManager.GetValue("x").Result;

                    Assert.Equal("1", result);

                    appManager.SettingsManager.Delete("x").Wait();

                    // Act
                    var ex = KuduAssert.ThrowsUnwrapped <HttpRequestException>(() => appManager.SettingsManager.GetValue("x").Wait());

                    // Assert
                    Assert.Equal("Response status code does not indicate success: 404 (Not Found).", ex.Message);
                });
            }
        }
Example #9
0
        public async Task TestDropboxBasic()
        {
            OAuthInfo oauth = GetOAuthInfo();

            if (oauth == null)
            {
                // only run in private kudu
                return;
            }

            AccountInfo       account = GetAccountInfo(oauth);
            DropboxDeployInfo deploy  = GetDeployInfo("/BasicTest", oauth, account);

            string appName = "DropboxTest";
            await ApplicationManager.RunAsync(appName, async appManager =>
            {
                HttpClient client = HttpClientHelper.CreateClient(appManager.ServiceUrl, appManager.DeploymentManager.Credentials);
                var result        = await client.PostAsJsonAsync("deploy?scmType=Dropbox", deploy);
                result.EnsureSuccessful();

                await Task.WhenAll(
                    KuduAssert.VerifyUrlAsync(appManager.SiteUrl + "/default.html", "Hello Default!"),
                    KuduAssert.VerifyUrlAsync(appManager.SiteUrl + "/temp/temp.html", "Hello Temp!"),
                    KuduAssert.VerifyUrlAsync(appManager.SiteUrl + "/New Folder/New File.html", "Hello New File!")
                    );
            });
        }
Example #10
0
        public void PushAndDeployApps(string name, string repoName,
                                      string repoUrl, string repoCloneUrl,
                                      string defaultBranchName, string verificationText,
                                      HttpStatusCode expectedResponseCode, bool skip, string verificationLogText = null)
        {
            if (!skip)
            {
                string randomTestName = KuduUtils.GetRandomWebsiteName(repoName);
                using (var repo = Git.Clone(randomTestName, repoCloneUrl))
                {
                    ApplicationManager.Run(randomTestName, appManager =>
                    {
                        // Act
                        appManager.GitDeploy(repo.PhysicalPath, defaultBranchName);
                        var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                        // Assert
                        Assert.Equal(1, results.Count);
                        Assert.Equal(DeployStatus.Success, results[0].Status);
                        KuduAssert.VerifyUrl(appManager.SiteUrl, verificationText, expectedResponseCode);
                        if (!String.IsNullOrEmpty(verificationLogText.Trim()))
                        {
                            KuduAssert.VerifyLogOutput(appManager, results[0].Id, verificationLogText.Trim());
                        }
                    });
                }
                Debug.Write(String.Format("Test completed: {0}\n", name));
            }
            else
            {
                Debug.Write(String.Format("Test skipped: {0}\n", name));
            }
        }
Example #11
0
        private void VerifyDeploymentConfiguration(string siteName, string targetProject, string expectedText, DeployStatus expectedStatus = DeployStatus.Success, string expectedLog = null)
        {
            string name     = KuduUtils.GetRandomWebsiteName(siteName);
            string cloneUrl = "https://github.com/KuduApps/SpecificDeploymentConfiguration.git";

            using (var repo = Git.Clone(name, cloneUrl))
            {
                ApplicationManager.Run(name, appManager =>
                {
                    string deploymentFile = Path.Combine(repo.PhysicalPath, @".deployment");
                    File.WriteAllText(deploymentFile, String.Format(@"[config]
project = {0}", targetProject));
                    Git.Commit(name, "Updated configuration");

                    // Act
                    appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(expectedStatus, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, expectedText);
                    if (!String.IsNullOrEmpty(expectedLog))
                    {
                        KuduAssert.VerifyLogOutput(appManager, results[0].Id, expectedLog);
                    }
                });
            }
        }
        public void PushSimpleWapWithFailingCustomDeploymentScript()
        {
            // Arrange
            string repositoryName = "WapWithFailingCustomDeploymentScript";
            string appName        = KuduUtils.GetRandomWebsiteName("WapWithFailingCustomDeploymentScript");
            string cloneUrl       = "https://github.com/KuduApps/CustomBuildScript.git";

            using (var repo = Git.Clone(repositoryName, cloneUrl))
            {
                repo.WriteFile(".deployment", @"
[config]
command = deploy.cmd");
                repo.WriteFile("deploy.cmd", "bogus");
                Git.Commit(repo.PhysicalPath, "Updated the deploy file.");

                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    GitDeploymentResult deployResult = appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Failed, results[0].Status);
                    KuduAssert.VerifyLogOutput(appManager, results[0].Id, ">bogus");
                    KuduAssert.VerifyLogOutput(appManager, results[0].Id, "'bogus' is not recognized as an internal or external command");
                });
            }
        }
Example #13
0
        public void FirstPushDeletesPriorContent()
        {
            string repositoryName = "Bakery10";
            string appName        = KuduUtils.GetRandomWebsiteName("FirstPushDelPrior");

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    appManager.ProjectSystem.WriteAllText("foo.txt", "This is a test file");
                    string url = appManager.SiteUrl + "/foo.txt";

                    Thread.Sleep(500);

                    KuduAssert.VerifyUrl(url, "This is a test file");

                    // Act
                    appManager.GitDeploy(repo.PhysicalPath);

                    // Assert
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl);
                    KuduAssert.VerifyUrl(url, statusCode: HttpStatusCode.NotFound);
                });
            }
        }
Example #14
0
        public void DeletesToRepositoryArePropagatedForWaps()
        {
            string repositoryName = "Mvc3Application";
            string appName        = KuduUtils.GetRandomWebsiteName("DeletesToRepoForWaps");

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    string deletePath  = Path.Combine(repo.PhysicalPath, @"Mvc3Application\Controllers\AccountController.cs");
                    string projectPath = Path.Combine(repo.PhysicalPath, @"Mvc3Application\Mvc3Application.csproj");

                    // Act
                    appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl + "Account/LogOn", statusCode: HttpStatusCode.OK);

                    File.Delete(deletePath);
                    File.WriteAllText(projectPath, File.ReadAllText(projectPath).Replace(@"<Compile Include=""Controllers\AccountController.cs"" />", ""));
                    Git.Commit(repo.PhysicalPath, "Deleted the filez");
                    appManager.GitDeploy(repo.PhysicalPath);
                    results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(2, results.Count);
                    Assert.Equal(DeployStatus.Success, results[1].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl + "Account/LogOn", statusCode: HttpStatusCode.NotFound);
                });
            }
        }
Example #15
0
        public async Task TestDropboxBasicForBasicScenarioWithOAuthV2()
        {
            if (String.IsNullOrEmpty(OAuth20Token))
            {
                // only run in private kudu
                return;
            }

            object payload = new
            {
                scmType       = "DropboxV2",
                dropbox_token = OAuth20Token,
                dropbox_path  = "/Basictest"
            };

            await ApplicationManager.RunAsync("TestDropboxBasicForBasicScenarioWithOAuthV2", async appManager =>
            {
                HttpClient client = HttpClientHelper.CreateClient(appManager.ServiceUrl, appManager.DeploymentManager.Credentials);
                var result        = await client.PostAsJsonAsync("deploy?scmType=Dropbox", payload);
                result.EnsureSuccessful();

                await Task.WhenAll(
                    KuduAssert.VerifyUrlAsync(appManager.SiteUrl + "/default.html", "Hello Default!"),
                    KuduAssert.VerifyUrlAsync(appManager.SiteUrl + "/temp/temp.html", "Hello Temp!"),
                    KuduAssert.VerifyUrlAsync(appManager.SiteUrl + "/New Folder/New File.html", "Hello New File!")
                    );
            });
        }
Example #16
0
        public void TestNodeCustomStartScriptFromPackageJson()
        {
            // Arrange
            string appName = "TestCustomStartScriptFromPackageJson";

            using (var repo = Git.Clone("NodeWithCustomStartScript"))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    GitDeploymentResult deployResult = appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert deployment success
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    // Verify log output
                    Assert.Contains("Using start-up script app/app.js", deployResult.GitTrace);
                    Assert.Contains("Updating iisnode.yml", deployResult.GitTrace);
                    // Verify app works.
                    KuduAssert.VerifyUrl(appManager.SiteUrl, "Hello Main App!");
                    // Verify that node-inspector works
                    KuduAssert.VerifyUrl(appManager.SiteUrl + "/app/app.js/debug", "node-inspector");
                });
            }
        }
Example #17
0
        public void DeploymentApisReturn404IfDeploymentIdDoesntExist()
        {
            string appName = KuduUtils.GetRandomWebsiteName("Rtn404IfDeployIdNotExist");

            ApplicationManager.Run(appName, appManager =>
            {
                string id = "foo";
                var ex    = KuduAssert.ThrowsUnwrapped <HttpRequestException>(() => appManager.DeploymentManager.DeleteAsync(id).Wait());
                Assert.Equal("Response status code does not indicate success: 404 (Not Found).", ex.Message);

                ex = KuduAssert.ThrowsUnwrapped <HttpRequestException>(() => appManager.DeploymentManager.DeployAsync(id).Wait());
                Assert.Equal("Response status code does not indicate success: 404 (Not Found).", ex.Message);

                ex = KuduAssert.ThrowsUnwrapped <HttpRequestException>(() => appManager.DeploymentManager.DeployAsync(id, clean: true).Wait());
                Assert.Equal("Response status code does not indicate success: 404 (Not Found).", ex.Message);

                ex = KuduAssert.ThrowsUnwrapped <HttpRequestException>(() => appManager.DeploymentManager.GetLogEntriesAsync(id).Wait());
                Assert.Equal("Response status code does not indicate success: 404 (Not Found).", ex.Message);

                ex = KuduAssert.ThrowsUnwrapped <HttpRequestException>(() => appManager.DeploymentManager.GetResultAsync(id).Wait());
                Assert.Equal("Response status code does not indicate success: 404 (Not Found).", ex.Message);

                ex = KuduAssert.ThrowsUnwrapped <HttpRequestException>(() => appManager.DeploymentManager.GetLogEntryDetailsAsync(id, "fakeId").Wait());
                Assert.Equal("Response status code does not indicate success: 404 (Not Found).", ex.Message);
            });
        }
        public void SetGetDeleteValue()
        {
            // Arrange
            string repositoryName = "Mvc3Application";
            string appName        = "SetValue";

            using (var repo = Git.Clone(repositoryName))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    appManager.SettingsManager.SetValue("x", "1").Wait();

                    // Assert
                    string result = appManager.SettingsManager.GetValue("x").Result;

                    Assert.Equal("1", result);

                    appManager.SettingsManager.Delete("x").Wait();

                    // Act
                    var ex = KuduAssert.ThrowsUnwrapped <HttpUnsuccessfulRequestException>(() => appManager.SettingsManager.GetValue("x").Wait());

                    // Assert
                    Assert.Equal(HttpStatusCode.NotFound, ex.ResponseMessage.StatusCode);
                });
            }
        }
Example #19
0
        public void WarningsAsErrors()
        {
            // Arrange
            string repositoryName = "WarningsAsErrors";
            string appName        = KuduUtils.GetRandomWebsiteName("WarningsAsErrors");
            string cloneUrl       = "https://github.com/KuduApps/WarningsAsErrors.git";

            using (var repo = Git.Clone(repositoryName, cloneUrl))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    GitDeploymentResult deployResult = appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Failed, results[0].Status);
                    Assert.Null(results[0].LastSuccessEndTime);
                    KuduAssert.VerifyLogOutput(appManager, results[0].Id, "Warning as Error: The variable 'x' is declared but never used");
                    Assert.True(deployResult.GitTrace.Contains("Warning as Error: The variable 'x' is declared but never used"));
                    Assert.True(deployResult.GitTrace.Contains("Error - Changes committed to remote repository but your website not updated."));
                });
            }
        }
Example #20
0
        public void PostDeploymentActionWhichFailsShouldFailDeployment()
        {
            string testName          = "PostDeploymentActionsShouldBeCalledOnSuccessfulPublish";
            string testLine1         = "test script 1 is running";
            string testLine2         = "test script 2 is running too";
            string failScriptCommand = "\n exit /b 1";

            using (new LatencyLogger(testName))
            {
                ApplicationManager.Run(testName, appManager =>
                {
                    using (var appRepository = Git.Clone("HelloKudu"))
                    {
                        TestTracer.Trace("Add action scripts, first script should fail, second script shouldn't run");
                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_1.cmd",
                            @"@echo off
                              echo " + testLine1 + failScriptCommand);

                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_2.bat",
                            @"@echo off
                              echo " + testLine2);

                        TestTracer.Trace("Deploy test app");
                        appManager.GitDeploy(appRepository.PhysicalPath);

                        TestTracer.Trace("Verify results");
                        var deploymentResults = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                        Assert.Equal(1, deploymentResults.Count);
                        Assert.Equal(DeployStatus.Failed, deploymentResults[0].Status);

                        KuduAssert.VerifyLogOutput(appManager, deploymentResults[0].Id, testLine1);
                        KuduAssert.VerifyLogOutputWithUnexpected(appManager, deploymentResults[0].Id, testLine2);

                        TestTracer.Trace("Update action scripts, first script should succeed, second script should fail");
                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_1.cmd",
                            @"@echo off
                              echo " + testLine1);

                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_2.bat",
                            @"@echo off
                              echo " + testLine2 + failScriptCommand);

                        TestTracer.Trace("Deploy test app");
                        appManager.DeploymentManager.DeployAsync(null).Wait();

                        TestTracer.Trace("Verify results");
                        deploymentResults = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                        Assert.Equal(1, deploymentResults.Count);
                        Assert.Equal(DeployStatus.Failed, deploymentResults[0].Status);

                        KuduAssert.VerifyLogOutput(appManager, deploymentResults[0].Id, testLine1, testLine2);
                    }
                });
            }
        }
Example #21
0
        public async Task TestDropboxBasicForBasicScenario(Scenario scenario)
        {
            OAuthInfo oauth = GetOAuthInfo();

            if (oauth == null)
            {
                // only run in private kudu
                return;
            }

            AccountInfo account = GetAccountInfo(oauth);

            Assert.Equal(oauth.Account, account.email);
            var deploy = GetDeployInfo("/BasicTest", oauth, account);

            string appName = "DropboxTest";
            await ApplicationManager.RunAsync(appName, async appManager =>
            {
                if (scenario == Scenario.NoRepository)
                {
                    await appManager.SettingsManager.SetValue(SettingsKeys.NoRepository, "1");
                }
                else if (scenario == Scenario.InPlace)
                {
                    await appManager.SettingsManager.SetValue(SettingsKeys.RepositoryPath, "wwwroot");
                }

                HttpClient client = HttpClientHelper.CreateClient(appManager.ServiceUrl, appManager.DeploymentManager.Credentials);
                var result        = await client.PostAsJsonAsync("deploy?scmType=Dropbox", deploy);
                result.EnsureSuccessful();

                await Task.WhenAll(
                    KuduAssert.VerifyUrlAsync(appManager.SiteUrl + "/default.html", "Hello Default!"),
                    KuduAssert.VerifyUrlAsync(appManager.SiteUrl + "/temp/temp.html", "Hello Temp!"),
                    KuduAssert.VerifyUrlAsync(appManager.SiteUrl + "/New Folder/New File.html", "Hello New File!")
                    );

                var repositoryGit = appManager.VfsManager.Exists(@"site\repository\.git");
                var wwwrootGit    = appManager.VfsManager.Exists(@"site\wwwroot\.git");

                if (scenario == Scenario.NoRepository)
                {
                    Assert.False(repositoryGit, @"site\repository\.git should not exist for " + scenario);
                    Assert.False(wwwrootGit, @"site\wwwroot\.git should not exist for " + scenario);
                }
                else if (scenario == Scenario.InPlace)
                {
                    Assert.False(repositoryGit, @"site\repository\.git should not exist for " + scenario);
                    Assert.True(wwwrootGit, @"site\wwwroot\.git should exist for " + scenario);
                }
                else if (scenario == Scenario.Default)
                {
                    Assert.True(repositoryGit, @"site\repository\.git should exist for " + scenario);
                    Assert.False(wwwrootGit, @"site\wwwroot\.git should not exist for " + scenario);
                }
            });
        }
Example #22
0
        public void DeployLargeRepoFromDropbox(string repoPath, string appName, string verificationText, string resourcePath)
        {
            if (!shouldRunLargeRepoTests)
            {
                return;
            }
            using (new LatencyLogger("PushAndDeployApps - " + appName))
            {
                var db = new DropboxTests();
                {
                    DropboxTests.OAuthInfo oauth = db.GetOAuthInfo(appName);

                    if (oauth == null)
                    {
                        // only run in private kudu
                        return;
                    }
                    JObject deploy;
                    DropboxTests.AccountInfo account = db.GetAccountInfo(oauth);
                    using (new LatencyLogger("DropboxGetDeployInfo - " + appName))
                    {
                        deploy = db.GetDeployInfo(repoPath, oauth, account);
                    }

                    ApplicationManager.Run(appName, appManager =>
                    {
                        const int timeoutInMinutes = 100;
                        DateTime stopTime          = DateTime.Now.AddMinutes(timeoutInMinutes);

                        var client = HttpClientHelper.CreateClient(appManager.ServiceUrl, appManager.DeploymentManager.Credentials);

                        using (new LatencyLogger("DropboxDeploy - " + appName))
                        {
                            client.PostAsJsonAsync("deploy?scmType=Dropbox", deploy);
                            List <DeployResult> results;
                            do
                            {
                                Thread.Sleep(5000);
                                if (DateTime.Now > stopTime)
                                {
                                    throw new TimeoutException("Terminating test. Current test took too long.");
                                }
                                results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                                TestTracer.Trace(results[0].Progress);
                            } while ((results[0]).Status != DeployStatus.Success && (results[0]).Status != DeployStatus.Failed);
                        }

                        KuduAssert.VerifyUrl(appManager.SiteUrl + resourcePath, verificationText);
                        using (new LatencyLogger("DropboxScmDelete - " + appName))
                        {
                            appManager.RepositoryManager.Delete(deleteWebRoot: false, ignoreErrors: false).Wait();
                        }
                    });
                }
            }
        }
Example #23
0
        private static void CreateLogDirectory(string siteUrl, string directory)
        {
            if (!directory.EndsWith("\\"))
            {
                directory += "\\";
            }
            string url = String.Format("{0}?path={1}", siteUrl, directory);

            KuduAssert.VerifyUrl(url);
        }
Example #24
0
 public virtual void VerifyUrl(ApplicationManager appManager, Setting setting)
 {
     if (setting.TargetPath == ".")
     {
         KuduAssert.VerifyUrl(appManager.SiteUrl + DefaultDocument, Content);
     }
     else
     {
         VerifyUrl(appManager, setting.TargetPath);
     }
 }
Example #25
0
        public void TestLogStreamNotFound()
        {
            string appName = "TestLogStreamNotFound";

            ApplicationManager.Run(appName, appManager =>
            {
                RemoteLogStreamManager manager = new RemoteLogStreamManager(appManager.ServiceUrl + "/logstream/notfound");
                var ex = KuduAssert.ThrowsUnwrapped <WebException>(() => manager.GetStream().Wait());
                Assert.Equal(((HttpWebResponse)ex.Response).StatusCode, HttpStatusCode.NotFound);
            });
        }
Example #26
0
        public void PostDeploymentActionsShouldBeCalledOnSuccessfulDeployment()
        {
            string testName  = "PostDeploymentActionsShouldBeCalledOnSuccessfulDeployment";
            string testLine1 = "test script 1 is running";
            string testLine2 = "test script 2 is running too";

            const string testCommitIdPrefix   = @"SCM_COMMIT_ID = ";
            const string testCommitIdVariable = @"%SCM_COMMIT_ID%";

            using (new LatencyLogger(testName))
            {
                ApplicationManager.Run(testName, appManager =>
                {
                    using (var appRepository = Git.Clone("HelloKudu"))
                    {
                        TestTracer.Trace("Add action scripts");
                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_1.cmd",
                            @"@echo off
                              echo " + testLine1);

                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_2.bat",
                            @"@echo off
                              echo " + testLine2);

                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_3.sh",
                            @"@echo off
                              echo fail if we try to run this
                              exit /b 1");

                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_4.cmd",
                            @"@echo off
                              echo " + testCommitIdPrefix + testCommitIdVariable);

                        TestTracer.Trace("Deploy test app");
                        appManager.GitDeploy(appRepository.PhysicalPath);

                        TestTracer.Trace("Verify results");
                        var deploymentResults = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                        Assert.Equal(1, deploymentResults.Count);
                        Assert.Equal(DeployStatus.Success, deploymentResults[0].Status);

                        KuduAssert.VerifyLogOutput(appManager, deploymentResults[0].Id, testLine1, testLine2);
                        KuduAssert.VerifyLogOutput(appManager, deploymentResults[0].Id, testCommitIdPrefix + deploymentResults[0].Id);
                    }
                });
            }
        }
Example #27
0
        //Common code
        internal static void PushAndDeployApps(string repoCloneUrl, string defaultBranchName, string verificationText,
                                               HttpStatusCode expectedResponseCode, string verificationLogText,
                                               DeployStatus expectedStatus = DeployStatus.Success, string resourcePath = "",
                                               string httpMethod           = "GET", string jsonPayload = "", bool deleteSCM = false)
        {
            using (new LatencyLogger("PushAndDeployApps - " + repoCloneUrl))
            {
                Uri uri;
                if (!Uri.TryCreate(repoCloneUrl, UriKind.Absolute, out uri))
                {
                    uri = null;
                }

                string randomTestName = uri != null?Path.GetFileNameWithoutExtension(repoCloneUrl) : repoCloneUrl;

                ApplicationManager.Run(randomTestName, appManager =>
                {
                    // Act
                    using (TestRepository testRepository = Git.Clone(randomTestName, uri != null ? repoCloneUrl : null))
                    {
                        using (new LatencyLogger("GitDeploy"))
                        {
                            appManager.GitDeploy(testRepository.PhysicalPath, defaultBranchName);
                        }
                    }
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(expectedStatus, results[0].Status);
                    var url = new Uri(new Uri(appManager.SiteUrl), resourcePath);
                    if (!String.IsNullOrEmpty(verificationText))
                    {
                        KuduAssert.VerifyUrl(url.ToString(), verificationText, expectedResponseCode, httpMethod, jsonPayload);
                    }
                    if (!String.IsNullOrEmpty(verificationLogText))
                    {
                        KuduAssert.VerifyLogOutput(appManager, results[0].Id, verificationLogText.Trim());
                    }
                    if (deleteSCM)
                    {
                        using (new LatencyLogger("SCMAndWebDelete"))
                        {
                            appManager.RepositoryManager.Delete(deleteWebRoot: false, ignoreErrors: false).Wait();
                        }
                    }
                });
            }
        }
Example #28
0
        public void UpdatedTargetPathShouldChangeDeploymentDestination()
        {
            ApplicationManager.Run("UpdatedTargetPathShouldChangeDeploymentDestination", appManager =>
            {
                using (TestRepository testRepository = Git.Clone("TargetPathTest"))
                {
                    appManager.GitDeploy(testRepository.PhysicalPath, "master");
                }
                var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                Assert.Equal(1, results.Count);
                Assert.Equal(DeployStatus.Success, results[0].Status);
                KuduAssert.VerifyUrl(appManager.SiteUrl + "myTarget/index.html", "Target Path Test");
            });
        }
Example #29
0
        public async Task ProcessApiTests()
        {
            string appName = "ProcessApiTests";

            await ApplicationManager.RunAsync(appName, async appManager =>
            {
                // Test current process
                var process        = await appManager.ProcessManager.GetCurrentProcessAsync();
                int currentId      = process.Id;
                DateTime startTime = process.StartTime;
                Assert.NotNull(process);
                Assert.Contains("w3wp", process.Name);
                Assert.Contains("/diagnostics/processes/" + currentId, process.Href.AbsoluteUri);

                // Test get process by id
                process = await appManager.ProcessManager.GetProcessAsync(currentId);
                Assert.NotNull(process);
                Assert.Contains("w3wp", process.Name);
                Assert.Contains("/diagnostics/processes/" + currentId, process.Href.AbsoluteUri);

                // Test get not running process id
                var notfound = await KuduAssert.ThrowsUnwrappedAsync <HttpUnsuccessfulRequestException>(() => appManager.ProcessManager.GetProcessAsync(99999));
                Assert.Equal(HttpStatusCode.NotFound, notfound.ResponseMessage.StatusCode);
                Assert.Contains("is not running", notfound.ResponseMessage.ExceptionMessage);

                // Test process list
                var processes = await appManager.ProcessManager.GetProcessesAsync();
                Assert.True(processes.Count() >= 1);
                Assert.True(processes.Any(p => p.Id == currentId));

                // Test minidump
                var stream = new MemoryStream();
                using (var minidump = await appManager.ProcessManager.MiniDump())
                {
                    Assert.NotNull(minidump);
                    await minidump.CopyToAsync(stream);
                }
                Assert.True(stream.Length > 0);

                // Test kill process
                await KuduAssert.ThrowsUnwrappedAsync <HttpRequestException>(() => appManager.ProcessManager.KillProcessAsync(currentId));
                HttpUtils.WaitForSite(appManager.SiteUrl, delayBeforeRetry: 10000);
                process = await appManager.ProcessManager.GetCurrentProcessAsync();
                Assert.NotEqual(startTime, process.StartTime);
            });
        }
Example #30
0
        public void GoingBackInTimeShouldOverwriteModifiedFilesInRepo()
        {
            // Arrange
            string repositoryName   = "Mvc3Application";
            string appName          = KuduUtils.GetRandomWebsiteName("GoBackOverwriteModified");
            string verificationText = "Welcome to ASP.NET MVC!";

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                string id = repo.CurrentId;

                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    appManager.GitDeploy(repositoryName);

                    KuduAssert.VerifyUrl(appManager.SiteUrl, verificationText);

                    repo.AppendFile(@"Mvc3Application\Views\Home\Index.cshtml", "Say Whattttt!");

                    // Make a small changes and commit them to the local repo
                    Git.Commit(repositoryName, "This is a small changes");

                    // Push those changes
                    appManager.GitDeploy(repositoryName);

                    // Make a server site change and verify it shows up
                    appManager.ProjectSystem.WriteAllText("Views/Home/Index.cshtml", "Hello world!");

                    Thread.Sleep(500);

                    KuduAssert.VerifyUrl(appManager.SiteUrl, "Hello world!");

                    // Now go back in time
                    appManager.DeploymentManager.DeployAsync(id).Wait();

                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(2, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, verificationText);
                });
            }
        }