MM-10573 Add error page if user doesn't authorize Mattermost for OAuth (#9402)
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
f2ddef9117
Коммит
8afc529753
@@ -452,6 +452,15 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
service := c.Params.Service
|
service := c.Params.Service
|
||||||
|
|
||||||
|
oauthError := r.URL.Query().Get("error")
|
||||||
|
if oauthError == "access_denied" {
|
||||||
|
utils.RenderWebError(c.App.Config(), w, r, http.StatusTemporaryRedirect, url.Values{
|
||||||
|
"type": []string{"oauth_access_denied"},
|
||||||
|
"service": []string{strings.Title(service)},
|
||||||
|
}, c.App.AsymmetricSigningKey())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
code := r.URL.Query().Get("code")
|
code := r.URL.Query().Get("code")
|
||||||
if len(code) == 0 {
|
if len(code) == 0 {
|
||||||
utils.RenderWebError(c.App.Config(), w, r, http.StatusTemporaryRedirect, url.Values{
|
utils.RenderWebError(c.App.Config(), w, r, http.StatusTemporaryRedirect, url.Values{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -18,6 +19,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/einterfaces"
|
"github.com/mattermost/mattermost-server/einterfaces"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
|
"github.com/mattermost/mattermost-server/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateOAuthApp(t *testing.T) {
|
func TestCreateOAuthApp(t *testing.T) {
|
||||||
@@ -1147,6 +1149,30 @@ func TestOAuthComplete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOAuthComplete_AccessDenied(t *testing.T) {
|
||||||
|
th := Setup().InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
c := &Context{
|
||||||
|
App: th.App,
|
||||||
|
Params: &web.Params{
|
||||||
|
Service: "TestService",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
responseWriter := httptest.NewRecorder()
|
||||||
|
request, _ := http.NewRequest(http.MethodGet, th.App.GetSiteURL()+"/signup/TestService/complete?error=access_denied", nil)
|
||||||
|
|
||||||
|
completeOAuth(c, responseWriter, request)
|
||||||
|
|
||||||
|
response := responseWriter.Result()
|
||||||
|
|
||||||
|
assert.Equal(t, http.StatusTemporaryRedirect, response.StatusCode)
|
||||||
|
|
||||||
|
location, _ := url.Parse(response.Header.Get("Location"))
|
||||||
|
assert.Equal(t, "oauth_access_denied", location.Query().Get("type"))
|
||||||
|
assert.Equal(t, "TestService", location.Query().Get("service"))
|
||||||
|
}
|
||||||
|
|
||||||
func HttpGet(url string, httpClient *http.Client, authToken string, followRedirect bool) (*http.Response, *model.AppError) {
|
func HttpGet(url string, httpClient *http.Client, authToken string, followRedirect bool) (*http.Response, *model.AppError) {
|
||||||
rq, _ := http.NewRequest("GET", url, nil)
|
rq, _ := http.NewRequest("GET", url, nil)
|
||||||
rq.Close = true
|
rq.Close = true
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user