Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Webfinger working for users, models, collections, and creators #2508

Merged
merged 5 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ GIT

GIT
remote: https://gitlab.com/manyfold3d/federails.git
revision: 631de8856448ab375e8115940e90f1381cf8db38
revision: 59e9bc0b0a417cce714e7f99392f010582242103
branch: polymorphic_actor_relationship
specs:
federails (0.0.1)
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/followable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module Followable
include FederailsCommon

included do
acts_as_federails_actor username_field: :id, name_field: :name, profile_url_method: :url_for
delegate :following_followers, to: :actor

after_create :post_creation_activity
end

Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/follower.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Follower
include FederailsCommon

included do
acts_as_federails_actor username_field: :username, name_field: :name
delegate :activities, to: :actor
delegate :following_follows, to: :actor
end
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Application < Rails::Application
}.compact

# Load some feature settings from ENV
# Some are automatically enabled in test mode because they impact initialization
config.manyfold_features = {
multiuser: (ENV.fetch("MULTIUSER", nil) == "enabled"),
federation: (ENV.fetch("FEDERATION", nil) == "enabled"),
Expand Down
7 changes: 1 addition & 6 deletions config/initializers/federails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
conf.site_port = Rails.application.default_url_options[:port]
conf.force_ssl = Rails.application.config.force_ssl

conf.enable_discovery = Rails.application.config.manyfold_features[:federation]
conf.enable_discovery = Rails.application.config.manyfold_features[:federation] || Rails.env.test?
conf.server_routes_path = "federation"
conf.client_routes_path = "client"

conf.user_class = "::User"
conf.user_profile_url_method = nil
conf.user_name_field = "name"
conf.user_username_field = "username"
end
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
resources :activity
end

mount Federails::Engine => "/" if Rails.application.config.manyfold_features[:multiuser]
mount Federails::Engine => "/" if SiteSettings.multiuser_enabled? || Rails.env.test?

resources :users, only: [] do
resource :settings, only: [:show, :update]
Expand All @@ -36,7 +36,7 @@
end

concern :followable do |options|
if Rails.application.config.manyfold_features[:multiuser]
if SiteSettings.multiuser_enabled?
resources :follows, {only: [:create]}.merge(options) do
collection do
delete "/", action: "destroy"
Expand Down
67 changes: 67 additions & 0 deletions spec/requests/webfinger_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require "rails_helper"

RSpec.describe "Webfinger", :multiuser do
context "when looking up a user by federation URL" do
let(:user) { create(:user) }

before do
get("/.well-known/webfinger?resource=#{user.actor.federated_url}")
end

it "returns a successful response" do
expect(response).to have_http_status :success
end

it "responds with data on the correct user" do
expect(response.parsed_body["links"][0]["href"]).to eq user.actor.federated_url
end
end

context "when looking up a user by at_address" do
let(:user) { create(:user) }

before do
get("/.well-known/webfinger?resource=acct:#{user.actor.at_address}")
end

it "returns a successful response" do
expect(response).to have_http_status :success
end

it "responds with data on the correct user" do
expect(response.parsed_body["links"][0]["href"]).to eq user.actor.federated_url
end
end

context "when looking up a non-existent user" do
let(:user) { create(:user) }

before do
get("/.well-known/webfinger?resource=#{user.actor.federated_url}9999")
end

it "returns a not found response"
end

[
:collection,
:creator,
:model
].each do |followable|
context "when looking up a #{followable}" do
let(:object) { create(followable) }

before do
get("/.well-known/webfinger?resource=#{object.actor.federated_url}")
end

it "returns a successful response" do
expect(response).to have_http_status :success
end

it "responds with data on the correct #{followable}" do
expect(response.parsed_body["links"][0]["href"]).to eq object.actor.federated_url
end
end
end
end
Loading