webfinger_resource_spec.rb 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. require 'rails_helper'
  2. describe WebfingerResource do
  3. around do |example|
  4. before = Rails.configuration.x.local_domain
  5. example.run
  6. Rails.configuration.x.local_domain = before
  7. end
  8. describe '#username' do
  9. describe 'with a URL value' do
  10. it 'raises with an unrecognized route' do
  11. resource = 'https://example.com/users/alice/other'
  12. expect {
  13. WebfingerResource.new(resource).username
  14. }.to raise_error(ActiveRecord::RecordNotFound)
  15. end
  16. it 'raises with a string that doesnt start with URL' do
  17. resource = 'website for http://example.com/users/alice/other'
  18. expect {
  19. WebfingerResource.new(resource).username
  20. }.to raise_error(ActiveRecord::RecordNotFound)
  21. end
  22. it 'finds the username in a valid https route' do
  23. resource = 'https://example.com/users/alice'
  24. result = WebfingerResource.new(resource).username
  25. expect(result).to eq 'alice'
  26. end
  27. it 'finds the username in a mixed case http route' do
  28. resource = 'HTTp://exAMPLEe.com/users/alice'
  29. result = WebfingerResource.new(resource).username
  30. expect(result).to eq 'alice'
  31. end
  32. it 'finds the username in a valid http route' do
  33. resource = 'http://example.com/users/alice'
  34. result = WebfingerResource.new(resource).username
  35. expect(result).to eq 'alice'
  36. end
  37. end
  38. describe 'with a username and hostname value' do
  39. it 'raises on a non-local domain' do
  40. resource = 'user@remote-host.com'
  41. expect {
  42. WebfingerResource.new(resource).username
  43. }.to raise_error(ActiveRecord::RecordNotFound)
  44. end
  45. it 'finds username for a local domain' do
  46. Rails.configuration.x.local_domain = 'example.com'
  47. resource = 'alice@example.com'
  48. result = WebfingerResource.new(resource).username
  49. expect(result).to eq 'alice'
  50. end
  51. end
  52. describe 'with an acct value' do
  53. it 'raises on a non-local domain' do
  54. resource = 'acct:user@remote-host.com'
  55. expect {
  56. WebfingerResource.new(resource).username
  57. }.to raise_error(ActiveRecord::RecordNotFound)
  58. end
  59. it 'raises on a nonsense domain' do
  60. resource = 'acct:user@remote-host@remote-hostess.remote.local@remote'
  61. expect {
  62. WebfingerResource.new(resource).username
  63. }.to raise_error(ActiveRecord::RecordNotFound)
  64. end
  65. it 'finds the username for a local account' do
  66. Rails.configuration.x.local_domain = 'example.com'
  67. resource = 'acct:alice@example.com'
  68. result = WebfingerResource.new(resource).username
  69. expect(result).to eq 'alice'
  70. end
  71. end
  72. end
  73. end