-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(azure-devops): add check for test webhook URL #2809
Changes from all commits
8d2a66b
2aeaf43
f01519e
6f2166e
f31f776
219d75d
5bd15e9
f114bcc
01009e9
eb9a8ca
cb996e3
b62af93
bc8e980
9a8f68b
b30913b
61ae8a2
4288c77
a270313
054cbde
eda013f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,9 @@ const bitbucketCloudRequestIDHeader = "X-Request-UUID" | |
const bitbucketServerRequestIDHeader = "X-Request-ID" | ||
const bitbucketServerSignatureHeader = "X-Hub-Signature" | ||
|
||
// The URL used for Azure DevOps test webhooks | ||
const azuredevopsTestURL = "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come this url has to be hardcoded? Shouldn't this value be in the test instead? Who has access to use this url for testing purposes? Couldn't this be mocked? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR is to detect and ignore the test webhooks that come from Azure DevOps. The test requests for the 3 webhooks that Atlantis uses are in the PR description. (The tests aren't configurable, they just send the same requests every time) The URL is a common property that exists in all three requests so we're using it to say: "If the request says it's coming from this URL: Ignore the request" No access is needed to this URL, we're simply using it to identify these test requests. Does that sound okay? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think we'll ever have to configure these urls? Would you add some additional comments in the code to add this explaination in case people have this question in the future? |
||
|
||
// VCSEventsController handles all webhook requests which signify 'events' in the | ||
// VCS host, ex. GitHub. | ||
type VCSEventsController struct { | ||
|
@@ -639,6 +642,11 @@ func (e *VCSEventsController) HandleAzureDevopsPullRequestCommentedEvent(w http. | |
return | ||
} | ||
|
||
if isAzureDevOpsTestRepoURL(resource.PullRequest.GetRepository()) { | ||
e.respond(w, logging.Debug, http.StatusOK, "Ignoring Azure DevOps Test Event with Repo URL: %v %s", resource.PullRequest.Repository.URL, azuredevopsReqID) | ||
return | ||
} | ||
|
||
createdBy := resource.PullRequest.GetCreatedBy() | ||
user := models.User{Username: createdBy.GetUniqueName()} | ||
baseRepo, err := e.Parser.ParseAzureDevopsRepo(resource.PullRequest.GetRepository()) | ||
|
@@ -681,6 +689,16 @@ func (e *VCSEventsController) HandleAzureDevopsPullRequestEvent(w http.ResponseW | |
} | ||
} | ||
|
||
resource, ok := event.Resource.(*azuredevops.GitPullRequest) | ||
nitrocode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if !ok || event.PayloadType != azuredevops.PullRequestEvent { | ||
e.respond(w, logging.Error, http.StatusBadRequest, "Event.Resource is nil or received bad event type %v; %s", event.Resource, azuredevopsReqID) | ||
return | ||
} | ||
if isAzureDevOpsTestRepoURL(resource.GetRepository()) { | ||
e.respond(w, logging.Debug, http.StatusOK, "Ignoring Azure DevOps Test Event with Repo URL: %v %s", resource.Repository.URL, azuredevopsReqID) | ||
return | ||
} | ||
|
||
pull, pullEventType, baseRepo, headRepo, user, err := e.Parser.ParseAzureDevopsPullEvent(*event) | ||
if err != nil { | ||
e.respond(w, logging.Error, http.StatusBadRequest, "Error parsing pull data: %s %s", err, azuredevopsReqID) | ||
|
@@ -730,3 +748,10 @@ func (e *VCSEventsController) commentNotAllowlisted(baseRepo models.Repo, pullNu | |
e.Logger.Err("unable to comment on pull request: %s", err) | ||
} | ||
} | ||
|
||
func isAzureDevOpsTestRepoURL(repository *azuredevops.GitRepository) bool { | ||
if repository == nil { | ||
return false | ||
} | ||
return repository.GetURL() == azuredevopsTestURL | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this PR been tested in your atlantis deployment? Were you able to verify that this change worked as expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll build it and run through some tests - hold off until I've confirmed that's sorted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Once you confirm then we can merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SSKLCP friendly ping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SSKLCP friendly ping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SSKLCP friendly ping