about summary refs log tree commit diff
path: root/spec/lib
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/activitypub/linked_data_signature_spec.rb4
-rw-r--r--spec/lib/formatter_spec.rb6
-rw-r--r--spec/lib/ostatus/atom_serializer_spec.rb32
-rw-r--r--spec/lib/provider_discovery_spec.rb118
-rw-r--r--spec/lib/tag_manager_spec.rb34
5 files changed, 37 insertions, 157 deletions
diff --git a/spec/lib/activitypub/linked_data_signature_spec.rb b/spec/lib/activitypub/linked_data_signature_spec.rb
index a4d6fe8c3..1f413eec9 100644
--- a/spec/lib/activitypub/linked_data_signature_spec.rb
+++ b/spec/lib/activitypub/linked_data_signature_spec.rb
@@ -16,6 +16,10 @@ RSpec.describe ActivityPub::LinkedDataSignature do
 
   subject { described_class.new(json) }
 
+  before do
+    stub_jsonld_contexts!
+  end
+
   describe '#verify_account!' do
     context 'when signature matches' do
       let(:raw_signature) do
diff --git a/spec/lib/formatter_spec.rb b/spec/lib/formatter_spec.rb
index 6e849f379..b8683e720 100644
--- a/spec/lib/formatter_spec.rb
+++ b/spec/lib/formatter_spec.rb
@@ -2,7 +2,7 @@ require 'rails_helper'
 
 RSpec.describe Formatter do
   let(:local_account)  { Fabricate(:account, domain: nil, username: 'alice') }
