Skip to content

Commit

Permalink
Fix projectkudu#2493 NullRefException when deploying from BitBucket
Browse files Browse the repository at this point in the history
  • Loading branch information
suwatch committed Jun 24, 2017
1 parent 0cc7b62 commit be49421
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions Kudu.Services.Test/BitbucketDeployment/BitbucketHandlerV2Facts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,35 @@ public async Task BitbucketHandlerAllowsPayloadsWithNullBranch()
Assert.Equal("Another check in\n", deploymentInfo.TargetChangeset.Message);
}

[Fact]
public async Task BitbucketHandlerAllowsPayloadsWithNullNew()
{
// Arrange
string payloadContent = null;
using (var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Kudu.Services.Test.BitbucketDeployment.BitbucketV2Payload.json")))
{
payloadContent = await reader.ReadToEndAsync();
}

var payload = JObject.Parse(payloadContent);
foreach (var change in payload.Value<JObject>("push").Value<JArray>("changes"))
{
// simulate branch deleted push event
change["new"] = null;
}

var httpRequest = new Mock<HttpRequestBase>();
httpRequest.SetupGet(r => r.UserAgent).Returns("Bitbucket-Webhooks/2.0");
var bitbucketHandler = new BitbucketHandlerV2();

// Act
DeploymentInfo deploymentInfo;
DeployAction result = bitbucketHandler.TryParseDeploymentInfo(httpRequest.Object, payload: payload, targetBranch: "not-default", deploymentInfo: out deploymentInfo);

// Assert
Assert.Equal(DeployAction.NoOp, result);
}

//// TODO once bug is fixed https://bitbucket.org/site/master/issues/11665/missing-scm-and-is_private-info-from
////[Fact]
////public void BitbucketHandlerParsesBitbucketPayloadsForMercurialRepositories()
Expand Down
2 changes: 1 addition & 1 deletion Kudu.Services/ServiceHookHandlers/BitbucketHandlerV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected static DeploymentInfo GetDeploymentInfo(JObject payload, string target
if (changes != null && changes.Count > 0)
{
JObject latestCommit = (from change in changes
where string.Equals(targetBranch, change.Value<JObject>("new").Value<string>("name") ?? targetBranch, StringComparison.OrdinalIgnoreCase)
where change.Value<JObject>("new") != null && string.Equals(targetBranch, change.Value<JObject>("new").Value<string>("name") ?? targetBranch, StringComparison.OrdinalIgnoreCase)
orderby BitbucketHandler.TryParseCommitStamp(change.Value<JObject>("new").Value<JObject>("target").Value<string>("date")) descending
select change.Value<JObject>("new")).FirstOrDefault();

Expand Down

0 comments on commit be49421

Please sign in to comment.