code_test.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import 'package:ente_auth/models/code.dart';
  2. import 'package:flutter_test/flutter_test.dart';
  3. void main() {
  4. test("parseCodeFromRawData", () {
  5. final code1 = Code.fromRawData(
  6. "otpauth://totp/example%20finance%3Aee%40ff.gg?secret=ASKZNWOU6SVYAMVS",
  7. );
  8. expect(code1.issuer, "example finance", reason: "issuerMismatch");
  9. expect(code1.account, "ee@ff.gg", reason: "accountMismatch");
  10. expect(code1.secret, "ASKZNWOU6SVYAMVS");
  11. });
  12. test("parseDocumentedFormat", () {
  13. final code = Code.fromRawData(
  14. "otpauth://totp/testdata@ente.io?secret=ASKZNWOU6SVYAMVS&issuer=GitHub",
  15. );
  16. expect(code.issuer, "GitHub", reason: "issuerMismatch");
  17. expect(code.account, "testdata@ente.io", reason: "accountMismatch");
  18. expect(code.secret, "ASKZNWOU6SVYAMVS");
  19. });
  20. test("validateCount", () {
  21. final code = Code.fromRawData(
  22. "otpauth://hotp/testdata@ente.io?secret=ASKZNWOU6SVYAMVS&issuer=GitHub&counter=15",
  23. );
  24. expect(code.issuer, "GitHub", reason: "issuerMismatch");
  25. expect(code.account, "testdata@ente.io", reason: "accountMismatch");
  26. expect(code.secret, "ASKZNWOU6SVYAMVS");
  27. expect(code.counter, 15);
  28. });
  29. //
  30. test("parseWithFunnyAccountName", () {
  31. final code = Code.fromRawData(
  32. "otpauth://totp/Mongo Atlas:Acc !@#444?algorithm=sha1&digits=6&issuer=Mongo Atlas&period=30&secret=NI4CTTFEV4G2JFE6",
  33. );
  34. expect(code.issuer, "Mongo Atlas", reason: "issuerMismatch");
  35. expect(code.account, "Acc !@#444", reason: "accountMismatch");
  36. expect(code.secret, "NI4CTTFEV4G2JFE6");
  37. });
  38. test("parseAndUpdateInChinese", () {
  39. const String rubberDuckQr =
  40. 'otpauth://totp/%E6%A9%A1%E7%9A%AE%E9%B8%AD?secret=2CWDCK4EOIN5DJDRMYUMYBBO4MKSR5AX&issuer=ente.io';
  41. final code = Code.fromRawData(rubberDuckQr);
  42. expect(code.account, '橡皮鸭');
  43. final String updatedRawCode =
  44. code.copyWith(account: '伍迪', issuer: '鸭子').rawData;
  45. final updateCode = Code.fromRawData(updatedRawCode);
  46. expect(updateCode.account, '伍迪', reason: 'updated accountMismatch');
  47. expect(updateCode.issuer, '鸭子', reason: 'updated issuerMismatch');
  48. });
  49. }