authenticators.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import type {
  2. RecoveryAuthenticator,
  3. SmsAuthenticator,
  4. TotpAuthenticator,
  5. U2fAuthenticator,
  6. UserEnrolledAuthenticator,
  7. } from 'sentry/types';
  8. export function AuthenticatorsFixture(): {
  9. Recovery: (props?: Partial<RecoveryAuthenticator>) => RecoveryAuthenticator;
  10. Sms: (props?: Partial<SmsAuthenticator>) => SmsAuthenticator;
  11. Totp: (props?: Partial<TotpAuthenticator>) => TotpAuthenticator;
  12. U2f: (props?: Partial<U2fAuthenticator>) => U2fAuthenticator;
  13. } {
  14. return {
  15. Totp: (p = {}) => ({
  16. lastUsedAt: null,
  17. enrollButton: 'Enroll',
  18. description:
  19. 'An authenticator application that supports TOTP (like Google Authenticator or 1Password) can be used to conveniently secure your account. A new token is generated every 30 seconds.',
  20. isEnrolled: true,
  21. removeButton: 'Remove',
  22. id: 'totp',
  23. createdAt: '2018-01-30T17:24:36.554Z',
  24. configureButton: 'Info',
  25. name: 'Authenticator App',
  26. allowMultiEnrollment: false,
  27. disallowNewEnrollment: false,
  28. authId: '15',
  29. canValidateOtp: true,
  30. isBackupInterface: false,
  31. allowRotationInPlace: false,
  32. authenticatorDevice: [],
  33. devices: [],
  34. rotationWarning: null,
  35. status: 'active',
  36. codes: ['123-456'],
  37. qrcode: 'qr-code',
  38. ...p,
  39. }),
  40. Sms: (p = {}) => ({
  41. createdAt: '2018-01-30T17:24:36.554Z',
  42. lastUsedAt: null,
  43. enrollButton: 'Enroll',
  44. name: 'Text Message',
  45. allowMultiEnrollment: false,
  46. removeButton: 'Remove',
  47. canValidateOtp: true,
  48. isEnrolled: false,
  49. configureButton: 'Info',
  50. id: 'sms',
  51. isBackupInterface: false,
  52. disallowNewEnrollment: false,
  53. allowRotationInPlace: false,
  54. authenticatorDevice: [],
  55. devices: [],
  56. rotationWarning: null,
  57. status: 'active',
  58. codes: ['123-456'],
  59. qrcode: 'qr-code',
  60. description:
  61. "This authenticator sends you text messages for verification. It's useful as a backup method or when you do not have a phone that supports an authenticator application.",
  62. ...p,
  63. }),
  64. U2f: (p = {}) => ({
  65. lastUsedAt: null,
  66. enrollButton: 'Enroll',
  67. description:
  68. "Authenticate with a U2F hardware device. This is a device like a Yubikey or something similar which supports FIDO's U2F specification. This also requires a browser which supports this system (like Google Chrome).",
  69. isEnrolled: true,
  70. removeButton: 'Remove',
  71. id: 'u2f',
  72. createdAt: '2018-01-30T20:56:45.932Z',
  73. configureButton: 'Configure',
  74. name: 'U2F (Universal 2nd Factor)',
  75. allowMultiEnrollment: true,
  76. disallowNewEnrollment: false,
  77. authId: '23',
  78. canValidateOtp: false,
  79. isBackupInterface: false,
  80. allowRotationInPlace: false,
  81. devices: [],
  82. rotationWarning: null,
  83. status: 'active',
  84. codes: [],
  85. challenge: {
  86. webAuthnAuthenticationData: 'webAuthnAuthenticationData',
  87. authenticateRequests: {
  88. version: 'U2F_V2',
  89. appId: 'https://sentry.io',
  90. keyHandle: 'keyHandle',
  91. challenge: 'challenge',
  92. },
  93. registerRequests: {
  94. version: 'U2F_V2',
  95. appId: 'https://sentry.io',
  96. challenge: 'challenge',
  97. },
  98. registeredKeys: [],
  99. // for WebAuthn register
  100. webAuthnRegisterData: 'webAuthnRegisterData',
  101. },
  102. ...p,
  103. }),
  104. Recovery: (p = {}) => ({
  105. id: 'recovery',
  106. lastUsedAt: null,
  107. enrollButton: 'Activate',
  108. allowRotationInPlace: false,
  109. devices: [],
  110. disallowNewEnrollment: false,
  111. rotationWarning: null,
  112. status: 'active',
  113. description:
  114. 'Recovery codes are the only way to access your account if you lose your device and cannot receive two-factor authentication codes.',
  115. isEnrolled: true,
  116. removeButton: null,
  117. createdAt: '2018-01-30T17:24:36.570Z',
  118. configureButton: 'View Codes',
  119. name: 'Recovery Codes',
  120. allowMultiEnrollment: false,
  121. authId: '16',
  122. canValidateOtp: true,
  123. isBackupInterface: true,
  124. codes: ['ABCD-1234', 'EFGH-5678'],
  125. ...p,
  126. }),
  127. };
  128. }
  129. export function AllAuthenticatorsFixture() {
  130. return Object.values(AuthenticatorsFixture()).map(x => x());
  131. }
  132. export function UserEnrolledAuthenticatorFixture(
  133. params: Partial<UserEnrolledAuthenticator>
  134. ): UserEnrolledAuthenticator {
  135. return {
  136. id: '1',
  137. type: 'totp',
  138. name: 'auth',
  139. dateCreated: '2020-01-01T00:00:00.000Z',
  140. dateUsed: '2020-01-01T00:00:00.000Z',
  141. ...params,
  142. };
  143. }