Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5bee51f

Browse files
committed
limit message length
1 parent93de18a commit5bee51f

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

‎coderd/database/dbfake/dbfake.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3921,6 +3921,10 @@ func (q *fakeQuerier) InsertTemplateVersion(_ context.Context, arg database.Inse
39213921
return database.TemplateVersion{},err
39223922
}
39233923

3924+
iflen(arg.Message)>1048576 {
3925+
return database.TemplateVersion{},xerrors.New("message too long")
3926+
}
3927+
39243928
q.mutex.Lock()
39253929
deferq.mutex.Unlock()
39263930

‎coderd/database/dump.sql

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
ALTERTABLE template_versions ADD COLUMN messagetextNOT NULL DEFAULT'';
1+
ALTERTABLE template_versions ADD COLUMN messagevarchar(1048576)NOT NULL DEFAULT'';
22

33
COMMENT ON COLUMN template_versions.message IS'Message describing the changes in this version of the template, similar to a Git commit message. Like a commit message, this should be a short, high-level description of the changes in this version of the template. This message is immutable and should not be updated after the fact.';

‎coderd/templateversions_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"net/http"
77
"regexp"
8+
"strings"
89
"testing"
910

1011
"github.com/google/uuid"
@@ -51,6 +52,26 @@ func TestTemplateVersion(t *testing.T) {
5152
assert.Equal(t,"first try",tv.Message)
5253
})
5354

55+
t.Run("Message limit exceeded",func(t*testing.T) {
56+
t.Parallel()
57+
client,_,_:=coderdtest.NewWithAPI(t,nil)
58+
user:=coderdtest.CreateFirstUser(t,client)
59+
60+
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitLong)
61+
defercancel()
62+
63+
file,err:=client.Upload(ctx,codersdk.ContentTypeTar,bytes.NewReader([]byte{}))
64+
require.NoError(t,err)
65+
_,err=client.CreateTemplateVersion(ctx,user.OrganizationID, codersdk.CreateTemplateVersionRequest{
66+
Name:"bananas",
67+
Message:strings.Repeat("a",1048577),
68+
StorageMethod:codersdk.ProvisionerStorageMethodFile,
69+
FileID:file.ID,
70+
Provisioner:codersdk.ProvisionerTypeEcho,
71+
})
72+
require.Error(t,err,"message too long, create should fail")
73+
})
74+
5475
t.Run("MemberCanRead",func(t*testing.T) {
5576
t.Parallel()
5677

‎codersdk/organizations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type OrganizationMember struct {
4343
// CreateTemplateVersionRequest enables callers to create a new Template Version.
4444
typeCreateTemplateVersionRequeststruct {
4545
Namestring`json:"name,omitempty" validate:"omitempty,template_version_name"`
46-
Messagestring`json:"message,omitempty"`
46+
Messagestring`json:"message,omitempty" validate:"lt=1048577"`// Database limit: 1048576.
4747
// TemplateID optionally associates a version with a template.
4848
TemplateID uuid.UUID`json:"template_id,omitempty" format:"uuid"`
4949
StorageMethodProvisionerStorageMethod`json:"storage_method" validate:"oneof=file,required" enums:"file"`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp