Skip to content
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

Support OIDC for the SSO #5008

Merged
merged 17 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/app/server/httpapi/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,13 @@ func parseProjectAndState(r *http.Request) (string, string, error) {
if len(s) != 2 {
projectID := r.FormValue(projectFormKey)
if projectID == "" {
return "", "", fmt.Errorf("missing project id")
return s[0], "", fmt.Errorf("missing project id")
}
return state, projectID, nil
} else {
if s[1] == "" {
return s[0], "", fmt.Errorf("missing project id")
}
return s[0], s[1], nil
}
}
80 changes: 80 additions & 0 deletions pkg/app/server/httpapi/callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,83 @@
// limitations under the License.

package httpapi

import (
"net/http"
"net/http/httptest"
"net/url"
"testing"

"github.com/stretchr/testify/assert"
)

func TestParseProjectAndState(t *testing.T) {
tests := []struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll add t.Parallel() in later PRs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solved by #5173

name string
formValues url.Values
expectedState string
expectedProj string
expectErr bool
}{
{
name: "missing state",
formValues: url.Values{},
expectedState: "",
expectedProj: "",
expectErr: true,
},
{
name: "state without project id",
formValues: url.Values{
stateFormKey: {"state-token"},
},
expectedState: "state-token",
expectedProj: "",
expectErr: true,
},
{
name: "state with project id",
formValues: url.Values{
stateFormKey: {"state-token:project-id"},
},
expectedState: "state-token",
expectedProj: "project-id",
expectErr: false,
},
{
name: "state without colon and project id in form",
formValues: url.Values{
stateFormKey: {"state-token"},
projectFormKey: {"project-id"},
},
expectedState: "state-token",
expectedProj: "project-id",
expectErr: false,
},
{
name: "state with colon but missing project id in form",
formValues: url.Values{
stateFormKey: {"state-token:"},
},
expectedState: "state-token",
expectedProj: "",
expectErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
req.Form = tt.formValues

state, project, err := parseProjectAndState(req)
if tt.expectErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, tt.expectedState, state)
assert.Equal(t, tt.expectedProj, project)
})
}
}