Skip to content

Commit

Permalink
Adding bitbucket data center support and using data center in tests (#…
Browse files Browse the repository at this point in the history
…879)

* adding bitbucket data center support and using data center in tests

* fix condition for validation

* fix conditional checks

* Updated Change Log
  • Loading branch information
zainq11 committed Apr 3, 2024
1 parent 41a1b6f commit 146ad87
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Unreleased

## Enhancements
* Adds Bitbucket Data Center as a new `ServiceProviderType` and ensures similar validation as Bitbucket Server by @zainq11 [#879](https://github.com/hashicorp/go-tfe/pull/879)

# v1.49.0

## Enhancements
Expand Down
9 changes: 6 additions & 3 deletions oauth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type ServiceProviderType string
const (
ServiceProviderAzureDevOpsServer ServiceProviderType = "ado_server"
ServiceProviderAzureDevOpsServices ServiceProviderType = "ado_services"
ServiceProviderBitbucketDataCenter ServiceProviderType = "bitbucket_data_center"
ServiceProviderBitbucket ServiceProviderType = "bitbucket_hosted"
// Bitbucket Server v5.4.0 and above
ServiceProviderBitbucketServer ServiceProviderType = "bitbucket_server"
Expand Down Expand Up @@ -160,8 +161,8 @@ type OAuthClientCreateOptions struct {
// Optional: Secret key associated with this vcs provider - only available for ado_server
Secret *string `jsonapi:"attr,secret,omitempty"`

// Optional: RSAPublicKey the text of the SSH public key associated with your BitBucket
// Server Application Link.
// Optional: RSAPublicKey the text of the SSH public key associated with your
// BitBucket Data Center Application Link.
RSAPublicKey *string `jsonapi:"attr,rsa-public-key,omitempty"`

// Required: The VCS provider being connected with.
Expand Down Expand Up @@ -342,7 +343,9 @@ func (o OAuthClientCreateOptions) valid() error {
if o.ServiceProvider == nil {
return ErrRequiredServiceProvider
}
if !validString(o.OAuthToken) && *o.ServiceProvider != *ServiceProvider(ServiceProviderBitbucketServer) {
if !validString(o.OAuthToken) &&
*o.ServiceProvider != *ServiceProvider(ServiceProviderBitbucketServer) &&
*o.ServiceProvider != *ServiceProvider(ServiceProviderBitbucketDataCenter) {
return ErrRequiredOauthToken
}
if validString(o.PrivateKey) && *o.ServiceProvider != *ServiceProvider(ServiceProviderAzureDevOpsServer) {
Expand Down
34 changes: 17 additions & 17 deletions oauth_client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ func TestOAuthClientsCreate_rsaKeyPair(t *testing.T) {
t.Run("with key, rsa public/private key options", func(t *testing.T) {
key := randomString(t)
options := OAuthClientCreateOptions{
APIURL: String("https://bbs.com"),
HTTPURL: String("https://bbs.com"),
ServiceProvider: ServiceProvider(ServiceProviderBitbucketServer),
APIURL: String("https://bbdc.com"),
HTTPURL: String("https://bbdc.com"),
ServiceProvider: ServiceProvider(ServiceProviderBitbucketDataCenter),
Key: String(key),
Secret: String(privateKey),
RSAPublicKey: String(publicKey),
Expand All @@ -216,9 +216,9 @@ func TestOAuthClientsCreate_rsaKeyPair(t *testing.T) {
oc, err := client.OAuthClients.Create(ctx, orgTest.Name, options)
require.NoError(t, err)
assert.NotEmpty(t, oc.ID)
assert.Equal(t, "https://bbs.com", oc.APIURL)
assert.Equal(t, "https://bbs.com", oc.HTTPURL)
assert.Equal(t, ServiceProviderBitbucketServer, oc.ServiceProvider)
assert.Equal(t, "https://bbdc.com", oc.APIURL)
assert.Equal(t, "https://bbdc.com", oc.HTTPURL)
assert.Equal(t, ServiceProviderBitbucketDataCenter, oc.ServiceProvider)
assert.Equal(t, publicKey, oc.RSAPublicKey)
assert.Equal(t, key, oc.Key)
})
Expand Down Expand Up @@ -644,9 +644,9 @@ func TestOAuthClientsUpdate(t *testing.T) {
organizationScoped := false
organizationScopedTrue := true
options := OAuthClientCreateOptions{
APIURL: String("https://bbs.com"),
HTTPURL: String("https://bbs.com"),
ServiceProvider: ServiceProvider(ServiceProviderBitbucketServer),
APIURL: String("https://bbdc.com"),
HTTPURL: String("https://bbdc.com"),
ServiceProvider: ServiceProvider(ServiceProviderBitbucketDataCenter),
OrganizationScoped: &organizationScopedTrue,
}

Expand Down Expand Up @@ -686,9 +686,9 @@ func TestOAuthClientsUpdate_rsaKeyPair(t *testing.T) {
t.Run("updates a new key", func(t *testing.T) {
originalKey := randomString(t)
options := OAuthClientCreateOptions{
APIURL: String("https://bbs.com"),
HTTPURL: String("https://bbs.com"),
ServiceProvider: ServiceProvider(ServiceProviderBitbucketServer),
APIURL: String("https://bbdc.com"),
HTTPURL: String("https://bbdc.com"),
ServiceProvider: ServiceProvider(ServiceProviderBitbucketDataCenter),
Key: String(originalKey),
Secret: String(privateKey),
RSAPublicKey: String(publicKey),
Expand All @@ -705,17 +705,17 @@ func TestOAuthClientsUpdate_rsaKeyPair(t *testing.T) {
oc, err := client.OAuthClients.Update(ctx, origOC.ID, updateOpts)
require.NoError(t, err)
assert.NotEmpty(t, oc.ID)
assert.Equal(t, ServiceProviderBitbucketServer, oc.ServiceProvider)
assert.Equal(t, ServiceProviderBitbucketDataCenter, oc.ServiceProvider)
assert.Equal(t, oc.RSAPublicKey, origOC.RSAPublicKey)
assert.Equal(t, newKey, oc.Key)
})

t.Run("errors when missing key", func(t *testing.T) {
originalKey := randomString(t)
options := OAuthClientCreateOptions{
APIURL: String("https://bbs.com"),
HTTPURL: String("https://bbs.com"),
ServiceProvider: ServiceProvider(ServiceProviderBitbucketServer),
APIURL: String("https://bbdc.com"),
HTTPURL: String("https://bbdc.com"),
ServiceProvider: ServiceProvider(ServiceProviderBitbucketDataCenter),
Key: String(originalKey),
Secret: String(privateKey),
RSAPublicKey: String(publicKey),
Expand All @@ -729,6 +729,6 @@ func TestOAuthClientsUpdate_rsaKeyPair(t *testing.T) {
Key: String(""),
}
_, err = client.OAuthClients.Update(ctx, origOC.ID, updateOpts)
assert.Error(t, err, "The Consumer Key for BitBucket Server must be present. Please add a value for `key`.")
assert.Error(t, err, "The Consumer Key for Bitbucket Data Center must be present. Please add a value for `key`.")
})
}

0 comments on commit 146ad87

Please sign in to comment.