mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 08:22:49 +01:00
Merge pull request 'feat: extend webfinger to respond to profile page URIs' (#2883) from realaravinth/forgejo:cb-2870 into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2883 Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
commit
d5fd40821e
2 changed files with 72 additions and 0 deletions
|
@ -64,6 +64,63 @@ func WebfingerQuery(ctx *context.Context) {
|
|||
if u != nil && u.KeepEmailPrivate {
|
||||
err = user_model.ErrUserNotExist{}
|
||||
}
|
||||
case "https", "http":
|
||||
if resource.Host != appURL.Host {
|
||||
ctx.Error(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
p := strings.Trim(resource.Path, "/")
|
||||
if len(p) == 0 {
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
parts := strings.Split(p, "/")
|
||||
|
||||
switch len(parts) {
|
||||
case 1: // user
|
||||
u, err = user_model.GetUserByName(ctx, parts[0])
|
||||
case 2: // repository
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
|
||||
case 3:
|
||||
switch parts[2] {
|
||||
case "issues":
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
|
||||
case "pulls":
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
|
||||
case "projects":
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
|
||||
default:
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
|
||||
}
|
||||
case 4:
|
||||
//nolint:gocritic
|
||||
if parts[3] == "teams" {
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
|
||||
} else {
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
default:
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
ctx.Error(http.StatusBadRequest)
|
||||
return
|
||||
|
|
|
@ -66,4 +66,19 @@ func TestWebfinger(t *testing.T) {
|
|||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=mailto:%s", user.Email))
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=https://%s/%s/", appURL.Host, user.Name))
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=https://%s/%s", appURL.Host, user.Name))
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=http://%s/%s/foo", appURL.Host, user.Name))
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=http://%s", appURL.Host))
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=http://%s/%s/foo", "example.com", user.Name))
|
||||
MakeRequest(t, req, http.StatusBadRequest)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue