package oauth2provider_test import ( htmltemplate "html/template" "net/http" "net/http/httptest" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/coder/coder/v2/site" ) func TestOAuthConsentFormIncludesCSRFToken(t *testing.T) { t.Parallel() const csrfFieldValue = "csrf-field-value" req := httptest.NewRequest(http.MethodGet, "https://coder.com/oauth2/authorize", nil) rec := httptest.NewRecorder() site.RenderOAuthAllowPage(rec, req, site.RenderOAuthAllowData{ AppName: "Test OAuth App", CancelURI: htmltemplate.URL("https://coder.com/cancel"), DashboardURL: "https://coder.com/", CSRFToken: csrfFieldValue, Username: "test-user", }) require.Equal(t, http.StatusOK, rec.Result().StatusCode) body := rec.Body.String() assert.Contains(t, body, `name="csrf_token"`) assert.Contains(t, body, `value="`+csrfFieldValue+`"`) assert.Contains(t, body, `id="allow-form"`) assert.Contains(t, body, `id="cancel-link"`) }