refactor: Gitea 式目录改组,移除本分支 SPA 与杂项产物
将 model/service/handler/middleware 迁至 models/services/routers/api/modules/auth,并删除 frontend、embed_static、scripts 及误入库缓存/二进制。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
46
services/friend_link_reciprocal_test.go
Normal file
46
services/friend_link_reciprocal_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPageContainsLinkToHost(t *testing.T) {
|
||||
our, err := url.Parse("https://forum.example.com")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
page := "https://friend.example/links.html"
|
||||
host := "forum.example.com"
|
||||
|
||||
if !pageContainsLinkToHost(`<a href="https://forum.example.com/">本站</a>`, page, our, host) {
|
||||
t.Fatal("应检测到绝对回链")
|
||||
}
|
||||
if pageContainsLinkToHost(`<a href="https://other.example/">其他</a>`, page, our, host) {
|
||||
t.Fatal("不应把外站当成回链")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPageContainsLinkToHost_LargeHTMLFast(t *testing.T) {
|
||||
our, err := url.Parse("https://forum.example.com")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var b strings.Builder
|
||||
b.Grow(512 * 1024)
|
||||
for b.Len() < 400*1024 {
|
||||
b.WriteString(`<a href="https://noise.example/page">x</a>`)
|
||||
}
|
||||
b.WriteString(`<a href="https://forum.example.com/">本站</a>`)
|
||||
html := b.String()
|
||||
|
||||
start := time.Now()
|
||||
if !pageContainsLinkToHost(html, "https://friend.example/", our, "forum.example.com") {
|
||||
t.Fatal("应在大量无关链接中找到回链")
|
||||
}
|
||||
if elapsed := time.Since(start); elapsed > 500*time.Millisecond {
|
||||
t.Fatalf("解析耗时过长: %s", elapsed)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user