mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 12:54:53 -05:00
fix NPE
This commit is contained in:
parent
e9fed7a488
commit
6c7cff4f16
2 changed files with 27 additions and 3 deletions
|
@ -46,8 +46,16 @@ func (like ForgeLike) Validate() []string {
|
|||
var result []string
|
||||
result = append(result, validation.ValidateNotEmpty(string(like.Type), "type")...)
|
||||
result = append(result, validation.ValidateOneOf(string(like.Type), []any{"Like"})...)
|
||||
result = append(result, validation.ValidateNotEmpty(like.Actor.GetID().String(), "actor")...)
|
||||
result = append(result, validation.ValidateNotEmpty(like.Object.GetID().String(), "object")...)
|
||||
if like.Actor == nil {
|
||||
result = append(result, "Actor my not be nil.")
|
||||
} else {
|
||||
result = append(result, validation.ValidateNotEmpty(like.Actor.GetID().String(), "actor")...)
|
||||
}
|
||||
if like.Object == nil {
|
||||
result = append(result, "Object my not be nil.")
|
||||
} else {
|
||||
result = append(result, validation.ValidateNotEmpty(like.Object.GetID().String(), "object")...)
|
||||
}
|
||||
result = append(result, validation.ValidateNotEmpty(like.StartTime.String(), "startTime")...)
|
||||
if like.StartTime.IsZero() {
|
||||
result = append(result, "StartTime was invalid.")
|
||||
|
|
|
@ -128,7 +128,7 @@ func TestActivityValidation(t *testing.T) {
|
|||
sut.UnmarshalJSON([]byte(`{"actor":"https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
||||
"object":"https://codeberg.org/api/activitypub/repository-id/1",
|
||||
"startTime": "2014-12-31T23:00:00-08:00"}`))
|
||||
if sut.Validate()[0] != "Field type should not be empty" {
|
||||
if sut.Validate()[0] != "type should not be empty" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate()[0])
|
||||
}
|
||||
|
||||
|
@ -147,4 +147,20 @@ func TestActivityValidation(t *testing.T) {
|
|||
if sut.Validate()[0] != "StartTime was invalid." {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate())
|
||||
}
|
||||
|
||||
sut.UnmarshalJSON([]byte(`{"type":"Wrong",
|
||||
"actor":"https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
||||
"object":"https://codeberg.org/api/activitypub/repository-id/1",
|
||||
"startTime": "2014-12-31T23:00:00-08:00"}`))
|
||||
if sut.Validate()[0] != "Value Wrong is not contained in allowed values [Like]" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate())
|
||||
}
|
||||
}
|
||||
|
||||
func TestActivityValidation_Attack(t *testing.T) {
|
||||
sut := new(ForgeLike)
|
||||
sut.UnmarshalJSON([]byte(`{rubbish}`))
|
||||
if len(sut.Validate()) != 5 {
|
||||
t.Errorf("5 validateion errors expected but was: %v\n", len(sut.Validate()))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue