[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) {
c.RequirePostId().RequireActionId()
c.RequirePostId()
if c.Err != nil {
return
}

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

@@ -51,49 +51,96 @@ func TestPostActionCookies(t *testing.T) {
handler := &testHandler{t}
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{
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{&action},
for name, test := range map[string]struct {
Action model.PostAction
ExpectedSucess bool
ExpectedStatusCode int
}{
"32 character ID": {
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",
},
},
},
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) {

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

@@ -496,17 +496,6 @@ func (c *Context) RequireJobType() *Context {
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 {
if c.Err != nil {
return c