Bind prompt history to Gitea's server-rendered session identity without an API token
Hop-State: A_06FNB7D05ZQ3AHD1V0GY5P8 Hop-Proposal: R_06FNB7CDK6ZKM505CPR2DY8 Hop-Task: T_06FNB715NCG0M3SVDJAGHY8 Hop-Attempt: AT_06FNB715NCK5MKAVH59TE0G
This commit is contained in:
@@ -66,28 +66,21 @@ func TestUserUsesTokenAndDecodesStableID(t *testing.T) {
|
||||
|
||||
func TestAuthenticatedUserForwardsSessionCookie(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/user/settings":
|
||||
if got := r.Header.Get("Cookie"); got != "i_like_gitea=session" {
|
||||
t.Fatalf("cookie = %q", got)
|
||||
}
|
||||
_, _ = w.Write([]byte(`<input id="username" name="name" value="alice" data-name="alice" required>`))
|
||||
case "/api/v1/users/alice":
|
||||
if got := r.Header.Get("Authorization"); got != "token gitea-token" {
|
||||
t.Fatalf("authorization = %q", got)
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"id":42,"login":"alice"}`))
|
||||
default:
|
||||
if r.URL.Path != "/user/settings" {
|
||||
t.Fatalf("path = %q", r.URL.Path)
|
||||
}
|
||||
if got := r.Header.Get("Cookie"); got != "i_like_gitea=session" {
|
||||
t.Fatalf("cookie = %q", got)
|
||||
}
|
||||
_, _ = w.Write([]byte(`<meta name="hop-signed-user-id" content="42"><meta name="hop-signed-user-login" content="alice">`))
|
||||
}))
|
||||
defer server.Close()
|
||||
client, err := NewClient(server.URL, "gitea-token")
|
||||
client, err := NewClient(server.URL, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
user, authenticated, err := client.AuthenticatedUser(context.Background(), "i_like_gitea=session")
|
||||
if err != nil || !authenticated || user.ID != 42 {
|
||||
if err != nil || !authenticated || user.ID != 42 || user.LoginName() != "alice" {
|
||||
t.Fatalf("user = %#v, authenticated = %t, err = %v", user, authenticated, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user