You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
4.2 KiB

Add Keybase integration (#10297) * create account_identity_proofs table * add endpoint for keybase to check local proofs * add async task to update validity and liveness of proofs from keybase * first pass keybase proof CRUD * second pass keybase proof creation * clean up proof list and add badges * add avatar url to keybase api * Always highlight the “Identity Proofs” navigation item when interacting with proofs. * Update translations. * Add profile URL. * Reorder proofs. * Add proofs to bio. * Update settings/identity_proofs front-end. * Use `link_to`. * Only encode query params if they exist. URLs without params had a trailing `?`. * Only show live proofs. * change valid to active in proof list and update liveness before displaying * minor fixes * add keybase config at well-known path * extremely naive feature flagging off the identity proof UI * fixes for rubocop * make identity proofs page resilient to potential keybase issues * normalize i18n * tweaks for brakeman * remove two unused translations * cleanup and add more localizations * make keybase_contacts an admin setting * fix ExternalProofService my_domain * use Addressable::URI in identity proofs * use active model serializer for keybase proof config * more cleanup of keybase proof config * rename proof is_valid and is_live to proof_valid and proof_live * cleanup * assorted tweaks for more robust communication with keybase * Clean up * Small fixes * Display verified identity identically to verified links * Clean up unused CSS * Add caching for Keybase avatar URLs * Remove keybase_contacts setting
5 years ago
  1. require 'rails_helper'
  2. describe Api::ProofsController do
  3. let(:alice) { Fabricate(:account, username: 'alice') }
  4. before do
  5. stub_request(:get, 'https://keybase.io/_/api/1.0/sig/proof_valid.json?domain=cb6e6126.ngrok.io&kb_username=crypto_alice&sig_hash=111111111111111111111111111111111111111111111111111111111111111111&username=alice').to_return(status: 200, body: '{"proof_valid":true,"proof_live":false}')
  6. stub_request(:get, 'https://keybase.io/_/api/1.0/sig/proof_live.json?domain=cb6e6126.ngrok.io&kb_username=crypto_alice&sig_hash=111111111111111111111111111111111111111111111111111111111111111111&username=alice').to_return(status: 200, body: '{"proof_valid":true,"proof_live":true}')
  7. stub_request(:get, 'https://keybase.io/_/api/1.0/sig/proof_valid.json?domain=cb6e6126.ngrok.io&kb_username=hidden_alice&sig_hash=222222222222222222222222222222222222222222222222222222222222222222&username=alice').to_return(status: 200, body: '{"proof_valid":true,"proof_live":true}')
  8. stub_request(:get, 'https://keybase.io/_/api/1.0/sig/proof_live.json?domain=cb6e6126.ngrok.io&kb_username=hidden_alice&sig_hash=222222222222222222222222222222222222222222222222222222222222222222&username=alice').to_return(status: 200, body: '{"proof_valid":true,"proof_live":true}')
  9. end
  10. describe 'GET #index' do
  11. describe 'with a non-existent username' do
  12. it '404s' do
  13. get :index, params: { username: 'nonexistent', provider: 'keybase' }
  14. expect(response).to have_http_status(:not_found)
  15. end
  16. end
  17. describe 'with a user that has no proofs' do
  18. it 'is an empty list of signatures' do
  19. get :index, params: { username: alice.username, provider: 'keybase' }
  20. expect(body_as_json[:signatures]).to eq []
  21. end
  22. end
  23. describe 'with a user that has a live, valid proof' do
  24. let(:token1) { '111111111111111111111111111111111111111111111111111111111111111111' }
  25. let(:kb_name1) { 'crypto_alice' }
  26. before do
  27. Fabricate(:account_identity_proof, account: alice, verified: true, live: true, token: token1, provider_username: kb_name1)
  28. end
  29. it 'is a list with that proof in it' do
  30. get :index, params: { username: alice.username, provider: 'keybase' }
  31. expect(body_as_json[:signatures]).to eq [
  32. { kb_username: kb_name1, sig_hash: token1 },
  33. ]
  34. end
  35. describe 'add one that is neither live nor valid' do
  36. let(:token2) { '222222222222222222222222222222222222222222222222222222222222222222' }
  37. let(:kb_name2) { 'hidden_alice' }
  38. before do
  39. Fabricate(:account_identity_proof, account: alice, verified: false, live: false, token: token2, provider_username: kb_name2)
  40. end
  41. it 'is a list with both proofs' do
  42. get :index, params: { username: alice.username, provider: 'keybase' }
  43. expect(body_as_json[:signatures]).to eq [
  44. { kb_username: kb_name1, sig_hash: token1 },
  45. { kb_username: kb_name2, sig_hash: token2 },
  46. ]
  47. end
  48. end
  49. end
  50. describe 'a user that has an avatar' do
  51. let(:alice) { Fabricate(:account, username: 'alice', avatar: attachment_fixture('avatar.gif')) }
  52. context 'and a proof' do
  53. let(:token1) { '111111111111111111111111111111111111111111111111111111111111111111' }
  54. let(:kb_name1) { 'crypto_alice' }
  55. before do
  56. Fabricate(:account_identity_proof, account: alice, verified: true, live: true, token: token1, provider_username: kb_name1)
  57. get :index, params: { username: alice.username, provider: 'keybase' }
  58. end
  59. it 'has two keys: signatures and avatar' do
  60. expect(body_as_json.keys).to match_array [:signatures, :avatar]
  61. end
  62. it 'has the correct signatures' do
  63. expect(body_as_json[:signatures]).to eq [
  64. { kb_username: kb_name1, sig_hash: token1 },
  65. ]
  66. end
  67. it 'has the correct avatar url' do
  68. first_part = 'https://cb6e6126.ngrok.io/system/accounts/avatars/'
  69. last_part = 'original/avatar.gif'
  70. expect(body_as_json[:avatar]).to match /#{Regexp.quote(first_part)}(?:\d{3,5}\/){3}#{Regexp.quote(last_part)}/
  71. end
  72. end
  73. end
  74. end
  75. end