This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 5.1] [gitlab] Support custom GitLab SSO sign-on URLs (#55076)
Co-authored-by: Petri-Johan Last <[email protected]> Closes #50879
- Loading branch information
1 parent
c8cada7
commit b02d1e4
Showing
8 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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
5 changes: 5 additions & 0 deletions
5
enterprise/cmd/frontend/internal/auth/gitlaboauth/BUILD.bazel
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
46 changes: 46 additions & 0 deletions
46
enterprise/cmd/frontend/internal/auth/gitlaboauth/login_test.go
This file contains 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,46 @@ | ||
package gitlaboauth | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"testing" | ||
|
||
oauth2Login "github.com/dghubble/gologin/oauth2" | ||
"github.com/dghubble/gologin/testutils" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
func TestSSOLoginHandler(t *testing.T) { | ||
expectedState := "state_val" | ||
ssoURL := "https://api.example.com/-/saml/sso?token=1234" | ||
expectedRedirectURL := "/authorize?client_id=client_id&redirect_uri=redirect_url&response_type=code&state=state_val" | ||
config := &oauth2.Config{ | ||
ClientID: "client_id", | ||
ClientSecret: "client_secret", | ||
RedirectURL: "redirect_url", | ||
Endpoint: oauth2.Endpoint{ | ||
AuthURL: "https://api.example.com/authorize", | ||
}, | ||
} | ||
failure := testutils.AssertFailureNotCalled(t) | ||
|
||
// SSOLoginHandler assert that: | ||
// - redirects to the SSO URL, with a redirect to the authURL | ||
// - redirect status code is 302 | ||
// - redirect url is the OAuth2 Config RedirectURL with the ClientID and ctx state | ||
loginHandler := SSOLoginHandler(config, failure, ssoURL) | ||
w := httptest.NewRecorder() | ||
req, _ := http.NewRequest("GET", "/", nil) | ||
ctx := oauth2Login.WithState(context.Background(), expectedState) | ||
loginHandler.ServeHTTP(w, req.WithContext(ctx)) | ||
assert.Equal(t, http.StatusFound, w.Code) | ||
locationURL, err := url.Parse(w.HeaderMap.Get("Location")) | ||
require.NoError(t, err) | ||
locationRedirectURL, err := url.QueryUnescape(locationURL.Query().Get("redirect")) | ||
require.NoError(t, err) | ||
assert.Equal(t, expectedRedirectURL, locationRedirectURL) | ||
} |
This file contains 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.
This file contains 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