about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/webfinger_resource_spec.rb88
1 files changed, 88 insertions, 0 deletions
diff --git a/spec/lib/webfinger_resource_spec.rb b/spec/lib/webfinger_resource_spec.rb
new file mode 100644
index 000000000..6c9a5ff2c
--- /dev/null
+++ b/spec/lib/webfinger_resource_spec.rb
@@ -0,0 +1,88 @@
+require 'rails_helper'
+
+describe WebfingerResource do
+  describe '#username' do
+    describe 'with a URL value' do
+      it 'raises with an unrecognized route' do
+        resource = 'https://example.com/users/alice/other'
+
+        expect {
+          WebfingerResource.new(resource).username
+        }.to raise_error(ActiveRecord::RecordNotFound)
+      end
+
+      it 'raises with a string that doesnt start with URL' do
+        resource = 'website for http://example.com/users/alice/other'
+
+        expect {
+          WebfingerResource.new(resource).username
+        }.to raise_error(ActiveRecord::RecordNotFound)
+      end
+
+      it 'finds the username in a valid https route' do
+        resource = 'https://example.com/users/alice'
+
+        result = WebfingerResource.new(resource).username
+        expect(result).to eq 'alice'
+      end
+
+      it 'finds the username in a mixed case http route' do
+        resource = 'HTTp://exAMPLEe.com/users/alice'
+
+        result = WebfingerResource.new(resource).username
+        expect(result).to eq 'alice'
+      end
+
+      it 'finds the username in a valid http route' do
+        resource = 'http://example.com/users/alice'
+
+        result = WebfingerResource.new(resource).username
+        expect(result).to eq 'alice'
+      end
+    end
+
+    describe 'with a username and hostname value' do
+      it 'raises on a non-local domain' do
+        resource = 'user@remote-host.com'
+
+        expect {
+          WebfingerResource.new(resource).username
+        }.to raise_error(ActiveRecord::RecordNotFound)
+      end
+
+      it 'finds username for a local domain' do
+        Rails.configuration.x.local_domain = 'example.com'
+        resource = 'alice@example.com'
+
+        result = WebfingerResource.new(resource).username
+        expect(result).to eq 'alice'
+      end
+    end
+
+    describe 'with an acct value' do
+      it 'raises on a non-local domain' do
+        resource = 'acct:user@remote-host.com'
+
+        expect {
+          WebfingerResource.new(resource).username
+        }.to raise_error(ActiveRecord::RecordNotFound)
+      end
+
+      it 'raises on a nonsense domain' do
+        resource = 'acct:user@remote-host@remote-hostess.remote.local@remote'
+
+        expect {
+          WebfingerResource.new(resource).username
+        }.to raise_error(ActiveRecord::RecordNotFound)
+      end
+
+      it 'finds the username for a local account' do
+        Rails.configuration.x.local_domain = 'example.com'
+        resource = 'acct:alice@example.com'
+
+        result = WebfingerResource.new(resource).username
+        expect(result).to eq 'alice'
+      end
+    end
+  end
+end