๐Ÿ“ฆ amake / orgro

๐Ÿ“„ encryption_test.dart ยท 87 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87import 'package:flutter_test/flutter_test.dart';
import 'package:org_flutter/org_flutter.dart';
import 'package:orgro/src/encryption.dart';

import 'utils/encryption.dart';

void main() {
  setUp(() {
    mockOpenPGP();
  });
  tearDown(() {
    restoreOpenPGP();
  });
  group('Encryption', () {
    group('needsEncryption', () {
      test('Correctly encrypted section', () {
        const content = '''
* foo :crypt:

-----BEGIN PGP MESSAGE-----

jA0ECQMI05i+dd7lsRry0joBcGZQ4m+N9M/Z3I2Xw7SSn2uPMRpWbH9UIRkzPTXU
28y0FO/Aug4JaE/n+wqbmgY0b37dZzWI2BWi
=uuok
-----END PGP MESSAGE-----
''';
        final doc = OrgDocument.parse(content);
        final section = doc.sections.first;
        expect(section.needsEncryption(), isFalse);
      });
      test('Non-Org Crypt section', () {
        const content = '''
* foo

bar
''';
        final doc = OrgDocument.parse(content);
        final section = doc.sections.first;
        expect(section.needsEncryption(), isFalse);
      });
      test('Unencrypted Org Crypt section', () {
        const content = '''
* foo :crypt:

bar
''';
        final doc = OrgDocument.parse(content);
        final section = doc.sections.first;
        expect(section.needsEncryption(), isTrue);
      });
      test('Unencrypted leading content', () {
        const content = '''
* foo :crypt:

bar

-----BEGIN PGP MESSAGE-----

jA0ECQMI05i+dd7lsRry0joBcGZQ4m+N9M/Z3I2Xw7SSn2uPMRpWbH9UIRkzPTXU
28y0FO/Aug4JaE/n+wqbmgY0b37dZzWI2BWi
=uuok
-----END PGP MESSAGE-----
''';
        final doc = OrgDocument.parse(content);
        final section = doc.sections.first;
        expect(section.needsEncryption(), isTrue);
      });
    });
    test('encrypt', () {
      const content = '''
* foo :crypt:

bar
''';
      final doc = OrgDocument.parse(content);
      final section = doc.sections.first;
      expect(section.encrypt('foobar'), '''* foo :crypt:

-----BEGIN PGP MESSAGE-----

YmFyCg==
-----END PGP MESSAGE-----
''');
    });
  });
}