Skip to content

Commit cdfc360

Browse files
authored
increase app/fn/trigger length caps (#1465)
was 30, now 255. the service validates the same value, via a different method, for each of these already. sql uses varchar 256 so we're good. can't think of any other ways this might break, so going for it.
1 parent 4b30cad commit cdfc360

File tree

10 files changed

+50
-16
lines changed

10 files changed

+50
-16
lines changed

api/models/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var (
3131
}
3232
ErrAppsTooLongName = err{
3333
code: http.StatusBadRequest,
34-
error: fmt.Errorf("App name must be %v characters or less", maxAppName),
34+
error: fmt.Errorf("App name must be %v characters or less", MaxLengthAppName),
3535
}
3636
ErrAppsInvalidName = err{
3737
code: http.StatusBadRequest,
@@ -98,7 +98,7 @@ func (a *App) ValidateName() error {
9898
return ErrMissingName
9999
}
100100

101-
if len(a.Name) > maxAppName {
101+
if len(a.Name) > MaxLengthAppName {
102102
return ErrAppsTooLongName
103103
}
104104

api/models/app_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ func TestAppEquality(t *testing.T) {
149149
}
150150

151151
func TestValidateAppName(t *testing.T) {
152+
tooLongName := "7"
153+
for i := 0; i < MaxLengthAppName+1; i++ {
154+
tooLongName += "7"
155+
}
156+
152157
testCases := []struct {
153158
Name string
154159
Want error
155160
}{
156161
{"valid_name-101", nil},
157-
{"an_app_with_a_name_that_is_too_long", ErrAppsTooLongName},
162+
{tooLongName, ErrAppsTooLongName},
158163
{"", ErrMissingName},
159164
{"invalid.character", ErrAppsInvalidName},
160165
}

api/models/error.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import (
66
"net/http"
77
)
88

9-
// TODO we can put constants all in this file too
109
const (
11-
maxAppName = 30
12-
maxFnName = 30
13-
MaxTriggerName = 30
10+
// MaxLengthAppName is the max length for an app name
11+
MaxLengthAppName = 255
12+
// MaxLengthFnName is the max length for an fn name
13+
MaxLengthFnName = 255
14+
// MaxLengthTriggerName is the max length for a trigger name
15+
MaxLengthTriggerName = 255
1416
)
1517

1618
var (

api/models/fn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var (
4444
}
4545
ErrFnsTooLongName = err{
4646
code: http.StatusBadRequest,
47-
error: fmt.Errorf("Fn name must be %v characters or less", maxFnName),
47+
error: fmt.Errorf("Fn name must be %v characters or less", MaxLengthFnName),
4848
}
4949
ErrFnsMissingAppID = err{
5050
code: http.StatusBadRequest,
@@ -178,7 +178,7 @@ func (f *Fn) ValidateName() error {
178178
return ErrFnsMissingName
179179
}
180180

181-
if len(f.Name) > maxFnName {
181+
if len(f.Name) > MaxLengthFnName {
182182
return ErrFnsTooLongName
183183
}
184184

api/models/fn_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,18 @@ func TestFnEquality(t *testing.T) {
108108
}
109109

110110
func TestValidateFnName(t *testing.T) {
111+
tooLongName := "7"
112+
for i := 0; i < MaxLengthFnName+1; i++ {
113+
tooLongName += "7"
114+
}
115+
111116
testCases := []struct {
112117
Name string
113118
Want error
114119
}{
115120
{"valid_name-101", nil},
116121
{"unescaped/path", ErrFnsInvalidName},
117-
{"a_function_with_a_name_that_is_too_long", ErrFnsTooLongName},
122+
{tooLongName, ErrFnsTooLongName},
118123
{"", ErrFnsMissingName},
119124
}
120125

api/models/trigger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ var (
9595
//ErrTriggerTooLongName - name exceeds maximum permitted name
9696
ErrTriggerTooLongName = err{
9797
code: http.StatusBadRequest,
98-
error: fmt.Errorf("Trigger name must be %v characters or less", MaxTriggerName)}
98+
error: fmt.Errorf("Trigger name must be %v characters or less", MaxLengthTriggerName)}
9999
//ErrTriggerInvalidName - name does not comply with naming spec
100100
ErrTriggerInvalidName = err{
101101
code: http.StatusBadRequest,
@@ -177,7 +177,7 @@ func (t *Trigger) ValidateName() error {
177177
return ErrTriggerMissingName
178178
}
179179

180-
if len(t.Name) > MaxTriggerName {
180+
if len(t.Name) > MaxLengthTriggerName {
181181
return ErrTriggerTooLongName
182182
}
183183

api/models/trigger_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ func TestTriggerEquality(t *testing.T) {
149149
}
150150

151151
func TestValidateTriggerName(t *testing.T) {
152+
tooLongName := "7"
153+
for i := 0; i < MaxLengthTriggerName+1; i++ {
154+
tooLongName += "7"
155+
}
156+
152157
testCases := []struct {
153158
Name string
154159
Want error
155160
}{
156161
{"valid_name-101", nil},
157-
{"a_trigger_with_a_name_that_is_too_long", ErrTriggerTooLongName},
162+
{tooLongName, ErrTriggerTooLongName},
158163
{"", ErrTriggerMissingName},
159164
{"invalid.character", ErrTriggerInvalidName},
160165
}

api/server/apps_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import (
55
"encoding/base64"
66
"encoding/json"
77
"errors"
8+
"fmt"
89
"log"
910
"net/http"
1011
"strings"
1112
"testing"
1213
"time"
1314

14-
"fmt"
1515
"github.com/fnproject/fn/api/datastore"
1616
"github.com/fnproject/fn/api/models"
1717
"github.com/gin-gonic/gin"
@@ -36,6 +36,11 @@ func TestAppCreate(t *testing.T) {
3636
}
3737
}()
3838

39+
tooLongName := "7"
40+
for i := 0; i < models.MaxLengthAppName+1; i++ {
41+
tooLongName += "7"
42+
}
43+
3944
for i, test := range []struct {
4045
mock models.Datastore
4146
path string
@@ -48,7 +53,7 @@ func TestAppCreate(t *testing.T) {
4853
{datastore.NewMock(), "/v2/apps", `{}`, http.StatusBadRequest, models.ErrMissingName},
4954
{datastore.NewMock(), "/v2/apps", `{"name": "app", "id":"badId"}`, http.StatusBadRequest, models.ErrAppIDProvided},
5055
{datastore.NewMock(), "/v2/apps", `{ "name": "" }`, http.StatusBadRequest, models.ErrMissingName},
51-
{datastore.NewMock(), "/v2/apps", `{"name": "1234567890123456789012345678901" }`, http.StatusBadRequest, models.ErrAppsTooLongName},
56+
{datastore.NewMock(), "/v2/apps", fmt.Sprintf(`{"name": "%s" }`, tooLongName), http.StatusBadRequest, models.ErrAppsTooLongName},
5257
{datastore.NewMock(), "/v2/apps", `{ "name": "&&%@!#$#@$" }`, http.StatusBadRequest, models.ErrAppsInvalidName},
5358
{datastore.NewMock(), "/v2/apps", `{ "name": "app", "annotations" : { "":"val" }}`, http.StatusBadRequest, models.ErrInvalidAnnotationKey},
5459
{datastore.NewMock(), "/v2/apps", `{"name": "app", "annotations" : { "key":"" }}`, http.StatusBadRequest, models.ErrInvalidAnnotationValue},

api/server/fns_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ func (test *funcTestCase) run(t *testing.T, i int, buf *bytes.Buffer) {
8383
func TestFnCreate(t *testing.T) {
8484
buf := setLogBuffer()
8585

86+
tooLongName := "7"
87+
for i := 0; i < models.MaxLengthAppName+1; i++ {
88+
tooLongName += "7"
89+
}
90+
8691
a := &models.App{Name: "a", ID: "aid"}
8792
ds := datastore.NewMockInit([]*models.App{a})
8893
for i, test := range []funcTestCase{
@@ -92,6 +97,7 @@ func TestFnCreate(t *testing.T) {
9297
{ds, http.MethodPost, "/v2/fns", fmt.Sprintf(`{ "app_id": "%s" }`, a.ID), http.StatusBadRequest, models.ErrFnsMissingName},
9398
{ds, http.MethodPost, "/v2/fns", fmt.Sprintf(`{ "app_id": "%s", "name": "a" }`, a.ID), http.StatusBadRequest, models.ErrFnsMissingImage},
9499
{ds, http.MethodPost, "/v2/fns", fmt.Sprintf(`{ "app_id": "%s", "name": " ", "image": "fnproject/fn-test-utils" }`, a.ID), http.StatusBadRequest, models.ErrFnsInvalidName},
100+
{ds, http.MethodPost, "/v2/fns", fmt.Sprintf(`{ "app_id": "%s", "name": "%s", "image": "fnproject/fn-test-utils" }`, a.ID, tooLongName), http.StatusBadRequest, models.ErrFnsTooLongName},
95101
{ds, http.MethodPost, "/v2/fns", fmt.Sprintf(`{ "app_id": "%s", "name": "a", "image": "fnproject/fn-test-utils", "timeout": 3601 }`, a.ID), http.StatusBadRequest, models.ErrFnsInvalidTimeout},
96102
{ds, http.MethodPost, "/v2/fns", fmt.Sprintf(`{ "app_id": "%s", "name": "a", "image": "fnproject/fn-test-utils", "idle_timeout": 3601 }`, a.ID), http.StatusBadRequest, models.ErrFnsInvalidIdleTimeout},
97103
{ds, http.MethodPost, "/v2/fns", fmt.Sprintf(`{ "app_id": "%s", "name": "a", "image": "fnproject/fn-test-utils", "memory": 100000000000000 }`, a.ID), http.StatusBadRequest, models.ErrInvalidMemory},

api/server/trigger_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/base64"
66
"encoding/json"
7+
"fmt"
78
"net/http"
89
"strings"
910
"testing"
@@ -33,6 +34,11 @@ func TestTriggerCreate(t *testing.T) {
3334
fn.SetDefaults()
3435
commonDS := datastore.NewMockInit([]*models.App{a, a2}, []*models.Fn{fn})
3536

37+
tooLongName := "7"
38+
for i := 0; i < models.MaxLengthTriggerName+1; i++ {
39+
tooLongName += "7"
40+
}
41+
3642
for i, test := range []struct {
3743
mock models.Datastore
3844
path string
@@ -50,7 +56,7 @@ func TestTriggerCreate(t *testing.T) {
5056
{commonDS, BaseRoute, `{ "name": "Test", "app_id": "appid", "fn_id": "fnid", "type":"http"}`, http.StatusBadRequest, models.ErrTriggerMissingSource},
5157
{commonDS, BaseRoute, `{ "name": "Test", "app_id": "appid", "fn_id": "fnid", "type":"http", "source":"src"}`, http.StatusBadRequest, models.ErrTriggerMissingSourcePrefix},
5258

53-
{commonDS, BaseRoute, `{ "name": "1234567890123456789012345678901", "app_id": "appid", "fn_id": "fnid", "type":"http"}`, http.StatusBadRequest, models.ErrTriggerTooLongName},
59+
{commonDS, BaseRoute, fmt.Sprintf(`{ "name": "%s", "app_id": "appid", "fn_id": "fnid", "type":"http"}`, tooLongName), http.StatusBadRequest, models.ErrTriggerTooLongName},
5460
{commonDS, BaseRoute, `{ "name": "&&%@!#$#@$","app_id": "appid", "fn_id": "fnid", "type":"http" }`, http.StatusBadRequest, models.ErrTriggerInvalidName},
5561
{commonDS, BaseRoute, `{ "name": "trigger", "app_id": "appid", "fn_id": "fnid", "type": "http", "source": "/src", "annotations" : { "":"val" }}`, http.StatusBadRequest, models.ErrInvalidAnnotationKey},
5662
{commonDS, BaseRoute, `{ "id": "asdasca", "name": "trigger", "app_id": "appid", "fn_id": "fnid", "type": "http", "source": "/src"}`, http.StatusBadRequest, models.ErrTriggerIDProvided},

0 commit comments

Comments
 (0)