code_test.dart 1.2 KB

1234567891011121314151617181920212223242526272829303132
  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. //
  21. test("parseWithFunnyAccountName", () {
  22. final code = Code.fromRawData(
  23. "otpauth://totp/Mongo Atlas:Acc !@#444?algorithm=sha1&digits=6&issuer=Mongo Atlas&period=30&secret=NI4CTTFEV4G2JFE6",
  24. );
  25. expect(code.issuer, "Mongo Atlas", reason: "issuerMismatch");
  26. expect(code.account, "Acc !@#444", reason: "accountMismatch");
  27. expect(code.secret, "NI4CTTFEV4G2JFE6");
  28. });
  29. }