feat: refresh settings, sync account avatars and link account management

This commit is contained in:
SantaSpeen committed 2026-10-22 12:52:37 +03:00
1 parent fa1832dfa7
commit d3d164910b
22 files changed
+789 -407

No files matched your search

+18 -1
View File
@@ -1,12 +1,15 @@
package fbhttp
import (
"bytes"
"context"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"image"
"image/png"
"net/http"
"net/http/httptest"
"net/url"
@@ -23,6 +26,10 @@ import (
)
func TestOIDCSessionLifecycle(t *testing.T) {
var avatarPNG bytes.Buffer
if err := png.Encode(&avatarPNG, image.NewRGBA(image.Rect(0, 0, 16, 16))); err != nil {
t.Fatal(err)
}
key, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
t.Fatal(err)
@@ -68,7 +75,10 @@ func TestOIDCSessionLifecycle(t *testing.T) {
if r.Header.Get("Authorization") != "Bearer access" {
t.Error("missing UserInfo bearer")
}
_ = json.NewEncoder(w).Encode(ssoClaims{Subject: profileSubject, Username: "alice", Name: "Alice Example", Email: "alice@example.test", Roles: []string{"User"}})
_ = json.NewEncoder(w).Encode(ssoClaims{Subject: profileSubject, Username: "alice", Name: "Alice Example", Email: "alice@example.test", Picture: issuer + "/avatars/alice.png", Roles: []string{"User"}})
case "/avatars/alice.png":
w.Header().Set("Content-Type", "image/png")
_, _ = w.Write(avatarPNG.Bytes())
default:
w.WriteHeader(404)
}
@@ -126,6 +136,13 @@ func TestOIDCSessionLifecycle(t *testing.T) {
if !strings.Contains(check.Body.String(), `"username":"alice"`) || !strings.Contains(check.Body.String(), `"email":"alice@example.test"`) {
t.Fatalf("UserInfo profile not loaded: %s", check.Body.String())
}
if !strings.Contains(check.Body.String(), `"picture":"data:image/png;base64,`) {
t.Fatalf("avatar missing from session: %s", check.Body.String())
}
account := request("GET", "/auth/account")
if account.Code != http.StatusFound || account.Header().Get("Location") != issuer+"/settings" {
t.Fatalf("account redirect: %d %s", account.Code, account.Header().Get("Location"))
}
// Repeated logins after changing preferences retain one local identity.
var firstID uint
for i := 0; i < 3; i++ {