-
Notifications
You must be signed in to change notification settings - Fork 894
feat: implement bitbucket-server external auth defaults #10520
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f7a5742
feat: implement bitbucket-server external auth defaults
Emyrk 29508a9
Merge remote-tracking branch 'origin/main' into stevenmasley/bitbucke…
Emyrk 5bfa357
make fmt
Emyrk 5d4d8fe
fix jfrog
Emyrk b3d75ec
parallel unit test
Emyrk 84509a1
Rename functions
Emyrk 57da5cc
change "bitbucket" to "bitbucket-cloud"
Emyrk 7d239d8
Make gen
Emyrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package externalauth | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/coder/v2/codersdk" | ||
) | ||
|
||
func Test_bitbucketServerConfigDefaults(t *testing.T) { | ||
t.Parallel() | ||
|
||
bbType := string(codersdk.EnhancedExternalAuthProviderBitBucketServer) | ||
tests := []struct { | ||
name string | ||
config *codersdk.ExternalAuthConfig | ||
expected codersdk.ExternalAuthConfig | ||
}{ | ||
{ | ||
// Very few fields are statically defined for Bitbucket Server. | ||
name: "EmpyBitbucketServer", | ||
config: &codersdk.ExternalAuthConfig{ | ||
Type: bbType, | ||
}, | ||
expected: codersdk.ExternalAuthConfig{ | ||
Type: bbType, | ||
ID: bbType, | ||
DisplayName: "Bitbucket Server", | ||
Scopes: []string{"PUBLIC_REPOS", "REPO_READ", "REPO_WRITE"}, | ||
DisplayIcon: "/icon/bitbucket.svg", | ||
}, | ||
}, | ||
{ | ||
// Only the AuthURL is required for defaults to work. | ||
name: "AuthURL", | ||
config: &codersdk.ExternalAuthConfig{ | ||
Type: bbType, | ||
AuthURL: "https://bitbucket.example.com/login/oauth/authorize", | ||
}, | ||
expected: codersdk.ExternalAuthConfig{ | ||
Type: bbType, | ||
ID: bbType, | ||
AuthURL: "https://bitbucket.example.com/login/oauth/authorize", | ||
TokenURL: "https://bitbucket.example.com/rest/oauth2/latest/token", | ||
ValidateURL: "https://bitbucket.example.com/rest/api/latest/inbox/pull-requests/count", | ||
Scopes: []string{"PUBLIC_REPOS", "REPO_READ", "REPO_WRITE"}, | ||
Regex: `^(https?://)?bitbucket\.example\.com(/.*)?$`, | ||
DisplayName: "Bitbucket Server", | ||
DisplayIcon: "/icon/bitbucket.svg", | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
applyDefaultsToConfig(tt.config) | ||
require.Equal(t, tt.expected, *tt.config) | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Shouldn't we be doing these for all of them? Seems like making it just for BitBucket server is weird.
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.
perhaps the self-hosted ones.
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.
We do.
Azure
coder/coderd/externalauth/externalauth.go
Line 607 in 84509a1
Bitbucket Cloud
coder/coderd/externalauth/externalauth.go
Line 616 in 84509a1
Gitlab
coder/coderd/externalauth/externalauth.go
Line 625 in 84509a1
Github
coder/coderd/externalauth/externalauth.go
Line 634 in 84509a1
Bitbucket Server is always hosted on a different domain for each customer. So it's a dynamic regex string based on the
AUTH_URL
. The other providers are all cloud based with static urls.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.
@spikecurtis yes, the self hosted ones need this dynamic approach. We need to handle them case by case. Maybe there will be generalizations, but for now I only implemented self hosted bitbucket server.
Gitlab for example can definitely have some broken defaults right now.
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.
@Emyrk automatically doing the Regex should be a global change in my mind; it's weird to do it for a single provider.
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.
The regex is automatic for all providers. As in, the default values are correct for every type now
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.
Talked to @kylecarbs offline a bit.
Yes this problem exists with Gitlab and Github Enterprise. We should probably have some solution for these.
I do not want to break backwards compatibility, and I do not have the test environments to confirm those (eg, are the urls consistent? bitbucket cloud and server are different).
So for this PR, I'd rather not try and solve github enterprise and gitlab self hosted.