Fix update webhook and use secret for webhook authentication (#42)

* Fix update repository webhooks and extend webhook tests

* Use secret to authenticate the webhook payload and extend the tests with the secret

Co-authored-by: Raul Barreto <raul.barreto@redbull.com>
This commit is contained in:
raulbarreto-delivion
2021-12-15 01:52:58 +01:00
committed by GitHub
parent bee3f62908
commit 1323abe664
3 changed files with 98 additions and 12 deletions

View File

@@ -42,8 +42,74 @@ func TestAccBitbucketResourceRepositoryWebhook_simple(t *testing.T) {
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "project", projectKey),
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "repository", "repo"),
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "webhook_url", "https://www.google.com/"),
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "secret", ""),
),
},
{
Config: config,
ExpectNonEmptyPlan: false,
},
},
})
}
func TestAccBitbucketResourceRepositoryWebhook_complete(t *testing.T) {
projectKey := fmt.Sprintf("TEST%v", rand.New(rand.NewSource(time.Now().UnixNano())).Int())
configString := `
resource "bitbucketserver_project" "test" {
key = "%v"
name = "test-project-%v"
}
resource "bitbucketserver_repository" "test" {
project = bitbucketserver_project.test.key
name = "repo"
}
resource "bitbucketserver_repository_webhook" "test" {
project = bitbucketserver_project.test.key
repository = bitbucketserver_repository.test.slug
name = "%v"
webhook_url = "%v"
secret = "abc"
events = ["repo:refs_changed"]
active = true
}
`
config := fmt.Sprintf(configString, projectKey, projectKey, "test", "https://www.oldurl.com/")
newConfig := fmt.Sprintf(configString, projectKey, projectKey, "test2", "https://www.newurl.com/")
// Create resource
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "project", projectKey),
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "repository", "repo"),
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "name", "test"),
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "webhook_url", "https://www.oldurl.com/"),
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "secret", "abc"),
),
},
{
Config: newConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "project", projectKey),
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "repository", "repo"),
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "name", "test2"),
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "webhook_url", "https://www.newurl.com/"),
resource.TestCheckResourceAttr("bitbucketserver_repository_webhook.test", "secret", "abc"),
),
},
{
Config: newConfig,
Destroy: true,
},
},
})
}