MigratorTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Exceptions\EncryptedMigrationException;
  4. use App\Exceptions\InvalidMigrationDataException;
  5. use App\Exceptions\UnsupportedMigrationException;
  6. use App\Factories\MigratorFactory;
  7. use App\Models\TwoFAccount;
  8. use App\Providers\MigrationServiceProvider;
  9. use App\Services\Migrators\AegisMigrator;
  10. use App\Services\Migrators\GoogleAuthMigrator;
  11. use App\Services\Migrators\Migrator;
  12. use App\Services\Migrators\PlainTextMigrator;
  13. use App\Services\Migrators\TwoFASMigrator;
  14. use App\Services\Migrators\TwoFAuthMigrator;
  15. use App\Services\SettingService;
  16. use Illuminate\Support\Facades\Storage;
  17. use Mockery;
  18. use Mockery\MockInterface;
  19. use PHPUnit\Framework\Attributes\CoversClass;
  20. use PHPUnit\Framework\Attributes\DataProvider;
  21. use PHPUnit\Framework\Attributes\UsesClass;
  22. use Tests\Data\MigrationTestData;
  23. use Tests\Data\OtpTestData;
  24. use Tests\TestCase;
  25. /**
  26. * MigratorTest test class
  27. */
  28. #[CoversClass(MigrationServiceProvider::class)]
  29. #[CoversClass(MigratorFactory::class)]
  30. #[CoversClass(Migrator::class)]
  31. #[CoversClass(AegisMigrator::class)]
  32. #[CoversClass(TwoFASMigrator::class)]
  33. #[CoversClass(PlainTextMigrator::class)]
  34. #[CoversClass(GoogleAuthMigrator::class)]
  35. #[CoversClass(TwoFAuthMigrator::class)]
  36. #[UsesClass(TwoFAccount::class)]
  37. class MigratorTest extends TestCase
  38. {
  39. /**
  40. * App\Models\TwoFAccount $totpTwofaccount
  41. */
  42. protected $totpTwofaccount;
  43. /**
  44. * App\Models\TwoFAccount $totpTwofaccount
  45. */
  46. protected $hotpTwofaccount;
  47. /**
  48. * App\Models\TwoFAccount $steamTwofaccount
  49. */
  50. protected $steamTwofaccount;
  51. /**
  52. * App\Models\TwoFAccount $GAuthTotpTwofaccount
  53. */
  54. protected $GAuthTotpTwofaccount;
  55. /**
  56. * App\Models\TwoFAccount $GAuthTotpBisTwofaccount
  57. */
  58. protected $GAuthTotpBisTwofaccount;
  59. protected $fakeTwofaccount;
  60. public function setUp() : void
  61. {
  62. parent::setUp();
  63. $this->mock(SettingService::class, function (MockInterface $settingService) {
  64. $settingService->allows()
  65. ->get('useEncryption')
  66. ->andReturn(false);
  67. });
  68. $this->totpTwofaccount = new TwoFAccount;
  69. $this->totpTwofaccount->legacy_uri = OtpTestData::TOTP_FULL_CUSTOM_URI_NO_IMG;
  70. $this->totpTwofaccount->service = OtpTestData::SERVICE;
  71. $this->totpTwofaccount->account = OtpTestData::ACCOUNT;
  72. $this->totpTwofaccount->icon = null;
  73. $this->totpTwofaccount->otp_type = 'totp';
  74. $this->totpTwofaccount->secret = OtpTestData::SECRET;
  75. $this->totpTwofaccount->digits = OtpTestData::DIGITS_CUSTOM;
  76. $this->totpTwofaccount->algorithm = OtpTestData::ALGORITHM_CUSTOM;
  77. $this->totpTwofaccount->period = OtpTestData::PERIOD_CUSTOM;
  78. $this->totpTwofaccount->counter = null;
  79. $this->hotpTwofaccount = new TwoFAccount;
  80. $this->hotpTwofaccount->legacy_uri = OtpTestData::HOTP_FULL_CUSTOM_URI_NO_IMG;
  81. $this->hotpTwofaccount->service = OtpTestData::SERVICE;
  82. $this->hotpTwofaccount->account = OtpTestData::ACCOUNT;
  83. $this->hotpTwofaccount->icon = null;
  84. $this->hotpTwofaccount->otp_type = 'hotp';
  85. $this->hotpTwofaccount->secret = OtpTestData::SECRET;
  86. $this->hotpTwofaccount->digits = OtpTestData::DIGITS_CUSTOM;
  87. $this->hotpTwofaccount->algorithm = OtpTestData::ALGORITHM_CUSTOM;
  88. $this->hotpTwofaccount->period = null;
  89. $this->hotpTwofaccount->counter = OtpTestData::COUNTER_CUSTOM;
  90. $this->steamTwofaccount = new TwoFAccount;
  91. $this->steamTwofaccount->legacy_uri = OtpTestData::STEAM_TOTP_URI;
  92. $this->steamTwofaccount->service = OtpTestData::STEAM;
  93. $this->steamTwofaccount->account = OtpTestData::ACCOUNT;
  94. $this->steamTwofaccount->icon = null;
  95. $this->steamTwofaccount->otp_type = 'steamtotp';
  96. $this->steamTwofaccount->secret = OtpTestData::STEAM_SECRET;
  97. $this->steamTwofaccount->digits = OtpTestData::DIGITS_STEAM;
  98. $this->steamTwofaccount->algorithm = OtpTestData::ALGORITHM_DEFAULT;
  99. $this->steamTwofaccount->period = OtpTestData::PERIOD_DEFAULT;
  100. $this->steamTwofaccount->counter = null;
  101. $this->GAuthTotpTwofaccount = new TwoFAccount;
  102. $this->GAuthTotpTwofaccount->service = OtpTestData::SERVICE;
  103. $this->GAuthTotpTwofaccount->account = OtpTestData::ACCOUNT;
  104. $this->GAuthTotpTwofaccount->icon = null;
  105. $this->GAuthTotpTwofaccount->otp_type = 'totp';
  106. $this->GAuthTotpTwofaccount->secret = OtpTestData::SECRET;
  107. $this->GAuthTotpTwofaccount->digits = OtpTestData::DIGITS_DEFAULT;
  108. $this->GAuthTotpTwofaccount->algorithm = OtpTestData::ALGORITHM_DEFAULT;
  109. $this->GAuthTotpTwofaccount->period = OtpTestData::PERIOD_DEFAULT;
  110. $this->GAuthTotpTwofaccount->counter = null;
  111. $this->GAuthTotpBisTwofaccount = new TwoFAccount;
  112. $this->GAuthTotpBisTwofaccount->service = OtpTestData::SERVICE . '_bis';
  113. $this->GAuthTotpBisTwofaccount->account = OtpTestData::ACCOUNT . '_bis';
  114. $this->GAuthTotpBisTwofaccount->icon = null;
  115. $this->GAuthTotpBisTwofaccount->otp_type = 'totp';
  116. $this->GAuthTotpBisTwofaccount->secret = OtpTestData::SECRET;
  117. $this->GAuthTotpBisTwofaccount->digits = OtpTestData::DIGITS_DEFAULT;
  118. $this->GAuthTotpBisTwofaccount->algorithm = OtpTestData::ALGORITHM_DEFAULT;
  119. $this->GAuthTotpBisTwofaccount->period = OtpTestData::PERIOD_DEFAULT;
  120. $this->GAuthTotpBisTwofaccount->counter = null;
  121. $this->fakeTwofaccount = new TwoFAccount;
  122. $this->fakeTwofaccount->id = TwoFAccount::FAKE_ID;
  123. }
  124. /**
  125. * Clean up the testing environment before the next test.
  126. *
  127. * @return void
  128. *
  129. * @throws \Mockery\Exception\InvalidCountException
  130. */
  131. protected function tearDown() : void
  132. {
  133. $this->forgetMock(SettingService::class);
  134. parent::tearDown();
  135. }
  136. /**
  137. * @test
  138. */
  139. #[DataProvider('validMigrationsProvider')]
  140. public function test_migrate_returns_consistent_accounts(Migrator $migrator, mixed $payload, string $expected, bool $hasSteam)
  141. {
  142. $accounts = $migrator->migrate($payload);
  143. if ($expected === 'gauth') {
  144. $totp = $this->GAuthTotpTwofaccount;
  145. $hotp = $this->GAuthTotpBisTwofaccount;
  146. } else {
  147. $totp = $this->totpTwofaccount;
  148. $hotp = $this->hotpTwofaccount;
  149. if ($hasSteam) {
  150. $steam = $this->steamTwofaccount;
  151. }
  152. }
  153. $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts);
  154. $this->assertCount($hasSteam ? 3 : 2, $accounts);
  155. // The returned collection could have non-linear index (because of possible blank lines
  156. // in the migration payload) so we do not use get() to retrieve items
  157. $this->assertObjectEquals($totp, $accounts->first());
  158. $this->assertObjectEquals($hotp, $accounts->slice(1, 1)->first());
  159. if ($hasSteam) {
  160. $this->assertObjectEquals($steam, $accounts->last());
  161. }
  162. }
  163. /**
  164. * Provide data for TwoFAccount store tests
  165. */
  166. public static function validMigrationsProvider()
  167. {
  168. return [
  169. 'PLAIN_TEXT_PAYLOAD' => [
  170. new PlainTextMigrator(),
  171. MigrationTestData::VALID_PLAIN_TEXT_PAYLOAD,
  172. 'custom',
  173. $hasSteam = true,
  174. ],
  175. 'PLAIN_TEXT_PAYLOAD_WITH_INTRUDER' => [
  176. new PlainTextMigrator(),
  177. MigrationTestData::VALID_PLAIN_TEXT_PAYLOAD_WITH_INTRUDER,
  178. 'custom',
  179. $hasSteam = true,
  180. ],
  181. 'AEGIS_JSON_MIGRATION_PAYLOAD' => [
  182. new AegisMigrator(),
  183. MigrationTestData::VALID_AEGIS_JSON_MIGRATION_PAYLOAD,
  184. 'custom',
  185. $hasSteam = true,
  186. ],
  187. '2FAS_MIGRATION_PAYLOAD' => [
  188. new TwoFASMigrator(),
  189. MigrationTestData::VALID_2FAS_MIGRATION_PAYLOAD,
  190. 'custom',
  191. $hasSteam = false,
  192. ],
  193. 'GOOGLE_AUTH_MIGRATION_PAYLOAD' => [
  194. new GoogleAuthMigrator(),
  195. MigrationTestData::GOOGLE_AUTH_MIGRATION_URI,
  196. 'gauth',
  197. $hasSteam = false,
  198. ],
  199. '2FAUTH_MIGRATION_PAYLOAD' => [
  200. new TwoFAuthMigrator(),
  201. MigrationTestData::VALID_2FAUTH_JSON_MIGRATION_PAYLOAD,
  202. 'custom',
  203. $hasSteam = true,
  204. ],
  205. ];
  206. }
  207. /**
  208. * @test
  209. */
  210. #[DataProvider('invalidMigrationsProvider')]
  211. public function test_migrate_with_invalid_payload_returns_InvalidMigrationDataException(Migrator $migrator, mixed $payload)
  212. {
  213. $this->expectException(InvalidMigrationDataException::class);
  214. $accounts = $migrator->migrate($payload);
  215. }
  216. /**
  217. * Provide data for TwoFAccount store tests
  218. */
  219. public static function invalidMigrationsProvider()
  220. {
  221. return [
  222. 'INVALID_PLAIN_TEXT_NO_URI' => [
  223. new PlainTextMigrator(),
  224. MigrationTestData::INVALID_PLAIN_TEXT_NO_URI,
  225. ],
  226. 'INVALID_PLAIN_TEXT_ONLY_EMPTY_LINES' => [
  227. new PlainTextMigrator(),
  228. MigrationTestData::INVALID_PLAIN_TEXT_ONLY_EMPTY_LINES,
  229. ],
  230. 'INVALID_PLAIN_TEXT_NULL' => [
  231. new PlainTextMigrator(),
  232. null,
  233. ],
  234. 'INVALID_PLAIN_TEXT_EMPTY_STRING' => [
  235. new PlainTextMigrator(),
  236. '',
  237. ],
  238. 'INVALID_PLAIN_TEXT_INT' => [
  239. new PlainTextMigrator(),
  240. 10,
  241. ],
  242. 'INVALID_PLAIN_TEXT_BOOL' => [
  243. new PlainTextMigrator(),
  244. true,
  245. ],
  246. 'INVALID_AEGIS_JSON_MIGRATION_PAYLOAD' => [
  247. new AegisMigrator(),
  248. MigrationTestData::INVALID_AEGIS_JSON_MIGRATION_PAYLOAD,
  249. ],
  250. 'ENCRYPTED_AEGIS_JSON_MIGRATION_PAYLOAD' => [
  251. new AegisMigrator(),
  252. MigrationTestData::ENCRYPTED_AEGIS_JSON_MIGRATION_PAYLOAD,
  253. ],
  254. 'INVALID_2FAS_MIGRATION_PAYLOAD' => [
  255. new TwoFASMigrator(),
  256. MigrationTestData::INVALID_2FAS_MIGRATION_PAYLOAD,
  257. ],
  258. 'INVALID_GOOGLE_AUTH_MIGRATION_URI' => [
  259. new GoogleAuthMigrator(),
  260. MigrationTestData::INVALID_GOOGLE_AUTH_MIGRATION_URI,
  261. ],
  262. 'GOOGLE_AUTH_MIGRATION_URI_WITH_INVALID_DATA' => [
  263. new GoogleAuthMigrator(),
  264. MigrationTestData::GOOGLE_AUTH_MIGRATION_URI_WITH_INVALID_DATA,
  265. ],
  266. 'INVALID_2FAUTH_JSON_MIGRATION_PAYLOAD' => [
  267. new TwoFAuthMigrator(),
  268. MigrationTestData::INVALID_2FAUTH_JSON_MIGRATION_PAYLOAD,
  269. ],
  270. ];
  271. }
  272. /**
  273. * @test
  274. */
  275. #[DataProvider('migrationWithInvalidAccountsProvider')]
  276. public function test_migrate_returns_fake_accounts(Migrator $migrator, mixed $payload)
  277. {
  278. $accounts = $migrator->migrate($payload);
  279. $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts);
  280. $this->assertCount(2, $accounts);
  281. // The returned collection could have non-linear index (because of possible blank lines
  282. // in the migration payload) so we do not use get() to retrieve items
  283. $this->assertObjectEquals($this->totpTwofaccount, $accounts->first());
  284. $this->assertEquals($this->fakeTwofaccount->id, $accounts->last()->id);
  285. }
  286. /**
  287. * Provide data for TwoFAccount store tests
  288. */
  289. public static function migrationWithInvalidAccountsProvider()
  290. {
  291. return [
  292. 'PLAIN_TEXT_PAYLOAD_WITH_INVALID_URI' => [
  293. new PlainTextMigrator(),
  294. MigrationTestData::PLAIN_TEXT_PAYLOAD_WITH_INVALID_URI,
  295. ],
  296. 'VALID_AEGIS_JSON_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_OTP_TYPE' => [
  297. new AegisMigrator(),
  298. MigrationTestData::VALID_AEGIS_JSON_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_OTP_TYPE,
  299. ],
  300. 'VALID_2FAS_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_OTP_TYPE' => [
  301. new TwoFASMigrator(),
  302. MigrationTestData::VALID_2FAS_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_OTP_TYPE,
  303. ],
  304. 'VALID_2FAUTH_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_OTP_TYPE' => [
  305. new TwoFAuthMigrator(),
  306. MigrationTestData::VALID_2FAUTH_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_OTP_TYPE,
  307. ],
  308. ];
  309. }
  310. /**
  311. * @test
  312. */
  313. public function test_migrate_gauth_returns_fake_accounts()
  314. {
  315. $migrator = $this->partialMock(GoogleAuthMigrator::class, function (MockInterface $migrator) {
  316. $migrator->shouldAllowMockingProtectedMethods()->shouldReceive('toBase32')
  317. ->andThrow(new \Exception());
  318. });
  319. /** @disregard Undefined function */
  320. $accounts = $migrator->migrate(MigrationTestData::GOOGLE_AUTH_MIGRATION_URI);
  321. $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts);
  322. $this->assertCount(2, $accounts);
  323. // The returned collection could have non-linear index (because of possible blank lines
  324. // in the migration payload) so we do not use get() to retrieve items
  325. $this->assertEquals($this->fakeTwofaccount->id, $accounts->first()->id);
  326. $this->assertEquals($this->fakeTwofaccount->id, $accounts->last()->id);
  327. $this->forgetMock(GoogleAuthMigrator::class);
  328. }
  329. /**
  330. * @test
  331. */
  332. #[DataProvider('AegisWithIconMigrationProvider')]
  333. public function test_migrate_aegis_payload_with_icon_sets_and_stores_the_icon($migration)
  334. {
  335. Storage::fake('icons');
  336. $migrator = new AegisMigrator();
  337. $accounts = $migrator->migrate($migration);
  338. $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts);
  339. $this->assertCount(1, $accounts);
  340. Storage::disk('icons')->assertExists($accounts->first()->icon);
  341. }
  342. /**
  343. * Provide data for TwoFAccount store tests
  344. */
  345. public static function AegisWithIconMigrationProvider()
  346. {
  347. return [
  348. 'SVG' => [
  349. MigrationTestData::VALID_AEGIS_JSON_MIGRATION_PAYLOAD_WITH_SVG_ICON,
  350. ],
  351. 'PNG' => [
  352. MigrationTestData::VALID_AEGIS_JSON_MIGRATION_PAYLOAD_WITH_PNG_ICON,
  353. ],
  354. 'JPG' => [
  355. MigrationTestData::VALID_AEGIS_JSON_MIGRATION_PAYLOAD_WITH_JPG_ICON,
  356. ],
  357. ];
  358. }
  359. /**
  360. * @test
  361. */
  362. public function test_migrate_aegis_payload_with_unsupported_icon_does_not_fail()
  363. {
  364. Storage::fake('icons');
  365. $migrator = new AegisMigrator();
  366. $accounts = $migrator->migrate(MigrationTestData::VALID_AEGIS_JSON_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_ICON);
  367. $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts);
  368. $this->assertCount(1, $accounts);
  369. $this->assertNull($this->fakeTwofaccount->icon);
  370. Storage::disk('icons')->assertDirectoryEmpty('/');
  371. }
  372. /**
  373. * @test
  374. */
  375. #[DataProvider('TwoFAuthWithIconMigrationProvider')]
  376. public function test_migrate_2fauth_payload_with_icon_sets_and_stores_the_icon($migration)
  377. {
  378. Storage::fake('icons');
  379. $migrator = new TwoFAuthMigrator();
  380. $accounts = $migrator->migrate($migration);
  381. $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts);
  382. $this->assertCount(1, $accounts);
  383. Storage::disk('icons')->assertExists($accounts->first()->icon);
  384. }
  385. /**
  386. * Provide data for TwoFAccount store tests
  387. */
  388. public static function TwoFAuthWithIconMigrationProvider()
  389. {
  390. return [
  391. 'SVG' => [
  392. MigrationTestData::VALID_2FAUTH_JSON_MIGRATION_PAYLOAD_WITH_SVG_ICON,
  393. ],
  394. 'PNG' => [
  395. MigrationTestData::VALID_2FAUTH_JSON_MIGRATION_PAYLOAD_WITH_PNG_ICON,
  396. ],
  397. 'JPG' => [
  398. MigrationTestData::VALID_2FAUTH_JSON_MIGRATION_PAYLOAD_WITH_JPG_ICON,
  399. ],
  400. 'BMP' => [
  401. MigrationTestData::VALID_2FAUTH_JSON_MIGRATION_PAYLOAD_WITH_BMP_ICON,
  402. ],
  403. 'WEBP' => [
  404. MigrationTestData::VALID_2FAUTH_JSON_MIGRATION_PAYLOAD_WITH_WEBP_ICON,
  405. ],
  406. ];
  407. }
  408. /**
  409. * @test
  410. */
  411. public function test_migrate_2fauth_payload_with_unsupported_icon_does_not_fail()
  412. {
  413. Storage::fake('icons');
  414. $migrator = new TwoFAuthMigrator();
  415. $accounts = $migrator->migrate(MigrationTestData::VALID_2FAUTH_JSON_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_ICON);
  416. $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts);
  417. $this->assertCount(1, $accounts);
  418. $this->assertNull($this->fakeTwofaccount->icon);
  419. Storage::disk('icons')->assertDirectoryEmpty('/');
  420. }
  421. /**
  422. * @test
  423. */
  424. #[DataProvider('factoryProvider')]
  425. public function test_factory_returns_relevant_migrator($payload, $migratorClass)
  426. {
  427. $factory = new MigratorFactory();
  428. $migrator = $factory->create($payload);
  429. $this->assertInstanceOf($migratorClass, $migrator);
  430. }
  431. /**
  432. * Provide data for TwoFAccount store tests
  433. */
  434. public static function factoryProvider()
  435. {
  436. return [
  437. 'VALID_PLAIN_TEXT_PAYLOAD' => [
  438. MigrationTestData::VALID_PLAIN_TEXT_PAYLOAD,
  439. PlainTextMigrator::class,
  440. ],
  441. 'VALID_AEGIS_JSON_MIGRATION_PAYLOAD' => [
  442. MigrationTestData::VALID_AEGIS_JSON_MIGRATION_PAYLOAD,
  443. AegisMigrator::class,
  444. ],
  445. 'VALID_AEGIS_JSON_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_ICON' => [
  446. MigrationTestData::VALID_AEGIS_JSON_MIGRATION_PAYLOAD_WITH_UNSUPPORTED_ICON,
  447. AegisMigrator::class,
  448. ],
  449. 'VALID_2FAS_MIGRATION_PAYLOAD' => [
  450. MigrationTestData::VALID_2FAS_MIGRATION_PAYLOAD,
  451. TwoFASMigrator::class,
  452. ],
  453. 'GOOGLE_AUTH_MIGRATION_URI' => [
  454. MigrationTestData::GOOGLE_AUTH_MIGRATION_URI,
  455. GoogleAuthMigrator::class,
  456. ],
  457. '2FAUTH_MIGRATION_URI' => [
  458. MigrationTestData::VALID_2FAUTH_JSON_MIGRATION_PAYLOAD,
  459. TwoFAuthMigrator::class,
  460. ],
  461. ];
  462. }
  463. /**
  464. * @test
  465. */
  466. public function test_factory_throw_UnsupportedMigrationException()
  467. {
  468. $this->expectException(UnsupportedMigrationException::class);
  469. $factory = new MigratorFactory();
  470. $migrator = $factory->create('not_a_valid_payload');
  471. }
  472. /**
  473. * @test
  474. */
  475. #[DataProvider('encryptedMigrationDataProvider')]
  476. public function test_factory_throw_EncryptedMigrationException($payload)
  477. {
  478. $this->expectException(EncryptedMigrationException::class);
  479. $factory = new MigratorFactory();
  480. $migrator = $factory->create($payload);
  481. }
  482. /**
  483. * Provide data for TwoFAccount store tests
  484. */
  485. public static function encryptedMigrationDataProvider()
  486. {
  487. return [
  488. 'ENCRYPTED_AEGIS_JSON_MIGRATION_PAYLOAD' => [
  489. MigrationTestData::ENCRYPTED_AEGIS_JSON_MIGRATION_PAYLOAD,
  490. ],
  491. 'ENCRYPTED_2FAS_MIGRATION_PAYLOAD' => [
  492. MigrationTestData::ENCRYPTED_2FAS_MIGRATION_PAYLOAD,
  493. ],
  494. ];
  495. }
  496. }