[MM-20706] Drop 26 character requirement from post action IDs (#13225)

Этот коммит содержится в:
Ben Schumacher
2020-01-14 07:18:14 +01:00
коммит произвёл GitHub
родитель 1f3f8fbf57
Коммит 2d9e85e82a
3 изменённых файлов: 86 добавлений и 50 удалений

Просмотреть файл

@@ -18,7 +18,7 @@ func (api *API) InitAction() {
} }
func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) { func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequirePostId().RequireActionId() c.RequirePostId()
if c.Err != nil { if c.Err != nil {
return return
} }

Просмотреть файл

@@ -51,7 +51,14 @@ func TestPostActionCookies(t *testing.T) {
handler := &testHandler{t} handler := &testHandler{t}
server := httptest.NewServer(handler) server := httptest.NewServer(handler)
action := model.PostAction{
for name, test := range map[string]struct {
Action model.PostAction
ExpectedSucess bool
ExpectedStatusCode int
}{
"32 character ID": {
Action: model.PostAction{
Id: model.NewId(), Id: model.NewId(),
Name: "Test-action", Name: "Test-action",
Type: model.POST_ACTION_TYPE_BUTTON, Type: model.POST_ACTION_TYPE_BUTTON,
@@ -61,8 +68,42 @@ func TestPostActionCookies(t *testing.T) {
"test-key": "test-value", "test-key": "test-value",
}, },
}, },
} },
ExpectedSucess: true,
ExpectedStatusCode: http.StatusOK,
},
"6 character ID": {
Action: model.PostAction{
Id: "someID",
Name: "Test-action",
Type: model.POST_ACTION_TYPE_BUTTON,
Integration: &model.PostActionIntegration{
URL: server.URL,
Context: map[string]interface{}{
"test-key": "test-value",
},
},
},
ExpectedSucess: true,
ExpectedStatusCode: http.StatusOK,
},
"Empty ID": {
Action: model.PostAction{
Id: "",
Name: "Test-action",
Type: model.POST_ACTION_TYPE_BUTTON,
Integration: &model.PostActionIntegration{
URL: server.URL,
Context: map[string]interface{}{
"test-key": "test-value",
},
},
},
ExpectedSucess: false,
ExpectedStatusCode: http.StatusNotFound,
},
} {
t.Run(name, func(t *testing.T) {
post := &model.Post{ post := &model.Post{
Id: model.NewId(), Id: model.NewId(),
Type: model.POST_EPHEMERAL, Type: model.POST_EPHEMERAL,
@@ -77,23 +118,29 @@ func TestPostActionCookies(t *testing.T) {
TitleLink: "https://some-url.com", TitleLink: "https://some-url.com",
Text: "some-text", Text: "some-text",
ImageURL: "https://some-other-url.com", ImageURL: "https://some-other-url.com",
Actions: []*model.PostAction{&action}, Actions: []*model.PostAction{&test.Action},
}, },
}, },
}, },
} }
post.GenerateActionIds()
assert.Equal(t, 32, len(th.App.PostActionCookieSecret())) assert.Equal(t, 32, len(th.App.PostActionCookieSecret()))
post = model.AddPostActionCookies(post, th.App.PostActionCookieSecret()) post = model.AddPostActionCookies(post, th.App.PostActionCookieSecret())
ok, resp := Client.DoPostActionWithCookie(post.Id, action.Id, "", action.Cookie) ok, resp := Client.DoPostActionWithCookie(post.Id, test.Action.Id, "", test.Action.Cookie)
require.NotNil(t, resp)
if test.ExpectedSucess {
assert.True(t, ok) assert.True(t, ok)
assert.NotNil(t, resp)
assert.Equal(t, 200, resp.StatusCode)
assert.Nil(t, resp.Error) assert.Nil(t, resp.Error)
} else {
assert.False(t, ok)
assert.NotNil(t, resp.Error)
}
assert.Equal(t, test.ExpectedStatusCode, resp.StatusCode)
assert.NotNil(t, resp.RequestId) assert.NotNil(t, resp.RequestId)
assert.NotNil(t, resp.ServerVersion) assert.NotNil(t, resp.ServerVersion)
})
}
} }
func TestOpenDialog(t *testing.T) { func TestOpenDialog(t *testing.T) {

Просмотреть файл

@@ -496,17 +496,6 @@ func (c *Context) RequireJobType() *Context {
return c return c
} }
func (c *Context) RequireActionId() *Context {
if c.Err != nil {
return c
}
if len(c.Params.ActionId) != 26 {
c.SetInvalidUrlParam("action_id")
}
return c
}
func (c *Context) RequireRoleId() *Context { func (c *Context) RequireRoleId() *Context {
if c.Err != nil { if c.Err != nil {
return c return c