Skip to content

Commit

Permalink
fix: resource_name length
Browse files Browse the repository at this point in the history
  • Loading branch information
gassara-kys committed Nov 8, 2023
1 parent 6deef65 commit 7bedaf9
Show file tree
Hide file tree
Showing 37 changed files with 66 additions and 59 deletions.
2 changes: 1 addition & 1 deletion pkg/ai/mocks/AIService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/db/mocks/AlertRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/db/mocks/FindingRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/db/mocks/IAMRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/db/mocks/ProjectRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/db/mocks/ReportRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/alert/entity.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/alert/mocks/AlertServiceClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/alert/mocks/AlertServiceServer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/alert/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/alert/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (e *AlertRuleForUpsert) Validate() error {
validation.Field(&e.ProjectId, validation.Required),
validation.Field(&e.Name, validation.Required, validation.Length(0, 200)),
validation.Field(&e.Score, validation.Min(0.0), validation.Max(1.0)),
validation.Field(&e.ResourceName, validation.Length(0, 255)),
validation.Field(&e.ResourceName, validation.Length(0, 512)),
validation.Field(&e.Tag, validation.Length(0, 64)),
validation.Field(&e.FindingCnt, validation.Min(uint(1))),
)
Expand Down
8 changes: 7 additions & 1 deletion proto/alert/validator_entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import (
"testing"
)

const (
STRING_LENGTH_10 = "1234567890"
STRING_LENGTH_100 = STRING_LENGTH_10 + STRING_LENGTH_10 + STRING_LENGTH_10 + STRING_LENGTH_10 + STRING_LENGTH_10 + STRING_LENGTH_10 + STRING_LENGTH_10 + STRING_LENGTH_10 + STRING_LENGTH_10 + STRING_LENGTH_10
STRING_LENGTH_513 = STRING_LENGTH_100 + STRING_LENGTH_100 + STRING_LENGTH_100 + STRING_LENGTH_100 + STRING_LENGTH_100 + STRING_LENGTH_10 + "0123"
)

