diff --git a/app/controllers/well_known/node_info_controller.rb b/app/controllers/well_known/node_info_controller.rb deleted file mode 100644 index c4031c69..00000000 --- a/app/controllers/well_known/node_info_controller.rb +++ /dev/null @@ -1,54 +0,0 @@ -# frozen_string_literal: true - -class WellKnown::NodeInfoController < ApplicationController - def discovery - expires_in 3.days, public: true - - render json: { - links: [ - rel: "http://nodeinfo.diaspora.software/ns/schema/2.1", - href: node_info_url - ], - } - end - - def nodeinfo - expires_in 30.minutes, public: true - - render json: { - version: "2.1", - software: software_info, - protocols: %i[], - services: { - inbound: inbound_services, - outbound: outbound_services, - }, - usage: usage_stats, - # We don't implement this so we can always return true for now - openRegistrations: true, - metadata: {}, - } - end - - private - - def software_info - { - name: "Retrospring", - version: Retrospring::Version.to_s, - repository: "https://github.com/Retrospring/retrospring", - } - end - - def usage_stats - { - users: { - total: User.count, - }, - } - end - - def inbound_services = [] - - def outbound_services = [] -end diff --git a/config/routes.rb b/config/routes.rb index 9790212f..856d34af 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -177,11 +177,8 @@ Rails.application.routes.draw do namespace :well_known, path: "/.well-known" do get "/change-password", to: redirect("/settings/account") - get "/nodeinfo", to: "node_info#discovery" end - get "/nodeinfo/2.1", to: "well_known/node_info#nodeinfo", as: :node_info - get "/modal/close", to: "modal#close", as: :modal_close puts "processing time of routes.rb: #{"#{(Time.zone.now - start).round(3).to_s.ljust(5, '0')}s".light_green}" diff --git a/spec/controllers/well_known/node_info_controller_spec.rb b/spec/controllers/well_known/node_info_controller_spec.rb deleted file mode 100644 index 54d871aa..00000000 --- a/spec/controllers/well_known/node_info_controller_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -describe WellKnown::NodeInfoController do - describe "#discovery" do - subject { get :discovery } - - it "returns the expected response" do - subject - parsed = JSON.parse(response.body) - expect(parsed).to eq({ - "links" => [ - { - "rel" => "http://nodeinfo.diaspora.software/ns/schema/2.1", - "href" => "http://test.host/nodeinfo/2.1", - } - ], - }) - end - end - - describe "#nodeinfo" do - subject { get :nodeinfo } - - it "is valid as specified by the schema" do - get(:discovery) - schema = response.body - subject - parsed = JSON.parse(response.body) - messages = JSON::Validator.fully_validate(schema, parsed) - - expect(messages).to be_empty - end - - context "version is 2023.0102.1" do - before do - allow(Retrospring::Version).to receive(:to_s).and_return("2023.0102.1") - end - - it "returns the correct version" do - subject - parsed = JSON.parse(response.body) - expect(parsed["software"]).to eq({ - "name" => "Retrospring", - "version" => "2023.0102.1", - "repository" => "https://github.com/Retrospring/retrospring", - }) - end - end - - context "site has users" do - let(:num_users) { rand(10..50) } - - before do - FactoryBot.create_list(:user, num_users) - end - - it "includes the correct user count" do - subject - parsed = JSON.parse(response.body) - expect(parsed.dig("usage", "users", "total")).to eq(num_users) - end - end - end -end