Skip to content

Commit

Permalink
fix: revert the modifications to resource naming rules (#568)
Browse files Browse the repository at this point in the history
* Revert "feat: change logic of resource name length check (#560)"

This reverts commit eb94297

* chore: update go.mod and some error msgs
  • Loading branch information
pythonberg1997 authored Jan 23, 2024
1 parent 1c47fbd commit 781b351
Show file tree
Hide file tree
Showing 19 changed files with 195 additions and 679 deletions.
8 changes: 0 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ require (
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
Expand All @@ -66,7 +65,6 @@ require (
github.com/creachadair/taskgroup v0.4.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
Expand All @@ -82,7 +80,6 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
Expand All @@ -92,7 +89,6 @@ require (
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
Expand Down Expand Up @@ -139,12 +135,10 @@ require (
github.com/prysmaticlabs/eth2-types v0.0.0-20210303084904-c9735a06829d // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rjeczalik/notify v0.9.1 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/rs/zerolog v1.29.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand All @@ -155,7 +149,6 @@ require (
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/urfave/cli/v2 v2.10.2 // indirect
github.com/wealdtech/go-bytesutil v1.1.1 // indirect
Expand All @@ -175,7 +168,6 @@ require (
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v0.5.5 // indirect
Expand Down
9 changes: 0 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8
github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
github.com/cespare/cp v1.1.1 h1:nCb6ZLdB7NRaqsm91JtQTAme2SKJzXVsdPIPkyJr1MU=
github.com/cespare/cp v1.1.1/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
Expand Down Expand Up @@ -298,8 +297,6 @@ github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018/go.mod h1:rQY
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U=
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4=
github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo=
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
Expand Down Expand Up @@ -343,7 +340,6 @@ github.com/eapache/go-resiliency v1.2.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5m
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts=
github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/dot v0.11.0/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s=
Expand Down Expand Up @@ -573,7 +569,6 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.5/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY=
github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg=
Expand Down Expand Up @@ -658,9 +653,7 @@ github.com/hdevalence/ed25519consensus v0.1.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3s
github.com/herumi/bls-eth-go-binary v0.0.0-20210130185500-57372fb27371/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U=
github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e h1:wCMygKUQhmcQAjlk2Gquzq6dLmyMv2kF+llRspoRgrk=
github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM=
github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c=
Expand Down Expand Up @@ -1243,7 +1236,6 @@ github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rjeczalik/notify v0.9.1 h1:CLCKso/QK1snAlnhNR/CNvNiFU2saUtjV0bx3EwNeCE=
github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
Expand Down Expand Up @@ -2043,7 +2035,6 @@ gopkg.in/jcmturner/dnsutils.v1 v1.0.1/go.mod h1:m3v+5svpVOhtFAP/wSz+yzh4Mc0Fg7eR
gopkg.in/jcmturner/goidentity.v3 v3.0.0/go.mod h1:oG2kH0IvSYNIu80dVAyu/yoefjq1mNfM5bm88whjWx4=
gopkg.in/jcmturner/gokrb5.v7 v7.5.0/go.mod h1:l8VISx+WGYp+Fp7KRbsiUuXTTOnxIc3Tuvyavf11/WM=
gopkg.in/jcmturner/rpc.v1 v1.1.0/go.mod h1:YIdkC4XfD6GXbzje11McwsDuOlZQSb9W4vfLvuNnlv8=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c=
gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns=
gopkg.in/redis.v4 v4.2.4/go.mod h1:8KREHdypkCEojGKQcjMqAODMICIVwZAONWq8RowTITA=
Expand Down
8 changes: 4 additions & 4 deletions types/grn.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (r *GRN) ParseFromString(res string, wildcards bool) error {
return gnfderrors.ErrInvalidGRN.Wrapf("Not allowed '/' in bucket resource name")
}
if !wildcards {
err = s3util.CheckValidBucketNameByCharacterLength(r.name)
err = s3util.CheckValidBucketName(r.name)
if err != nil {
return gnfderrors.ErrInvalidGRN.Wrapf("invalid bucketName: %s, err: %s", r.name, err)
}
Expand All @@ -179,7 +179,7 @@ func (r *GRN) ParseFromString(res string, wildcards bool) error {
return gnfderrors.ErrInvalidGRN.Wrapf("invalid group owner account, err : %s", err)
}
if !wildcards {
err = s3util.CheckValidGroupNameByCharacterLength(name)
err = s3util.CheckValidGroupName(name)
if err != nil {
return gnfderrors.ErrInvalidGRN.Wrapf("invalid group name, err : %s", err)
}
Expand All @@ -200,11 +200,11 @@ func (r *GRN) parseBucketAndObjectName(name string) (string, string, error) {
if !found {
return "", "", gnfderrors.ErrInvalidGRN.Wrapf("object name not found, grn: %s", name)
}
err := s3util.CheckValidBucketNameByCharacterLength(bucketName)
err := s3util.CheckValidBucketName(bucketName)
if err != nil {
return "", "", gnfderrors.ErrInvalidGRN.Wrapf("invalid bucketName, err: %s", err)
}
err = s3util.CheckValidObjectNameByCharacterLength(objectName)
err = s3util.CheckValidObjectName(objectName)
if err != nil {
return "", "", gnfderrors.ErrInvalidGRN.Wrapf("invalid objectName, err: %s", err)
}
Expand Down
105 changes: 16 additions & 89 deletions types/s3util/s3util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func CheckValidBucketName(bucketName string) (err error) {
return errors.Wrap(gnfderrors.ErrInvalidBucketName, "Bucket name cannot be empty")
}
if len(bucketName) < 3 {
return errors.Wrap(gnfderrors.ErrInvalidBucketName, "Bucket name cannot be shorter than 3 characters")
return errors.Wrap(gnfderrors.ErrInvalidBucketName, "Bucket name cannot be shorter than 3 bytes")
}
if len(bucketName) > 63 {
return errors.Wrap(gnfderrors.ErrInvalidBucketName, "Bucket name cannot be longer than 63 characters")
return errors.Wrap(gnfderrors.ErrInvalidBucketName, "Bucket name cannot be longer than 63 bytes")
}
if ipAddress.MatchString(bucketName) {
return errors.Wrap(gnfderrors.ErrInvalidBucketName, "Bucket name cannot be an ip address")
Expand All @@ -42,16 +42,25 @@ func CheckValidBucketName(bucketName string) (err error) {
return nil
}

const (
// Bad path components to be rejected by the path validity handler.
dotdotComponent = ".."
dotComponent = "."

// SlashSeparator - slash separator.
SlashSeparator = "/"
)

// CheckValidObjectName checks if we have a valid input object name.
//
// - http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html
// http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html
func CheckValidObjectName(objectName string) error {
// check the length of objectName
if len(objectName) == 0 || strings.TrimSpace(objectName) == "" {
return errors.Wrap(gnfderrors.ErrInvalidObjectName, "Object name cannot be empty")
}
if len(objectName) > 1024 {
return errors.Wrap(gnfderrors.ErrInvalidObjectName, "Object name cannot be longer than 1024 characters")
return errors.Wrap(gnfderrors.ErrInvalidObjectName, "Object name cannot be longer than 1024 bytes")
}

// check bad path component
Expand All @@ -77,10 +86,10 @@ func CheckValidGroupName(groupName string) error {
return errors.Wrap(gnfderrors.ErrInvalidGroupName, "Group name cannot be empty")
}
if len(groupName) < 3 {
return errors.Wrap(gnfderrors.ErrInvalidGroupName, "Group name cannot be shorter than 3 characters")
return errors.Wrap(gnfderrors.ErrInvalidGroupName, "Group name cannot be shorter than 3 bytes")
}
if len(groupName) > 63 {
return errors.Wrap(gnfderrors.ErrInvalidGroupName, "Group name cannot be longer than 63 characters")
return errors.Wrap(gnfderrors.ErrInvalidGroupName, "Group name cannot be longer than 63 bytes")
}
if !utf8.ValidString(groupName) {
return errors.Wrap(gnfderrors.ErrInvalidGroupName, "Group name with non UTF-8 strings is not supported")
Expand All @@ -89,95 +98,13 @@ func CheckValidGroupName(groupName string) error {
return nil
}

// CheckValidBucketNameByCharacterLength - checks if we have a valid input bucket name.
// This is a stricter version.
// - http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html
func CheckValidBucketNameByCharacterLength(bucketName string) (err error) {
if len(bucketName) == 0 || strings.TrimSpace(bucketName) == "" {
return errors.Wrap(gnfderrors.ErrInvalidBucketName, "Bucket name cannot be empty")
}
if utf8.RuneCountInString(bucketName) < 3 {
return errors.Wrap(gnfderrors.ErrInvalidBucketName, "Bucket name cannot be shorter than 3 characters")
}
if utf8.RuneCountInString(bucketName) > 63 {
return errors.Wrap(gnfderrors.ErrInvalidBucketName, "Bucket name cannot be longer than 63 characters")
}
if ipAddress.MatchString(bucketName) {
return errors.Wrap(gnfderrors.ErrInvalidBucketName, "Bucket name cannot be an ip address")
}
if strings.Contains(bucketName, "..") || strings.Contains(bucketName, ".-") || strings.Contains(bucketName, "-.") {
return errors.Wrap(gnfderrors.ErrInvalidBucketName, "Bucket name contains invalid characters")
}
if !validBucketName.MatchString(bucketName) {
return errors.Wrap(gnfderrors.ErrInvalidBucketName, "Bucket name contains invalid characters")
}

return nil
}

// CheckValidObjectNameByCharacterLength checks if we have a valid input object name.
//
// - http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html
func CheckValidObjectNameByCharacterLength(objectName string) error {
// check the length of objectName
if len(objectName) == 0 || strings.TrimSpace(objectName) == "" {
return errors.Wrap(gnfderrors.ErrInvalidObjectName, "Object name cannot be empty")
}
if utf8.RuneCountInString(objectName) > 1024 {
return errors.Wrap(gnfderrors.ErrInvalidObjectName, "Object name cannot be longer than 1024 characters")
}

// check bad path component
if hasBadPathComponent(objectName) {
return errors.Wrap(gnfderrors.ErrInvalidObjectName, "Object name with a bad path component is not supported")
}
// check UTF-8 strings
if !utf8.ValidString(objectName) {
return errors.Wrap(gnfderrors.ErrInvalidObjectName, "Object name with non UTF-8 strings is not supported")
}

if strings.Contains(objectName, `//`) {
// the error description and the judgement condition are not consistent
// `Contains` is not the same as `HasPrefix`
return errors.Wrap(gnfderrors.ErrInvalidObjectName, "Object name contains a \"//\" is not supported")
}

return nil
}

func CheckValidGroupNameByCharacterLength(groupName string) error {
if len(groupName) == 0 || strings.TrimSpace(groupName) == "" {
return errors.Wrap(gnfderrors.ErrInvalidGroupName, "Group name cannot be empty")
}
if utf8.RuneCountInString(groupName) < 3 {
return errors.Wrap(gnfderrors.ErrInvalidGroupName, "Group name cannot be shorter than 3 characters")
}
if utf8.RuneCountInString(groupName) > 63 {
return errors.Wrap(gnfderrors.ErrInvalidGroupName, "Group name cannot be longer than 63 characters")
}
if !utf8.ValidString(groupName) {
return errors.Wrap(gnfderrors.ErrInvalidGroupName, "Group name with non UTF-8 strings is not supported")
}

return nil
}

const (
// Bad path components to be rejected by the path validity handler.
dotDotComponent = ".."
dotComponent = "."

// SlashSeparator - slash separator.
SlashSeparator = "/"
)

// Check if the incoming path has bad path components,
// such as ".." and "."
func hasBadPathComponent(path string) bool {
path = strings.TrimSpace(path)
for _, p := range strings.Split(path, SlashSeparator) {
switch strings.TrimSpace(p) {
case dotDotComponent:
case dotdotComponent:
return true
case dotComponent:
return true
Expand Down
4 changes: 2 additions & 2 deletions x/challenge/client/cli/tx_submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func CmdSubmit() *cobra.Command {
}

argBucketName := strings.TrimSpace(args[1])
if err := s3util.CheckValidBucketNameByCharacterLength(argBucketName); err != nil {
if err := s3util.CheckValidBucketName(argBucketName); err != nil {
return fmt.Errorf("bucket-name %s not a valid bucket name, please input a valid bucket-name", argBucketName)
}

argObjectName := strings.TrimSpace(args[2])
if err := s3util.CheckValidObjectNameByCharacterLength(argObjectName); err != nil {
if err := s3util.CheckValidObjectName(argObjectName); err != nil {
return fmt.Errorf("object-name %s not a valid object name, please input a valid object-name", argObjectName)
}

Expand Down
24 changes: 5 additions & 19 deletions x/challenge/types/message_submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/bnb-chain/greenfield/types/s3util"
)
Expand Down Expand Up @@ -56,25 +55,12 @@ func (msg *MsgSubmit) ValidateBasic() error {
return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sp operator address (%s)", err)
}

return nil
}
if err = s3util.CheckValidBucketName(msg.BucketName); err != nil {
return err
}

func (msg *MsgSubmit) ValidateRuntime(ctx sdk.Context) error {
var err error
if ctx.IsUpgraded(upgradetypes.Ural) {
if err = s3util.CheckValidBucketNameByCharacterLength(msg.BucketName); err != nil {
return err
}
if err = s3util.CheckValidObjectNameByCharacterLength(msg.ObjectName); err != nil {
return err
}
} else {
if err = s3util.CheckValidBucketName(msg.BucketName); err != nil {
return err
}
if err = s3util.CheckValidObjectName(msg.ObjectName); err != nil {
return err
}
if err = s3util.CheckValidObjectName(msg.ObjectName); err != nil {
return err
}

return nil
Expand Down
11 changes: 1 addition & 10 deletions x/challenge/types/message_submit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package types
import (
"testing"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -67,14 +65,7 @@ func TestMsgSubmit_ValidateBasic(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
err := tt.msg.ValidateBasic()
if tt.err != nil {
if err != nil {
require.ErrorIs(t, err, tt.err)
} else {
upgradeChecker := func(sdk.Context, string) bool { return true }
ctx := sdk.NewContext(nil, tmproto.Header{}, false, upgradeChecker, nil)
err = tt.msg.ValidateRuntime(ctx)
require.ErrorIs(t, err, tt.err)
}
require.ErrorIs(t, err, tt.err)
return
}
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 781b351

Please sign in to comment.