external_credential.rb 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. FactoryBot.define do
  3. factory :external_credential do
  4. factory :facebook_credential do
  5. name { 'facebook' }
  6. credentials { { application_id: 123, application_secret: 123 } }
  7. end
  8. factory :twitter_credential do
  9. name { 'twitter' }
  10. credentials do
  11. {
  12. consumer_key: consumer_key,
  13. consumer_secret: consumer_secret,
  14. oauth_token: oauth_token,
  15. oauth_token_secret: oauth_token_secret,
  16. env: 'zammad',
  17. controller: 'external_credentials',
  18. action: 'app_verify',
  19. provider: 'twitter',
  20. webhook_id: Faker::Number.unique.number(digits: 19),
  21. }
  22. end
  23. # When recording a new VCR cassette,
  24. # Twitter API tests need valid credentials--
  25. # but storing them in this file is a security no-no.
  26. #
  27. # Instead, store your twitter API credentials in env vars to utilize this factory.
  28. # (Try https://github.com/direnv/direnv to set env vars automatically.)
  29. transient do
  30. consumer_key { ENV.fetch('TWITTER_CONSUMER_KEY') { 'REDACTED' } }
  31. consumer_secret { ENV.fetch('TWITTER_CONSUMER_SECRET') { 'REDACTED' } }
  32. oauth_token { ENV.fetch('TWITTER_OAUTH_TOKEN') { 'REDACTED' } }
  33. oauth_token_secret { ENV.fetch('TWITTER_OAUTH_TOKEN_SECRET') { 'REDACTED' } }
  34. end
  35. trait :invalid do
  36. # If these credentials are fake/invalid,
  37. # why don't we use Faker to generate them dynamically?
  38. #
  39. # Our Twitter API tests use VCR to cache HTTP traffic.
  40. # If the values change each time you run the test,
  41. # VCR gets confused and raises errors.
  42. transient do
  43. consumer_key { 'q7K8GEkhyCHs9jHLtkmD9Kod4' }
  44. consumer_secret { 'LIDrpO6lRukO0PSicv00x9n8qMPvqvMq9mNInsby5sIkwN2J81' }
  45. oauth_token { '7783712304-H9s75r2d532diPmJYK6JrvUWxu9gTDZ6ocjfToL' }
  46. oauth_token_secret { 'XFhmXR1J17zaI3bEikHKG5zNUVHVnjpzPuQc0vNmb4z2y' }
  47. end
  48. end
  49. end
  50. factory :sms_message_bird_credential do
  51. name { 'message_bird' }
  52. credentials { { token: Faker::Alphanumeric.alphanumeric(number: 25) } }
  53. end
  54. factory :telegram_credential do
  55. name { 'telegram' }
  56. credentials { { api_token: "#{Faker::Alphanumeric.alphanumeric(number: 7)}-#{Faker::Alphanumeric.alphanumeric(number: 13)}_#{Faker::Alphanumeric.alphanumeric(number: 7)}_#{Faker::Alphanumeric.alphanumeric(number: 5)}" } }
  57. end
  58. factory :microsoft_graph_credential do
  59. name { 'microsoft_graph' }
  60. transient do
  61. client_id { SecureRandom.uuid }
  62. client_secret { SecureRandom.urlsafe_base64(40) }
  63. client_tenant { SecureRandom.uuid }
  64. end
  65. credentials do
  66. {
  67. 'client_id' => client_id,
  68. 'client_secret' => client_secret,
  69. 'client_tenant' => client_tenant,
  70. 'controller' => 'external_credentials',
  71. 'action' => 'app_verify',
  72. 'provider' => 'microsoft_graph',
  73. }
  74. end
  75. end
  76. factory :microsoft365_credential do
  77. name { 'microsoft365' }
  78. transient do
  79. client_id { SecureRandom.uuid }
  80. client_secret { SecureRandom.urlsafe_base64(40) }
  81. client_tenant { SecureRandom.uuid }
  82. end
  83. credentials do
  84. {
  85. 'client_id' => client_id,
  86. 'client_secret' => client_secret,
  87. 'client_tenant' => client_tenant,
  88. 'controller' => 'external_credentials',
  89. 'action' => 'app_verify',
  90. 'provider' => 'microsoft365',
  91. }
  92. end
  93. end
  94. factory :google_credential do
  95. name { 'google' }
  96. transient do
  97. client_id { SecureRandom.uuid }
  98. client_secret { SecureRandom.urlsafe_base64(40) }
  99. end
  100. credentials do
  101. {
  102. 'client_id' => client_id,
  103. 'client_secret' => client_secret,
  104. 'controller' => 'external_credentials',
  105. 'action' => 'app_verify',
  106. 'provider' => 'google',
  107. }
  108. end
  109. end
  110. end
  111. end