mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
* feat: add github device flow for authentication This will allow us to add a GitHub OAuth provider out-of-the-box to reduce setup requirements. * Improve askpass view * Add routes to improve clarity of git auth * Redesign the git auth page * Refactor to add a page view * Fix sideways layout * Remove legacy notify * Fix git auth redirects * Add E2E tests * Fix route documentation * Fix imports * Remove unused imports * Fix E2E web test * Fix friendly message appearance * Fix layout shifting for full-screen sign-in * Fix height going to 100% * Fix comments
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package httpmw_test
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/coderd/gitauth"
|
|
"github.com/coder/coder/coderd/httpmw"
|
|
)
|
|
|
|
//nolint:bodyclose
|
|
func TestGitAuthParam(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("Found", func(t *testing.T) {
|
|
t.Parallel()
|
|
routeCtx := chi.NewRouteContext()
|
|
routeCtx.URLParams.Add("gitauth", "my-id")
|
|
r := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, routeCtx))
|
|
res := httptest.NewRecorder()
|
|
|
|
httpmw.ExtractGitAuthParam([]*gitauth.Config{{
|
|
ID: "my-id",
|
|
}})(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
require.Equal(t, "my-id", httpmw.GitAuthParam(r).ID)
|
|
w.WriteHeader(http.StatusOK)
|
|
})).ServeHTTP(res, r)
|
|
|
|
require.Equal(t, http.StatusOK, res.Result().StatusCode)
|
|
})
|
|
|
|
t.Run("NotFound", func(t *testing.T) {
|
|
t.Parallel()
|
|
routeCtx := chi.NewRouteContext()
|
|
routeCtx.URLParams.Add("gitauth", "my-id")
|
|
r := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, routeCtx))
|
|
res := httptest.NewRecorder()
|
|
|
|
httpmw.ExtractGitAuthParam([]*gitauth.Config{})(nil).ServeHTTP(res, r)
|
|
|
|
require.Equal(t, http.StatusNotFound, res.Result().StatusCode)
|
|
})
|
|
}
|