code_test.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. }