func TestValidateAlertForUpsert(t *testing.T) {
cases := []struct {
name string
Expand Down Expand Up @@ -253,7 +259,7 @@ func TestValidateAlertRuleForUpsert(t *testing.T) {
},
{
name: "NG too long resource_name",
input: &AlertRuleForUpsert{Name: "test_alert_rule", Score: 1.0, ProjectId: 1001, ResourceName: "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456", Tag: "test_tag", FindingCnt: 1},
input: &AlertRuleForUpsert{Name: "test_alert_rule", Score: 1.0, ProjectId: 1001, ResourceName: STRING_LENGTH_513, Tag: "test_tag", FindingCnt: 1},
wantErr: true,
},
{
Expand Down
4 changes: 2 additions & 2 deletions proto/finding/entity.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/finding/mocks/FindingServiceClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/finding/mocks/FindingServiceServer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/finding/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions proto/finding/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (l *ListFindingRequest) Validate() error {
return validation.ValidateStruct(l,
validation.Field(&l.ProjectId, validation.Required),
validation.Field(&l.DataSource, validation.Each(validation.Length(0, 64))),
validation.Field(&l.ResourceName, validation.Each(validation.Length(0, 255))),
validation.Field(&l.ResourceName, validation.Each(validation.Length(0, 512))),
validation.Field(&l.FromScore, validation.Min(0.0), validation.Max(1.0)),
validation.Field(&l.ToScore, validation.Min(0.0), validation.Max(1.0)),
validation.Field(&l.Tag, validation.Each(validation.Length(0, 64))),
Expand All @@ -36,7 +36,7 @@ func (b *BatchListFindingRequest) Validate() error {
return validation.ValidateStruct(b,
validation.Field(&b.ProjectId, validation.Required),
validation.Field(&b.DataSource, validation.Each(validation.Length(0, 64))),
validation.Field(&b.ResourceName, validation.Each(validation.Length(0, 255))),
validation.Field(&b.ResourceName, validation.Each(validation.Length(0, 512))),
validation.Field(&b.FromScore, validation.Min(0.0), validation.Max(1.0)),
validation.Field(&b.ToScore, validation.Min(0.0), validation.Max(1.0)),
validation.Field(&b.Tag, validation.Each(validation.Length(0, 64))),
Expand Down Expand Up @@ -165,7 +165,7 @@ func (c *ClearScoreRequest) Validate() error {
func (l *ListResourceRequest) Validate() error {
return validation.ValidateStruct(l,
validation.Field(&l.ProjectId, validation.Required),
validation.Field(&l.ResourceName, validation.Each(validation.Length(0, 255))),
validation.Field(&l.ResourceName, validation.Each(validation.Length(0, 512))),
validation.Field(&l.Tag, validation.Each(validation.Length(0, 64))),
validation.Field(&l.Sort, validation.In(
"resource_id", "resource_name", "updated_at")),
Expand Down Expand Up @@ -383,7 +383,7 @@ func (f *FindingForUpsert) Validate() error {
validation.Field(&f.Description, validation.Length(0, 200)),
validation.Field(&f.DataSource, validation.Required, validation.Length(0, 64)),
validation.Field(&f.DataSourceId, validation.Required, validation.Length(0, 255)),
validation.Field(&f.ResourceName, validation.Required, validation.Length(0, 255)),
validation.Field(&f.ResourceName, validation.Required, validation.Length(0, 512)),
validation.Field(&f.OriginalScore, validation.Min(0.0), validation.Max(f.OriginalMaxScore)),
validation.Field(&f.OriginalMaxScore, validation.NilOrNotEmpty, validation.Min(0.0), validation.Max(999.99)),
validation.Field(&f.Data, is.JSON),
Expand All @@ -401,7 +401,7 @@ func (f *FindingTagForUpsert) Validate() error {
// Validate ResourceForUpsert
func (r *ResourceForUpsert) Validate() error {
return validation.ValidateStruct(r,
validation.Field(&r.ResourceName, validation.Required, validation.Length(0, 255)),
validation.Field(&r.ResourceName, validation.Required, validation.Length(0, 512)),
)
}

Expand Down
9 changes: 5 additions & 4 deletions proto/finding/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const (
len129string string = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789=12345678901234567890123456789"
len201string string = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789=123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789=1"
len256string string = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789=123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789=12345678901234567890123456789012345678901234567890123456"
len513string string = len256string + len256string + "1"
maxLimit int32 = 200
)

Expand All @@ -29,7 +30,7 @@ func TestValidate_ListFindingRequest(t *testing.T) {
},
{
name: "NG too long resource_name",
input: &ListFindingRequest{ProjectId: 1, ResourceName: []string{len256string}},
input: &ListFindingRequest{ProjectId: 1, ResourceName: []string{len513string}},
wantErr: true,
},
{
Expand Down Expand Up @@ -117,7 +118,7 @@ func TestValidate_BatchListFindingRequest(t *testing.T) {
},
{
name: "NG too long resource_name",
input: &BatchListFindingRequest{ProjectId: 1, ResourceName: []string{len256string}},
input: &BatchListFindingRequest{ProjectId: 1, ResourceName: []string{len513string}},
wantErr: true,
},
{
Expand Down Expand Up @@ -517,7 +518,7 @@ func TestValidate_ListResourceRequest(t *testing.T) {
},
{
name: "NG Length(resource_name)",
input: &ListResourceRequest{ProjectId: 1, ResourceName: []string{len256string}},
input: &ListResourceRequest{ProjectId: 1, ResourceName: []string{len513string}},
wantErr: true,
},
{
Expand Down Expand Up @@ -1236,7 +1237,7 @@ func TestValidate_FindingForUpsert(t *testing.T) {
},
{
name: "NG too long resource name",
input: &FindingForUpsert{Description: "desc", DataSource: "ds", DataSourceId: "ds-001", ResourceName: len256string, ProjectId: 1001, OriginalScore: 50.5, OriginalMaxScore: 100.0, Data: `{"key": "value"}`},
input: &FindingForUpsert{Description: "desc", DataSource: "ds", DataSourceId: "ds-001", ResourceName: len513string, ProjectId: 1001, OriginalScore: 50.5, OriginalMaxScore: 100.0, Data: `{"key": "value"}`},
wantErr: true,
},
{
Expand Down
4 changes: 2 additions & 2 deletions proto/iam/access_token.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/iam/entity.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/iam/mocks/IAMServiceClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/iam/mocks/IAMServiceServer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/iam/policy.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/iam/role.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/iam/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/iam/user.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/iam/user_reserved.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/project/entity.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/project/mocks/ProjectServiceClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/project/mocks/ProjectServiceServer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/project/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/report/entity.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/report/mocks/ReportServiceClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/report/mocks/ReportServiceServer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/report/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7bedaf9

Please sign in to comment.