mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 16:47:30 +00:00
added more tests
This commit is contained in:
parent
b5a467e94d
commit
184388015d
|
@ -83,7 +83,7 @@ func (value PersonId) Validate() []string {
|
|||
result = append(result, validation.ValidateOneOf(value.source, []string{"forgejo", "gitea"})...)
|
||||
switch value.source {
|
||||
case "forgejo", "gitea":
|
||||
if !strings.Contains(value.path, "api/v1/activitypub/user-id") {
|
||||
if strings.ToLower(value.path) != "api/v1/activitypub/user-id" {
|
||||
result = append(result, fmt.Sprintf("path has to be a api path"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,59 @@ func TestNewPersonId(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPersonIdValidation(t *testing.T) {
|
||||
sut := PersonId{
|
||||
source: "forgejo",
|
||||
schema: "https",
|
||||
path: "api/v1/activitypub/user-id",
|
||||
host: "an.other.host",
|
||||
port: "",
|
||||
unvalidatedInput: "https://an.other.host/api/v1/activitypub/user-id/",
|
||||
}
|
||||
if sut.Validate()[0] != "Field userId may not be empty" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate())
|
||||
}
|
||||
|
||||
sut = PersonId{
|
||||
userId: "1",
|
||||
source: "forgejox",
|
||||
schema: "https",
|
||||
path: "api/v1/activitypub/user-id",
|
||||
host: "an.other.host",
|
||||
port: "",
|
||||
unvalidatedInput: "https://an.other.host/api/v1/activitypub/user-id/1",
|
||||
}
|
||||
if sut.Validate()[0] != "Value forgejox is not contained in allowed values [[forgejo gitea]]" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate())
|
||||
}
|
||||
|
||||
sut = PersonId{
|
||||
userId: "1",
|
||||
source: "forgejo",
|
||||
schema: "https",
|
||||
path: "api/v1/activitypub/user-idx",
|
||||
host: "an.other.host",
|
||||
port: "",
|
||||
unvalidatedInput: "https://an.other.host/api/v1/activitypub/user-id/1",
|
||||
}
|
||||
if sut.Validate()[0] != "path has to be a api path" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate())
|
||||
}
|
||||
|
||||
sut = PersonId{
|
||||
userId: "1",
|
||||
source: "forgejo",
|
||||
schema: "https",
|
||||
path: "api/v1/activitypub/user-id",
|
||||
host: "an.other.host",
|
||||
port: "",
|
||||
unvalidatedInput: "https://an.other.host/api/v1/activitypub/user-id/1?illegal=action",
|
||||
}
|
||||
if sut.Validate()[0] != "not all input: \"https://an.other.host/api/v1/activitypub/user-id/1?illegal=action\" was parsed: \"https://an.other.host/api/v1/activitypub/user-id/1\"" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate())
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebfingerId(t *testing.T) {
|
||||
sut, _ := NewPersonId("https://codeberg.org/api/v1/activitypub/user-id/12345", "forgejo")
|
||||
if sut.AsWebfinger() != "@12345@codeberg.org" {
|
||||
|
|
|
@ -138,7 +138,7 @@ func IsValidUsername(name string) bool {
|
|||
|
||||
func ValidateNotEmpty(value string, fieldName string) []string {
|
||||
if value == "" {
|
||||
return []string{fmt.Sprintf("Field %v may not be empty.", fieldName)}
|
||||
return []string{fmt.Sprintf("Field %v may not be empty", fieldName)}
|
||||
}
|
||||
return []string{}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue