2023-11-15 17:07:23 +03:00
|
|
|
// Copyright 2023 The forgejo Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package activitypub
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2023-11-22 18:40:28 +03:00
|
|
|
func TestActorParserEmpty(t *testing.T) {
|
|
|
|
item := ""
|
|
|
|
want := ActorID{}
|
|
|
|
|
|
|
|
got, _ := ParseActorID(item)
|
|
|
|
|
|
|
|
if got != want {
|
|
|
|
t.Errorf("ParseActorID returned non empty actor id for empty input.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestActorParserValid(t *testing.T) {
|
|
|
|
item := "https://repo.prod.meissa.de/api/v1/activitypub/user-id/1"
|
|
|
|
want := ActorID{
|
|
|
|
schema: "https",
|
|
|
|
userId: "1",
|
|
|
|
path: "/api/v1/activitypub/user-id/1",
|
|
|
|
host: "repo.prod.meissa.de",
|
|
|
|
port: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
got, _ := ParseActorID(item)
|
|
|
|
|
|
|
|
if got != want {
|
2023-11-23 16:17:35 +03:00
|
|
|
t.Errorf("ParseActorID did not return want: %v.", want)
|
2023-11-22 18:40:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidateValid(t *testing.T) {
|
|
|
|
item := ActorID{
|
|
|
|
schema: "https",
|
|
|
|
userId: "1",
|
|
|
|
path: "/api/v1/activitypub/user-id/1",
|
|
|
|
host: "repo.prod.meissa.de",
|
|
|
|
port: "",
|
2023-11-15 17:07:23 +03:00
|
|
|
}
|
|
|
|
|
2023-11-24 13:38:01 +03:00
|
|
|
if valid, _ := item.IsValid(); !valid {
|
|
|
|
t.Errorf("Actor was invalid with valid input.")
|
2023-11-15 17:07:23 +03:00
|
|
|
}
|
2023-11-22 18:40:28 +03:00
|
|
|
}
|
2023-11-15 17:07:23 +03:00
|
|
|
|
2023-11-22 18:40:28 +03:00
|
|
|
func TestValidateInvalid(t *testing.T) {
|
|
|
|
item := "123456"
|
2023-11-15 17:07:23 +03:00
|
|
|
|
2023-11-22 18:40:28 +03:00
|
|
|
actor, _ := ParseActorID(item)
|
2023-11-16 18:03:05 +03:00
|
|
|
|
2023-11-24 13:38:01 +03:00
|
|
|
if valid, _ := actor.IsValid(); valid {
|
|
|
|
t.Errorf("Actor was valid with invalid input.")
|
2023-11-15 17:07:23 +03:00
|
|
|
}
|
|
|
|
}
|
2023-11-23 19:02:54 +03:00
|
|
|
|
|
|
|
func TestGetHostAndPort(t *testing.T) {
|
|
|
|
item := ActorID{
|
|
|
|
schema: "https",
|
|
|
|
userId: "1",
|
|
|
|
path: "/api/v1/activitypub/user-id/1",
|
|
|
|
host: "repo.prod.meissa.de",
|
|
|
|
port: "80",
|
|
|
|
}
|
|
|
|
want := "repo.prod.meissa.de:80"
|
|
|
|
|
|
|
|
hostAndPort := item.GetHostAndPort()
|
|
|
|
|
|
|
|
if hostAndPort != want {
|
|
|
|
t.Errorf("GetHostAndPort did not return correct host and port combination: %v", hostAndPort)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|