Add avatar URL to Webfinger when available
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
2025-05-14 15:39:50 +04:00
parent 417e346074
commit a098ea43bb
3 changed files with 63 additions and 2 deletions

View File

@@ -18,6 +18,46 @@ RSpec.describe "WebFinger", type: :request do
})
end
describe "Avatar" do
context "not available" do
it "does not include an avatar link" do
get "/.well-known/webfinger?resource=acct%3Atony%40kosmos.org"
expect(response).to have_http_status(:ok)
res = JSON.parse(response.body)
link = res["links"].find{|l| l["rel"] == "http://webfinger.net/rel/avatar"}
expect(link).to be_nil
end
end
context "available" do
let(:fixture_path) { Rails.root.join("spec/fixtures/files/taipei.jpg") }
let(:img_data) { File.read(fixture_path) }
let(:img_hash) { Digest::SHA256.hexdigest(img_data) }
before do
ActiveStorage::Blob.create_and_upload!(
io: File.open(fixture_path),
filename: "#{img_hash}.jpg",
content_type: "image/jpeg"
).tap do |blob|
user.avatar.attach(blob)
end
end
it "includes a public avatar link" do
get "/.well-known/webfinger?resource=acct%3Atony%40kosmos.org"
expect(response).to have_http_status(:ok)
res = JSON.parse(response.body)
link = res["links"].find { |l| l["rel"] == "http://webfinger.net/rel/avatar" }
expect(link).to be_present
expect(link["type"]).to eq("image/jpeg")
expect(link["href"]).to match(%r{users/tony/avatars/#{img_hash}.jpg})
end
end
end
describe "Mastodon entries" do
context "Mastodon available" do
it "includes the Mastodon aliases and links for the user" do