From aed957a8969e0580c1c3062fb4108f6eea743445 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sat, 17 Feb 2018 02:15:20 +0300 Subject: [PATCH 1/4] Fix latest tag condition --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d6fcf63..ef28f2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ jobs: - docker build -t elyby/chrly:$DOCKER_TAG . - docker push elyby/chrly:$DOCKER_TAG - | - if [ -z ${TRAVIS_TAG+x} ]; then + if [ ! -z ${TRAVIS_TAG+x} ] && [ "$TRAVIS_BRANCH" == "master" ]; then docker tag elyby/chrly:$DOCKER_TAG elyby/chrly:latest docker push elyby/chrly:latest fi From 9fc6ca54d9fadfae238d2db630bfc78c1bb6dbfb Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sat, 17 Feb 2018 02:21:03 +0300 Subject: [PATCH 2/4] Fix latest tag condition --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ef28f2a..1c8a520 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ jobs: - docker build -t elyby/chrly:$DOCKER_TAG . - docker push elyby/chrly:$DOCKER_TAG - | - if [ ! -z ${TRAVIS_TAG+x} ] && [ "$TRAVIS_BRANCH" == "master" ]; then + if [ ! -z ${TRAVIS_TAG+x} ] && [[ "$TRAVIS_TAG" != *"-"* ]]; then docker tag elyby/chrly:$DOCKER_TAG elyby/chrly:latest docker push elyby/chrly:latest fi From 34598e39bc02d3346e04dff73a303f6d78aa803d Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 19 Mar 2018 01:16:37 +0300 Subject: [PATCH 3/4] Allow any uuid version --- http/api.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/http/api.go b/http/api.go index ac737f1..bead6de 100644 --- a/http/api.go +++ b/http/api.go @@ -18,6 +18,10 @@ import ( "github.com/thedevsaddam/govalidator" ) +//noinspection GoSnakeCaseUsage +const UUID_ANY = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" +var regexUuidAny = regexp.MustCompile(UUID_ANY) + func init() { govalidator.AddCustomRule("md5", func(field string, rule string, message string, value interface{}) error { val := []byte(value.(string)) @@ -39,6 +43,20 @@ func init() { return errors.New(message) }) + + // Add ability to validate any possible uuid form + govalidator.AddCustomRule("uuid_any", func(field string, rule string, message string, value interface{}) error { + str := value.(string) + if !regexUuidAny.MatchString(str) { + if message == "" { + message = fmt.Sprintf("The %s field must contain valid UUID", field) + } + + return errors.New(message) + } + + return nil + }) } func (cfg *Config) PostSkin(resp http.ResponseWriter, req *http.Request) { @@ -152,7 +170,7 @@ func validatePostSkinRequest(request *http.Request) map[string][]string { validationRules := govalidator.MapData{ "identityId": {"required", "numeric", "min:1"}, "username": {"required"}, - "uuid": {"required", "uuid"}, + "uuid": {"required", "uuid_any"}, "skinId": {"required", "numeric", "min:1"}, "url": {"url"}, "file:skin": {"ext:png", "size:24576", "mime:image/png"}, From b73582bbf404b9f7d3ebc9357c0e031da4d0ebb2 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 19 Mar 2018 02:14:59 +0300 Subject: [PATCH 4/4] Do not limit hash format only to md5 --- http/api.go | 15 +-------------- http/api_test.go | 4 ---- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/http/api.go b/http/api.go index bead6de..0282f7a 100644 --- a/http/api.go +++ b/http/api.go @@ -23,19 +23,6 @@ const UUID_ANY = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ var regexUuidAny = regexp.MustCompile(UUID_ANY) func init() { - govalidator.AddCustomRule("md5", func(field string, rule string, message string, value interface{}) error { - val := []byte(value.(string)) - if ok, _ := regexp.Match(`^[a-f0-9]{32}$`, val); !ok { - if message == "" { - message = fmt.Sprintf("The %s field must be a valid md5 hash", field) - } - - return errors.New(message) - } - - return nil - }) - govalidator.AddCustomRule("skinUploadingNotAvailable", func(field string, rule string, message string, value interface{}) error { if message == "" { message = "Skin uploading is temporary unavailable" @@ -174,7 +161,7 @@ func validatePostSkinRequest(request *http.Request) map[string][]string { "skinId": {"required", "numeric", "min:1"}, "url": {"url"}, "file:skin": {"ext:png", "size:24576", "mime:image/png"}, - "hash": {"md5"}, + "hash": {}, "is1_8": {"bool"}, "isSlim": {"bool"}, } diff --git a/http/api_test.go b/http/api_test.go index e0f2fee..cc2cf6f 100644 --- a/http/api_test.go +++ b/http/api_test.go @@ -268,7 +268,6 @@ func TestConfig_PostSkin_RequiredFields(t *testing.T) { config, mocks := setupMocks(ctrl) form := url.Values{ - "hash": {"this is not md5"}, "mojangTextures": {"someBase64EncodedString"}, } @@ -307,9 +306,6 @@ func TestConfig_PostSkin_RequiredFields(t *testing.T) { "The uuid field is required", "The uuid field must contain valid UUID" ], - "hash": [ - "The hash field must be a valid md5 hash" - ], "url": [ "One of url or skin should be provided, but not both" ],