From 4b777cf2f356481a8e5cfb0864bc3b59e2d3539d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ka=C4=9Fan=20=C3=9Cst=C3=BCngel?= Date: Thu, 26 May 2022 01:57:40 +0300 Subject: [PATCH] replaced hostname in webhook url regex to address field of DefaultConfig() --- policy_set_integration_test.go | 5 +++-- registry_module_integration_test.go | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/policy_set_integration_test.go b/policy_set_integration_test.go index e49ccf7a0..2cd02cd56 100644 --- a/policy_set_integration_test.go +++ b/policy_set_integration_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "os" + "regexp" "testing" "github.com/stretchr/testify/assert" @@ -172,7 +173,7 @@ func TestPolicySetsCreate(t *testing.T) { assert.Equal(t, ps.VCSRepo.OAuthTokenID, oc.ID) assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier)) assert.Equal(t, ps.VCSRepo.ServiceProvider, string(ServiceProviderGithub)) - assert.Regexp(t, "^https://app\\.terraform\\.io/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", ps.VCSRepo.WebhookURL) + assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL) }) t.Run("with vcs policy updated", func(t *testing.T) { @@ -209,7 +210,7 @@ func TestPolicySetsCreate(t *testing.T) { assert.Equal(t, ps.VCSRepo.OAuthTokenID, oc.ID) assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier)) assert.Equal(t, ps.VCSRepo.ServiceProvider, string(ServiceProviderGithub)) - assert.Regexp(t, "^https://app\\.terraform\\.io/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", ps.VCSRepo.WebhookURL) + assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL) }) t.Run("without a name provided", func(t *testing.T) { diff --git a/registry_module_integration_test.go b/registry_module_integration_test.go index a6bcefd2f..e6d7fdf8c 100644 --- a/registry_module_integration_test.go +++ b/registry_module_integration_test.go @@ -9,6 +9,7 @@ import ( "encoding/json" "fmt" "os" + "regexp" "strings" "testing" @@ -272,7 +273,7 @@ func TestRegistryModulesCreateWithVCSConnection(t *testing.T) { assert.Equal(t, rm.VCSRepo.OAuthTokenID, oauthTokenTest.ID) assert.Equal(t, rm.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier)) assert.Equal(t, rm.VCSRepo.ServiceProvider, string(ServiceProviderGithub)) - assert.Regexp(t, "^https://app\\.terraform\\.io/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", rm.VCSRepo.WebhookURL) + assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), rm.VCSRepo.WebhookURL) t.Run("permissions are properly decoded", func(t *testing.T) { assert.True(t, rm.Permissions.CanDelete)