Merge branch 'master' into ely

This commit is contained in:
ErickSkrauch 2018-03-19 02:19:14 +03:00
commit c7ac890812
No known key found for this signature in database
GPG Key ID: 669339FCBB30EE0E
3 changed files with 21 additions and 20 deletions

View File

@ -35,7 +35,7 @@ jobs:
- docker build -t elyby/chrly:$DOCKER_TAG . - docker build -t elyby/chrly:$DOCKER_TAG .
- docker push elyby/chrly:$DOCKER_TAG - docker push elyby/chrly:$DOCKER_TAG
- | - |
if [ -z ${TRAVIS_TAG+x} ]; then if [ ! -z ${TRAVIS_TAG+x} ] && [[ "$TRAVIS_TAG" != *"-"* ]]; then
docker tag elyby/chrly:$DOCKER_TAG elyby/chrly:latest docker tag elyby/chrly:$DOCKER_TAG elyby/chrly:latest
docker push elyby/chrly:latest docker push elyby/chrly:latest
fi fi

View File

@ -18,20 +18,11 @@ import (
"github.com/thedevsaddam/govalidator" "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() { 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 { govalidator.AddCustomRule("skinUploadingNotAvailable", func(field string, rule string, message string, value interface{}) error {
if message == "" { if message == "" {
message = "Skin uploading is temporary unavailable" message = "Skin uploading is temporary unavailable"
@ -39,6 +30,20 @@ func init() {
return errors.New(message) 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) { func (cfg *Config) PostSkin(resp http.ResponseWriter, req *http.Request) {
@ -152,11 +157,11 @@ func validatePostSkinRequest(request *http.Request) map[string][]string {
validationRules := govalidator.MapData{ validationRules := govalidator.MapData{
"identityId": {"required", "numeric", "min:1"}, "identityId": {"required", "numeric", "min:1"},
"username": {"required"}, "username": {"required"},
"uuid": {"required", "uuid"}, "uuid": {"required", "uuid_any"},
"skinId": {"required", "numeric", "min:1"}, "skinId": {"required", "numeric", "min:1"},
"url": {"url"}, "url": {"url"},
"file:skin": {"ext:png", "size:24576", "mime:image/png"}, "file:skin": {"ext:png", "size:24576", "mime:image/png"},
"hash": {"md5"}, "hash": {},
"is1_8": {"bool"}, "is1_8": {"bool"},
"isSlim": {"bool"}, "isSlim": {"bool"},
} }

View File

@ -268,7 +268,6 @@ func TestConfig_PostSkin_RequiredFields(t *testing.T) {
config, mocks := setupMocks(ctrl) config, mocks := setupMocks(ctrl)
form := url.Values{ form := url.Values{
"hash": {"this is not md5"},
"mojangTextures": {"someBase64EncodedString"}, "mojangTextures": {"someBase64EncodedString"},
} }
@ -307,9 +306,6 @@ func TestConfig_PostSkin_RequiredFields(t *testing.T) {
"The uuid field is required", "The uuid field is required",
"The uuid field must contain valid UUID" "The uuid field must contain valid UUID"
], ],
"hash": [
"The hash field must be a valid md5 hash"
],
"url": [ "url": [
"One of url or skin should be provided, but not both" "One of url or skin should be provided, but not both"
], ],