-  let(:remote_account) { Fabricate(:account, domain: 'remote', username: 'bob', url: 'https://remote/') }
+  let(:remote_account) { Fabricate(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/') }
 
   shared_examples 'encode and link URLs' do
     context 'matches a stand-alone medium URL' do
@@ -377,12 +377,12 @@ RSpec.describe Formatter do
       end
 
       context 'contains linkable mentions for remote accounts' do
-        let(:text) { '@bob@remote' }
+        let(:text) { '@bob@remote.test' }
 
         before { remote_account }
 
         it 'links' do
-          is_expected.to eq '<p><span class="h-card"><a href="https://remote/" class="u-url mention">@<span>bob</span></a></span></p>'
+          is_expected.to eq '<p><span class="h-card"><a href="https://remote.test/" class="u-url mention">@<span>bob</span></a></span></p>'
         end
       end
 
diff --git a/spec/lib/ostatus/atom_serializer_spec.rb b/spec/lib/ostatus/atom_serializer_spec.rb
index 00e6f09dc..0bd22880e 100644
--- a/spec/lib/ostatus/atom_serializer_spec.rb
+++ b/spec/lib/ostatus/atom_serializer_spec.rb
@@ -30,13 +30,13 @@ RSpec.describe OStatus::AtomSerializer do
     end
 
     it 'appends activity:object with target account' do
-      target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id')
+      target_account = Fabricate(:account, domain: 'domain.test', uri: 'https://domain.test/id')
       follow_request = Fabricate(:follow_request, target_account: target_account)
 
       follow_request_salmon = serialize(follow_request)
 
       object = follow_request_salmon.nodes.find { |node| node.name == 'activity:object' }
-      expect(object.id.text).to eq 'https://domain/id'
+      expect(object.id.text).to eq 'https://domain.test/id'
     end
   end
 
@@ -386,12 +386,6 @@ RSpec.describe OStatus::AtomSerializer do
         expect(entry.category[:term]).to eq 'tag'
       end
 
-      it 'appends category element for NSFW if status is sensitive' do
-        status = Fabricate(:status, sensitive: true)
-        entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
-        expect(entry.category[:term]).to eq 'nsfw'
-      end
-
       it 'appends link elements for media attachments' do
         file = attachment_fixture('attachment.jpg')
         media_attachment = Fabricate(:media_attachment, file: file)
@@ -419,20 +413,20 @@ RSpec.describe OStatus::AtomSerializer do
 
         entry = OStatus::AtomSerializer.new.entry(remote_status.stream_entry, true)
         entry.nodes.delete_if { |node| node[:type] == 'application/activity+json' } # Remove ActivityPub link to simplify test
-        xml = OStatus::AtomSerializer.render(entry).gsub('cb6e6126.ngrok.io', 'remote')
+        xml = OStatus::AtomSerializer.render(entry).gsub('cb6e6126.ngrok.io', 'remote.test')
 
         remote_status.destroy!
         remote_account.destroy!
 
         account = Account.create!(
-          domain: 'remote',
+          domain: 'remote.test',
           username: 'username',
           last_webfingered_at: Time.now.utc
         )
 
         ProcessFeedService.new.call(xml, account)
 
-        expect(Status.find_by(uri: "https://remote/users/#{remote_status.account.to_param}/statuses/#{remote_status.id}")).to be_instance_of Status
+        expect(Status.find_by(uri: "https://remote.test/users/#{remote_status.account.to_param}/statuses/#{remote_status.id}")).to be_instance_of Status
       end
     end
 
@@ -782,13 +776,13 @@ RSpec.describe OStatus::AtomSerializer do
     end
 
     it 'appends activity:object element with target account' do
-      target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id')
+      target_account = Fabricate(:account, domain: 'domain.test', uri: 'https://domain.test/id')
       block = Fabricate(:block, target_account: target_account)
 
       block_salmon = OStatus::AtomSerializer.new.block_salmon(block)
 
       object = block_salmon.nodes.find { |node| node.name == 'activity:object' }
-      expect(object.id.text).to eq 'https://domain/id'
+      expect(object.id.text).to eq 'https://domain.test/id'
     end
 
     it 'returns element whose rendered view triggers block when processed' do
@@ -869,13 +863,13 @@ RSpec.describe OStatus::AtomSerializer do
     end
 
     it 'appends activity:object element with target account' do
-      target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id')
+      target_account = Fabricate(:account, domain: 'domain.test', uri: 'https://domain.test/id')
       block = Fabricate(:block, target_account: target_account)
 
       unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block)
 
       object = unblock_salmon.nodes.find { |node| node.name == 'activity:object' }
-      expect(object.id.text).to eq 'https://domain/id'
+      expect(object.id.text).to eq 'https://domain.test/id'
     end
 
     it 'returns element whose rendered view triggers block when processed' do
@@ -1130,13 +1124,13 @@ RSpec.describe OStatus::AtomSerializer do
     end
 
     it 'appends activity:object element with target account' do
-      target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id')
+      target_account = Fabricate(:account, domain: 'domain.test', uri: 'https://domain.test/id')
       follow = Fabricate(:follow, target_account: target_account)
 
       follow_salmon = OStatus::AtomSerializer.new.follow_salmon(follow)
 
       object = follow_salmon.nodes.find { |node| node.name == 'activity:object' }
-      expect(object.id.text).to eq 'https://domain/id'
+      expect(object.id.text).to eq 'https://domain.test/id'
     end
 
     it 'includes description' do
@@ -1248,14 +1242,14 @@ RSpec.describe OStatus::AtomSerializer do
     end
 
     it 'appends activity:object element with target account' do
-      target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id')
+      target_account = Fabricate(:account, domain: 'domain.test', uri: 'https://domain.test/id')
       follow = Fabricate(:follow, target_account: target_account)
       follow.destroy!
 
       unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
 
       object = unfollow_salmon.nodes.find { |node| node.name == 'activity:object' }
-      expect(object.id.text).to eq 'https://domain/id'
+      expect(object.id.text).to eq 'https://domain.test/id'
     end
 
     it 'returns element whose rendered view triggers unfollow when processed' do
diff --git a/spec/lib/provider_discovery_spec.rb b/spec/lib/provider_discovery_spec.rb
deleted file mode 100644
index 12e2616c9..000000000
--- a/spec/lib/provider_discovery_spec.rb
+++ /dev/null
@@ -1,118 +0,0 @@
-# frozen_string_literal: true
-
-require 'rails_helper'
-
-describe ProviderDiscovery do
-  describe 'discover_provider' do
-    context 'when status code is 200 and MIME type is text/html' do
-      context 'Both of JSON and XML provider are discoverable' do
-        before do
-          stub_request(:get, 'https://host/oembed.html').to_return(
-            status: 200,
-            headers: { 'Content-Type': 'text/html' },
-            body: request_fixture('oembed_json_xml.html')
-          )
-        end
-
-        it 'returns new OEmbed::Provider for JSON provider if :format option is set to :json' do
-          provider = ProviderDiscovery.discover_provider('https://host/oembed.html', format: :json)
-          expect(provider.endpoint).to eq 'https://host/provider.json'
-          expect(provider.format).to eq :json
-        end
-
-        it 'returns new OEmbed::Provider for XML provider if :format option is set to :xml' do
-          provider = ProviderDiscovery.discover_provider('https://host/oembed.html', format: :xml)
-          expect(provider.endpoint).to eq 'https://host/provider.xml'
-          expect(provider.format).to eq :xml
-        end
-      end
-
-      context 'JSON provider is discoverable while XML provider is not' do
-        before do
-          stub_request(:get, 'https://host/oembed.html').to_return(
-            status: 200,
-            headers: { 'Content-Type': 'text/html' },
-            body: request_fixture('oembed_json.html')
-          )
-        end
-
-        it 'returns new OEmbed::Provider for JSON provider' do
-          provider = ProviderDiscovery.discover_provider('https://host/oembed.html')
-          expect(provider.endpoint).to eq 'https://host/provider.json'
-          expect(provider.format).to eq :json
-        end
-      end
-
-      context 'XML provider is discoverable while JSON provider is not' do
-        before do
-          stub_request(:get, 'https://host/oembed.html').to_return(
-            status: 200,
-            headers: { 'Content-Type': 'text/html' },
-            body: request_fixture('oembed_xml.html')
-          )
-        end
-
-        it 'returns new OEmbed::Provider for XML provider' do
-          provider = ProviderDiscovery.discover_provider('https://host/oembed.html')
-          expect(provider.endpoint).to eq 'https://host/provider.xml'
-          expect(provider.format).to eq :xml
-        end
-      end
-
-      context 'Invalid XML provider is discoverable while JSON provider is not' do
-        before do
-          stub_request(:get, 'https://host/oembed.html').to_return(
-            status: 200,
-            headers: { 'Content-Type': 'text/html' },
-            body: request_fixture('oembed_invalid_xml.html')
-          )
-        end
-
-        it 'raises OEmbed::NotFound' do
-          expect { ProviderDiscovery.discover_provider('https://host/oembed.html') }.to raise_error OEmbed::NotFound
-        end
-      end
-
-      context 'Neither of JSON and XML provider is discoverable' do
-        before do
-          stub_request(:get, 'https://host/oembed.html').to_return(
-            status: 200,
-            headers: { 'Content-Type': 'text/html' },
-            body: request_fixture('oembed_undiscoverable.html')
-          )
-        end
-
-        it 'raises OEmbed::NotFound' do
-          expect { ProviderDiscovery.discover_provider('https://host/oembed.html') }.to raise_error OEmbed::NotFound
-        end
-      end
-    end
-
-    context 'when status code is not 200' do
-      before do
-        stub_request(:get, 'https://host/oembed.html').to_return(
-          status: 400,
-          headers: { 'Content-Type': 'text/html' },
-          body: request_fixture('oembed_xml.html')
-        )
-      end
-
-      it 'raises OEmbed::NotFound' do
-        expect { ProviderDiscovery.discover_provider('https://host/oembed.html') }.to raise_error OEmbed::NotFound
-      end
-    end
-
-    context 'when MIME type is not text/html' do
-      before do
-        stub_request(:get, 'https://host/oembed.html').to_return(
-          status: 200,
-          body: request_fixture('oembed_xml.html')
-        )
-      end
-
-      it 'raises OEmbed::NotFound' do
-        expect { ProviderDiscovery.discover_provider('https://host/oembed.html') }.to raise_error OEmbed::NotFound
-      end
-    end
-  end
-end
diff --git a/spec/lib/tag_manager_spec.rb b/spec/lib/tag_manager_spec.rb
index 5427a2929..3a804ac0f 100644
--- a/spec/lib/tag_manager_spec.rb
+++ b/spec/lib/tag_manager_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe TagManager do
 
     around do |example|
       original_local_domain = Rails.configuration.x.local_domain
-      Rails.configuration.x.local_domain = 'domain'
+      Rails.configuration.x.local_domain = 'domain.test'
 
       example.run
 
@@ -18,11 +18,11 @@ RSpec.describe TagManager do
     end
 
     it 'returns true if the slash-stripped string equals to local domain' do
-      expect(TagManager.instance.local_domain?('DoMaIn/')).to eq true
+      expect(TagManager.instance.local_domain?('DoMaIn.Test/')).to eq true
     end
 
     it 'returns false for irrelevant string' do
-      expect(TagManager.instance.local_domain?('DoMaIn!')).to eq false
+      expect(TagManager.instance.local_domain?('DoMaIn.Test!')).to eq false
     end
   end
 
@@ -31,7 +31,7 @@ RSpec.describe TagManager do
 
     around do |example|
       original_web_domain = Rails.configuration.x.web_domain
-      Rails.configuration.x.web_domain = 'domain'
+      Rails.configuration.x.web_domain = 'domain.test'
 
       example.run
 
@@ -43,11 +43,11 @@ RSpec.describe TagManager do
     end
 
     it 'returns true if the slash-stripped string equals to web domain' do
-      expect(TagManager.instance.web_domain?('DoMaIn/')).to eq true
+      expect(TagManager.instance.web_domain?('DoMaIn.Test/')).to eq true
     end
 
     it 'returns false for string with irrelevant characters' do
-      expect(TagManager.instance.web_domain?('DoMaIn!')).to eq false
+      expect(TagManager.instance.web_domain?('DoMaIn.Test!')).to eq false
     end
   end
 
@@ -57,7 +57,7 @@ RSpec.describe TagManager do
     end
 
     it 'returns normalized domain' do
-      expect(TagManager.instance.normalize_domain('DoMaIn/')).to eq 'domain'
+      expect(TagManager.instance.normalize_domain('DoMaIn.Test/')).to eq 'domain.test'
     end
   end
 
@@ -69,18 +69,18 @@ RSpec.describe TagManager do
     end
 
     it 'returns true if the normalized string with port is local URL' do
-      Rails.configuration.x.web_domain = 'domain:42'
-      expect(TagManager.instance.local_url?('https://DoMaIn:42/')).to eq true
+      Rails.configuration.x.web_domain = 'domain.test:42'
+      expect(TagManager.instance.local_url?('https://DoMaIn.Test:42/')).to eq true
     end
 
     it 'returns true if the normalized string without port is local URL' do
-      Rails.configuration.x.web_domain = 'domain'
-      expect(TagManager.instance.local_url?('https://DoMaIn/')).to eq true
+      Rails.configuration.x.web_domain = 'domain.test'
+      expect(TagManager.instance.local_url?('https://DoMaIn.Test/')).to eq true
     end
 
     it 'returns false for string with irrelevant characters' do
-      Rails.configuration.x.web_domain = 'domain'
-      expect(TagManager.instance.local_url?('https://domainn/')).to eq false
+      Rails.configuration.x.web_domain = 'domain.test'
+      expect(TagManager.instance.local_url?('https://domainn.test/')).to eq false
     end
   end
 
@@ -88,19 +88,19 @@ RSpec.describe TagManager do
     # The following comparisons MUST be case-insensitive.
 
     it 'returns true if the needle has a correct username and domain for remote user' do
-      expect(TagManager.instance.same_acct?('username@domain', 'UsErNaMe@DoMaIn')).to eq true
+      expect(TagManager.instance.same_acct?('username@domain.test', 'UsErNaMe@DoMaIn.Test')).to eq true
     end
 
     it 'returns false if the needle is missing a domain for remote user' do
-      expect(TagManager.instance.same_acct?('username@domain', 'UsErNaMe')).to eq false
+      expect(TagManager.instance.same_acct?('username@domain.test', 'UsErNaMe')).to eq false
     end
 
     it 'returns false if the needle has an incorrect domain for remote user' do
-      expect(TagManager.instance.same_acct?('username@domain', 'UsErNaMe@incorrect')).to eq false
+      expect(TagManager.instance.same_acct?('username@domain.test', 'UsErNaMe@incorrect.test')).to eq false
     end
 
     it 'returns false if the needle has an incorrect username for remote user' do
-      expect(TagManager.instance.same_acct?('username@domain', 'incorrect@DoMaIn')).to eq false
+      expect(TagManager.instance.same_acct?('username@domain.test', 'incorrect@DoMaIn.test')).to eq false
     end
 
     it 'returns true if the needle has a correct username and domain for local user' do