[MM-20706] Drop 26 character requirement from post action IDs (#13225)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1f3f8fbf57
Коммит
2d9e85e82a
@@ -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,49 +51,96 @@ func TestPostActionCookies(t *testing.T) {
|
|||||||
|
|
||||||
handler := &testHandler{t}
|
handler := &testHandler{t}
|
||||||
server := httptest.NewServer(handler)
|
server := httptest.NewServer(handler)
|
||||||
action := model.PostAction{
|
|
||||||
Id: model.NewId(),
|
|
||||||
Name: "Test-action",
|
|
||||||
Type: model.POST_ACTION_TYPE_BUTTON,
|
|
||||||
Integration: &model.PostActionIntegration{
|
|
||||||
URL: server.URL,
|
|
||||||
Context: map[string]interface{}{
|
|
||||||
"test-key": "test-value",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
post := &model.Post{
|
for name, test := range map[string]struct {
|
||||||
Id: model.NewId(),
|
Action model.PostAction
|
||||||
Type: model.POST_EPHEMERAL,
|
ExpectedSucess bool
|
||||||
UserId: th.BasicUser.Id,
|
ExpectedStatusCode int
|
||||||
ChannelId: th.BasicChannel.Id,
|
}{
|
||||||
CreateAt: model.GetMillis(),
|
"32 character ID": {
|
||||||
UpdateAt: model.GetMillis(),
|
Action: model.PostAction{
|
||||||
Props: map[string]interface{}{
|
Id: model.NewId(),
|
||||||
"attachments": []*model.SlackAttachment{
|
Name: "Test-action",
|
||||||
{
|
Type: model.POST_ACTION_TYPE_BUTTON,
|
||||||
Title: "some-title",
|
Integration: &model.PostActionIntegration{
|
||||||
TitleLink: "https://some-url.com",
|
URL: server.URL,
|
||||||
Text: "some-text",
|
Context: map[string]interface{}{
|
||||||
ImageURL: "https://some-other-url.com",
|
"test-key": "test-value",
|
||||||
Actions: []*model.PostAction{&action},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
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{
|
||||||
|
Id: model.NewId(),
|
||||||
|
Type: model.POST_EPHEMERAL,
|
||||||
|
UserId: th.BasicUser.Id,
|
||||||
|
ChannelId: th.BasicChannel.Id,
|
||||||
|
CreateAt: model.GetMillis(),
|
||||||
|
UpdateAt: model.GetMillis(),
|
||||||
|
Props: map[string]interface{}{
|
||||||
|
"attachments": []*model.SlackAttachment{
|
||||||
|
{
|
||||||
|
Title: "some-title",
|
||||||
|
TitleLink: "https://some-url.com",
|
||||||
|
Text: "some-text",
|
||||||
|
ImageURL: "https://some-other-url.com",
|
||||||
|
Actions: []*model.PostAction{&test.Action},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, 32, len(th.App.PostActionCookieSecret()))
|
||||||
|
post = model.AddPostActionCookies(post, th.App.PostActionCookieSecret())
|
||||||
|
|
||||||
|
ok, resp := Client.DoPostActionWithCookie(post.Id, test.Action.Id, "", test.Action.Cookie)
|
||||||
|
require.NotNil(t, resp)
|
||||||
|
if test.ExpectedSucess {
|
||||||
|
assert.True(t, ok)
|
||||||
|
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.ServerVersion)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
post.GenerateActionIds()
|
|
||||||
assert.Equal(t, 32, len(th.App.PostActionCookieSecret()))
|
|
||||||
post = model.AddPostActionCookies(post, th.App.PostActionCookieSecret())
|
|
||||||
|
|
||||||
ok, resp := Client.DoPostActionWithCookie(post.Id, action.Id, "", action.Cookie)
|
|
||||||
assert.True(t, ok)
|
|
||||||
assert.NotNil(t, resp)
|
|
||||||
assert.Equal(t, 200, resp.StatusCode)
|
|
||||||
assert.Nil(t, resp.Error)
|
|
||||||
assert.NotNil(t, resp.RequestId)
|
|
||||||
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
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user