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.

82 lines
2.9 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
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 ProofProvider::Keybase::Verifier do
  3. let(:my_domain) { Rails.configuration.x.local_domain }
  4. let(:keybase_proof) do
  5. local_proof = AccountIdentityProof.new(
  6. provider: 'Keybase',
  7. provider_username: 'cryptoalice',
  8. token: '11111111111111111111111111'
  9. )
  10. described_class.new('alice', 'cryptoalice', '11111111111111111111111111', my_domain)
  11. end
  12. let(:query_params) do
  13. "domain=#{my_domain}&kb_username=cryptoalice&sig_hash=11111111111111111111111111&username=alice"
  14. end
  15. describe '#valid?' do
  16. let(:base_url) { 'https://keybase.io/_/api/1.0/sig/proof_valid.json' }
  17. context 'when valid' do
  18. before do
  19. json_response_body = '{"status":{"code":0,"name":"OK"},"proof_valid":true}'
  20. stub_request(:get, "#{base_url}?#{query_params}").to_return(status: 200, body: json_response_body)
  21. end
  22. it 'calls out to keybase and returns true' do
  23. expect(keybase_proof.valid?).to eq true
  24. end
  25. end
  26. context 'when invalid' do
  27. before do
  28. json_response_body = '{"status":{"code":0,"name":"OK"},"proof_valid":false}'
  29. stub_request(:get, "#{base_url}?#{query_params}").to_return(status: 200, body: json_response_body)
  30. end
  31. it 'calls out to keybase and returns false' do
  32. expect(keybase_proof.valid?).to eq false
  33. end
  34. end
  35. context 'with an unexpected api response' do
  36. before do
  37. json_response_body = '{"status":{"code":100,"desc":"wrong size hex_id","fields":{"sig_hash":"wrong size hex_id"},"name":"INPUT_ERROR"}}'
  38. stub_request(:get, "#{base_url}?#{query_params}").to_return(status: 200, body: json_response_body)
  39. end
  40. it 'swallows the error and returns false' do
  41. expect(keybase_proof.valid?).to eq false
  42. end
  43. end
  44. end
  45. describe '#status' do
  46. let(:base_url) { 'https://keybase.io/_/api/1.0/sig/proof_live.json' }
  47. context 'with a normal response' do
  48. before do
  49. json_response_body = '{"status":{"code":0,"name":"OK"},"proof_live":false,"proof_valid":true}'
  50. stub_request(:get, "#{base_url}?#{query_params}").to_return(status: 200, body: json_response_body)
  51. end
  52. it 'calls out to keybase and returns the status fields as proof_valid and proof_live' do
  53. expect(keybase_proof.status).to include({ 'proof_valid' => true, 'proof_live' => false })
  54. end
  55. end
  56. context 'with an unexpected keybase response' do
  57. before do
  58. json_response_body = '{"status":{"code":100,"desc":"missing non-optional field sig_hash","fields":{"sig_hash":"missing non-optional field sig_hash"},"name":"INPUT_ERROR"}}'
  59. stub_request(:get, "#{base_url}?#{query_params}").to_return(status: 200, body: json_response_body)
  60. end
  61. it 'raises a ProofProvider::Keybase::UnexpectedResponseError' do
  62. expect { keybase_proof.status }.to raise_error ProofProvider::Keybase::UnexpectedResponseError
  63. end
  64. end
  65. end
  66. end