appium-ios-remotexpc 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/src/base-plist-service.d.ts +51 -0
  3. package/build/src/base-plist-service.d.ts.map +1 -0
  4. package/build/src/base-plist-service.js +61 -0
  5. package/build/src/base-socket-service.d.ts +15 -0
  6. package/build/src/base-socket-service.d.ts.map +1 -0
  7. package/build/src/base-socket-service.js +46 -0
  8. package/build/src/index.d.ts +9 -0
  9. package/build/src/index.d.ts.map +1 -0
  10. package/build/src/index.js +7 -0
  11. package/build/src/lib/apple-tv/constants.d.ts +49 -0
  12. package/build/src/lib/apple-tv/constants.d.ts.map +1 -0
  13. package/build/src/lib/apple-tv/constants.js +71 -0
  14. package/build/src/lib/apple-tv/errors.d.ts +17 -0
  15. package/build/src/lib/apple-tv/errors.d.ts.map +1 -0
  16. package/build/src/lib/apple-tv/errors.js +30 -0
  17. package/build/src/lib/apple-tv/tlv/decoder.d.ts +19 -0
  18. package/build/src/lib/apple-tv/tlv/decoder.d.ts.map +1 -0
  19. package/build/src/lib/apple-tv/tlv/decoder.js +49 -0
  20. package/build/src/lib/apple-tv/tlv/encoder.d.ts +10 -0
  21. package/build/src/lib/apple-tv/tlv/encoder.d.ts.map +1 -0
  22. package/build/src/lib/apple-tv/tlv/encoder.js +20 -0
  23. package/build/src/lib/apple-tv/tlv/index.d.ts +4 -0
  24. package/build/src/lib/apple-tv/tlv/index.d.ts.map +1 -0
  25. package/build/src/lib/apple-tv/tlv/index.js +3 -0
  26. package/build/src/lib/apple-tv/tlv/pairing-tlv.d.ts +14 -0
  27. package/build/src/lib/apple-tv/tlv/pairing-tlv.d.ts.map +1 -0
  28. package/build/src/lib/apple-tv/tlv/pairing-tlv.js +27 -0
  29. package/build/src/lib/apple-tv/types.d.ts +36 -0
  30. package/build/src/lib/apple-tv/types.d.ts.map +1 -0
  31. package/build/src/lib/apple-tv/types.js +1 -0
  32. package/build/src/lib/apple-tv/utils/buffer-utils.d.ts +40 -0
  33. package/build/src/lib/apple-tv/utils/buffer-utils.d.ts.map +1 -0
  34. package/build/src/lib/apple-tv/utils/buffer-utils.js +76 -0
  35. package/build/src/lib/apple-tv/utils/index.d.ts +3 -0
  36. package/build/src/lib/apple-tv/utils/index.d.ts.map +1 -0
  37. package/build/src/lib/apple-tv/utils/index.js +2 -0
  38. package/build/src/lib/apple-tv/utils/uuid-generator.d.ts +9 -0
  39. package/build/src/lib/apple-tv/utils/uuid-generator.d.ts.map +1 -0
  40. package/build/src/lib/apple-tv/utils/uuid-generator.js +36 -0
  41. package/build/src/lib/lockdown/index.d.ts +87 -0
  42. package/build/src/lib/lockdown/index.d.ts.map +1 -0
  43. package/build/src/lib/lockdown/index.js +324 -0
  44. package/build/src/lib/pair-record/index.d.ts +3 -0
  45. package/build/src/lib/pair-record/index.d.ts.map +1 -0
  46. package/build/src/lib/pair-record/index.js +2 -0
  47. package/build/src/lib/pair-record/pair-record.d.ts +48 -0
  48. package/build/src/lib/pair-record/pair-record.d.ts.map +1 -0
  49. package/build/src/lib/pair-record/pair-record.js +85 -0
  50. package/build/src/lib/plist/binary-plist-creator.d.ts +14 -0
  51. package/build/src/lib/plist/binary-plist-creator.d.ts.map +1 -0
  52. package/build/src/lib/plist/binary-plist-creator.js +475 -0
  53. package/build/src/lib/plist/binary-plist-parser.d.ts +14 -0
  54. package/build/src/lib/plist/binary-plist-parser.d.ts.map +1 -0
  55. package/build/src/lib/plist/binary-plist-parser.js +449 -0
  56. package/build/src/lib/plist/constants.d.ts +36 -0
  57. package/build/src/lib/plist/constants.d.ts.map +1 -0
  58. package/build/src/lib/plist/constants.js +43 -0
  59. package/build/src/lib/plist/index.d.ts +14 -0
  60. package/build/src/lib/plist/index.d.ts.map +1 -0
  61. package/build/src/lib/plist/index.js +16 -0
  62. package/build/src/lib/plist/length-based-splitter.d.ts +43 -0
  63. package/build/src/lib/plist/length-based-splitter.d.ts.map +1 -0
  64. package/build/src/lib/plist/length-based-splitter.js +228 -0
  65. package/build/src/lib/plist/plist-creator.d.ts +8 -0
  66. package/build/src/lib/plist/plist-creator.d.ts.map +1 -0
  67. package/build/src/lib/plist/plist-creator.js +33 -0
  68. package/build/src/lib/plist/plist-decoder.d.ts +25 -0
  69. package/build/src/lib/plist/plist-decoder.d.ts.map +1 -0
  70. package/build/src/lib/plist/plist-decoder.js +103 -0
  71. package/build/src/lib/plist/plist-encoder.d.ts +10 -0
  72. package/build/src/lib/plist/plist-encoder.d.ts.map +1 -0
  73. package/build/src/lib/plist/plist-encoder.js +27 -0
  74. package/build/src/lib/plist/plist-parser.d.ts +9 -0
  75. package/build/src/lib/plist/plist-parser.d.ts.map +1 -0
  76. package/build/src/lib/plist/plist-parser.js +109 -0
  77. package/build/src/lib/plist/plist-service.d.ts +86 -0
  78. package/build/src/lib/plist/plist-service.d.ts.map +1 -0
  79. package/build/src/lib/plist/plist-service.js +180 -0
  80. package/build/src/lib/plist/unified-plist-creator.d.ts +9 -0
  81. package/build/src/lib/plist/unified-plist-creator.d.ts.map +1 -0
  82. package/build/src/lib/plist/unified-plist-creator.js +14 -0
  83. package/build/src/lib/plist/unified-plist-parser.d.ts +8 -0
  84. package/build/src/lib/plist/unified-plist-parser.d.ts.map +1 -0
  85. package/build/src/lib/plist/unified-plist-parser.js +23 -0
  86. package/build/src/lib/plist/utils.d.ts +97 -0
  87. package/build/src/lib/plist/utils.d.ts.map +1 -0
  88. package/build/src/lib/plist/utils.js +287 -0
  89. package/build/src/lib/remote-xpc/constants.d.ts +20 -0
  90. package/build/src/lib/remote-xpc/constants.d.ts.map +1 -0
  91. package/build/src/lib/remote-xpc/constants.js +21 -0
  92. package/build/src/lib/remote-xpc/handshake-frames.d.ts +74 -0
  93. package/build/src/lib/remote-xpc/handshake-frames.d.ts.map +1 -0
  94. package/build/src/lib/remote-xpc/handshake-frames.js +285 -0
  95. package/build/src/lib/remote-xpc/handshake.d.ts +14 -0
  96. package/build/src/lib/remote-xpc/handshake.d.ts.map +1 -0
  97. package/build/src/lib/remote-xpc/handshake.js +95 -0
  98. package/build/src/lib/remote-xpc/remote-xpc-connection.d.ts +55 -0
  99. package/build/src/lib/remote-xpc/remote-xpc-connection.d.ts.map +1 -0
  100. package/build/src/lib/remote-xpc/remote-xpc-connection.js +365 -0
  101. package/build/src/lib/remote-xpc/xpc-protocol.d.ts +22 -0
  102. package/build/src/lib/remote-xpc/xpc-protocol.d.ts.map +1 -0
  103. package/build/src/lib/remote-xpc/xpc-protocol.js +368 -0
  104. package/build/src/lib/tunnel/index.d.ts +69 -0
  105. package/build/src/lib/tunnel/index.d.ts.map +1 -0
  106. package/build/src/lib/tunnel/index.js +205 -0
  107. package/build/src/lib/tunnel/packet-stream-client.d.ts +46 -0
  108. package/build/src/lib/tunnel/packet-stream-client.d.ts.map +1 -0
  109. package/build/src/lib/tunnel/packet-stream-client.js +152 -0
  110. package/build/src/lib/tunnel/packet-stream-server.d.ts +37 -0
  111. package/build/src/lib/tunnel/packet-stream-server.d.ts.map +1 -0
  112. package/build/src/lib/tunnel/packet-stream-server.js +109 -0
  113. package/build/src/lib/tunnel/tunnel-api-client.d.ts +85 -0
  114. package/build/src/lib/tunnel/tunnel-api-client.d.ts.map +1 -0
  115. package/build/src/lib/tunnel/tunnel-api-client.js +207 -0
  116. package/build/src/lib/tunnel/tunnel-registry-server.d.ts +68 -0
  117. package/build/src/lib/tunnel/tunnel-registry-server.d.ts.map +1 -0
  118. package/build/src/lib/tunnel/tunnel-registry-server.js +351 -0
  119. package/build/src/lib/types.d.ts +238 -0
  120. package/build/src/lib/types.d.ts.map +1 -0
  121. package/build/src/lib/types.js +4 -0
  122. package/build/src/lib/usbmux/index.d.ts +177 -0
  123. package/build/src/lib/usbmux/index.d.ts.map +1 -0
  124. package/build/src/lib/usbmux/index.js +490 -0
  125. package/build/src/lib/usbmux/usbmux-decoder.d.ts +19 -0
  126. package/build/src/lib/usbmux/usbmux-decoder.d.ts.map +1 -0
  127. package/build/src/lib/usbmux/usbmux-decoder.js +38 -0
  128. package/build/src/lib/usbmux/usbmux-encoder.d.ts +12 -0
  129. package/build/src/lib/usbmux/usbmux-encoder.d.ts.map +1 -0
  130. package/build/src/lib/usbmux/usbmux-encoder.js +32 -0
  131. package/build/src/service-connection.d.ts +34 -0
  132. package/build/src/service-connection.d.ts.map +1 -0
  133. package/build/src/service-connection.js +51 -0
  134. package/build/src/services/index.d.ts +6 -0
  135. package/build/src/services/index.d.ts.map +1 -0
  136. package/build/src/services/index.js +5 -0
  137. package/build/src/services/ios/base-service.d.ts +35 -0
  138. package/build/src/services/ios/base-service.d.ts.map +1 -0
  139. package/build/src/services/ios/base-service.js +55 -0
  140. package/build/src/services/ios/diagnostic-service/index.d.ts +46 -0
  141. package/build/src/services/ios/diagnostic-service/index.d.ts.map +1 -0
  142. package/build/src/services/ios/diagnostic-service/index.js +169 -0
  143. package/build/src/services/ios/diagnostic-service/keys.d.ts +5 -0
  144. package/build/src/services/ios/diagnostic-service/keys.d.ts.map +1 -0
  145. package/build/src/services/ios/diagnostic-service/keys.js +770 -0
  146. package/build/src/services/ios/syslog-service/index.d.ts +91 -0
  147. package/build/src/services/ios/syslog-service/index.d.ts.map +1 -0
  148. package/build/src/services/ios/syslog-service/index.js +323 -0
  149. package/build/src/services/ios/tunnel-service/index.d.ts +17 -0
  150. package/build/src/services/ios/tunnel-service/index.d.ts.map +1 -0
  151. package/build/src/services/ios/tunnel-service/index.js +57 -0
  152. package/build/src/services.d.ts +14 -0
  153. package/build/src/services.d.ts.map +1 -0
  154. package/build/src/services.js +48 -0
  155. package/package.json +12 -3
  156. package/.github/dependabot.yml +0 -38
  157. package/.github/workflows/format-check.yml +0 -43
  158. package/.github/workflows/lint-and-build.yml +0 -40
  159. package/.github/workflows/pr-title.yml +0 -16
  160. package/.github/workflows/publish.js.yml +0 -41
  161. package/.github/workflows/test-validation.yml +0 -40
  162. package/.mocharc.json +0 -8
  163. package/.prettierignore +0 -3
  164. package/.prettierrc +0 -17
  165. package/.releaserc +0 -48
  166. package/assets/images/ios-arch.png +0 -0
  167. package/eslint.config.js +0 -45
  168. package/npm-shrinkwrap.json +0 -2711
  169. package/test/integration/diagnostics-test.ts +0 -44
  170. package/test/integration/read-pair-record-test.ts +0 -39
  171. package/test/integration/tunnel-test.ts +0 -104
  172. package/test/unit/apple-tv/tlv/decoder.spec.ts +0 -144
  173. package/test/unit/apple-tv/tlv/encoder.spec.ts +0 -91
  174. package/test/unit/apple-tv/tlv/pairing-tlv.spec.ts +0 -101
  175. package/test/unit/apple-tv/tlv/tlv-integration.spec.ts +0 -146
  176. package/test/unit/apple-tv/utils/buffer-utils.spec.ts +0 -74
  177. package/test/unit/apple-tv/utils/uuid-generator.spec.ts +0 -39
  178. package/test/unit/fixtures/index.ts +0 -88
  179. package/test/unit/fixtures/usbmuxconnectmessage.bin +0 -0
  180. package/test/unit/fixtures/usbmuxlistdevicemessage.bin +0 -0
  181. package/test/unit/plist/error-handling.spec.ts +0 -101
  182. package/test/unit/plist/fixtures/sample.binary.plist +0 -0
  183. package/test/unit/plist/fixtures/sample.xml.plist +0 -38
  184. package/test/unit/plist/plist-parser.spec.ts +0 -283
  185. package/test/unit/plist/plist.spec.ts +0 -205
  186. package/test/unit/plist/tag-position-handling.spec.ts +0 -90
  187. package/test/unit/plist/unified-plist-parser.spec.ts +0 -227
  188. package/test/unit/plist/utils.spec.ts +0 -249
  189. package/test/unit/plist/xml-cleaning.spec.ts +0 -60
  190. package/test/unit/tunnel/tunnel-registry-server.spec.ts +0 -194
  191. package/test/unit/usbmux/usbmux-specs.ts +0 -71
  192. package/tsconfig.json +0 -36
@@ -1,205 +0,0 @@
1
- import { expect } from 'chai';
2
- import fs from 'fs';
3
- import path from 'path';
4
- import { fileURLToPath } from 'url';
5
-
6
- import {
7
- createBinaryPlist,
8
- createPlist,
9
- createXmlPlist,
10
- isBinaryPlist,
11
- parseBinaryPlist,
12
- parsePlist,
13
- parseXmlPlist,
14
- } from '../../../src/lib/plist/index.js';
15
- import type { PlistDictionary } from '../../../src/lib/types.js';
16
-
17
- // Get the directory name
18
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
19
- const FIXTURES_PATH = path.join(__dirname, 'fixtures');
20
-
21
- describe('Plist Module', function () {
22
- let sampleXmlPlistPath: string;
23
- let sampleXmlPlistContent: string;
24
- let sampleBinaryPlistPath: string;
25
- let sampleBinaryPlistContent: Buffer;
26
- let expectedPlistObject: PlistDictionary;
27
-
28
- before(function () {
29
- sampleXmlPlistPath = path.join(FIXTURES_PATH, 'sample.xml.plist');
30
- sampleXmlPlistContent = fs.readFileSync(sampleXmlPlistPath, 'utf8');
31
-
32
- sampleBinaryPlistPath = path.join(FIXTURES_PATH, 'sample.binary.plist');
33
- sampleBinaryPlistContent = fs.readFileSync(sampleBinaryPlistPath);
34
-
35
- // Define the expected object structure that should match our XML plist
36
- expectedPlistObject = {
37
- stringValue: 'Hello, World!',
38
- integerValue: 42,
39
- realValue: 3.14159,
40
- booleanTrue: true,
41
- booleanFalse: false,
42
- dateValue: new Date('2023-01-01T12:00:00Z'),
43
- dataValue: Buffer.from('Hello, World!'),
44
- arrayValue: ['Item 1', 'Item 2', 3],
45
- dictValue: {
46
- nestedKey: 'Nested Value',
47
- nestedArray: [1, 2],
48
- },
49
- specialChars: '<Hello & World>',
50
- };
51
- });
52
-
53
- describe('XML Plist Functions', function () {
54
- it('should parse XML plists correctly', function () {
55
- const result = parseXmlPlist(sampleXmlPlistContent);
56
-
57
- // Basic types
58
- expect(result).to.be.an('object');
59
- expect(result).to.have.property('stringValue', 'Hello, World!');
60
- expect(result).to.have.property('integerValue', 42);
61
- expect(result)
62
- .to.have.property('realValue')
63
- .that.is.closeTo(3.14159, 0.00001);
64
- expect(result).to.have.property('booleanTrue', true);
65
- expect(result).to.have.property('booleanFalse', false);
66
-
67
- // Complex types
68
- expect(result)
69
- .to.have.property('arrayValue')
70
- .that.is.an('array')
71
- .with.lengthOf(3);
72
- expect(result).to.have.property('dictValue').that.is.an('object');
73
- expect(result).to.have.property('specialChars', '<Hello & World>');
74
-
75
- // Error handling
76
- expect(() => parseXmlPlist('not a valid xml')).to.throw();
77
- });
78
-
79
- it('should create XML plists correctly', function () {
80
- const xmlContent = createXmlPlist(expectedPlistObject);
81
-
82
- // Check structure
83
- expect(xmlContent).to.include('<?xml version="1.0" encoding="UTF-8"?>');
84
- expect(xmlContent).to.include('<!DOCTYPE plist');
85
- expect(xmlContent).to.include('<plist version="1.0">');
86
-
87
- // Check content
88
- expect(xmlContent).to.include('<key>stringValue</key>');
89
- expect(xmlContent).to.include('<string>Hello, World!</string>');
90
- expect(xmlContent).to.include('<key>integerValue</key>');
91
- expect(xmlContent).to.include('<integer>42</integer>');
92
- expect(xmlContent).to.include('&lt;Hello &amp; World&gt;');
93
-
94
- // Round-trip test
95
- const parsedBack = parseXmlPlist(xmlContent);
96
- expect(parsedBack).to.have.property('stringValue', 'Hello, World!');
97
- expect(parsedBack).to.have.property('integerValue', 42);
98
- });
99
- });
100
-
101
- describe('Binary Plist Functions', function () {
102
- it('should detect, create and parse binary plists', function () {
103
- // Detection
104
- const binaryPlist = createBinaryPlist(expectedPlistObject);
105
- expect(isBinaryPlist(binaryPlist)).to.be.true;
106
- expect(isBinaryPlist(Buffer.from(sampleXmlPlistContent))).to.be.false;
107
-
108
- // Create and verify
109
- expect(Buffer.isBuffer(binaryPlist)).to.be.true;
110
- expect(binaryPlist.slice(0, 6).toString()).to.equal('bplist');
111
-
112
- // Parse
113
- const parsedObj = parseBinaryPlist(sampleBinaryPlistContent) as Record<
114
- string,
115
- any
116
- >;
117
- expect(parsedObj).to.be.an('object');
118
- expect(parsedObj).to.have.property('stringValue', 'Hello, World!');
119
- expect(parsedObj).to.have.property('integerValue', 42);
120
- expect(parsedObj)
121
- .to.have.property('realValue')
122
- .that.is.closeTo(3.14159, 0.00001);
123
- expect(parsedObj).to.have.property('booleanTrue', true);
124
- expect(parsedObj).to.have.property('booleanFalse', false);
125
- });
126
- });
127
-
128
- describe('Unified Plist Functions', function () {
129
- it('should auto-detect and parse both XML and binary plists', function () {
130
- // XML parsing
131
- const xmlResult = parsePlist(sampleXmlPlistContent) as Record<
132
- string,
133
- any
134
- >;
135
- expect(xmlResult).to.be.an('object');
136
- expect(xmlResult).to.have.property('stringValue', 'Hello, World!');
137
- expect(xmlResult).to.have.property('integerValue', 42);
138
-
139
- // Binary parsing
140
- const binaryResult = parsePlist(sampleBinaryPlistContent) as Record<
141
- string,
142
- any
143
- >;
144
- expect(binaryResult).to.be.an('object');
145
- expect(binaryResult).to.have.property('stringValue', 'Hello, World!');
146
- expect(binaryResult).to.have.property('integerValue', 42);
147
-
148
- // Error handling
149
- expect(() => parsePlist('not a plist')).to.throw();
150
- });
151
-
152
- it('should create plists in both formats', function () {
153
- // Default XML creation
154
- const xmlResult = createPlist(expectedPlistObject);
155
- expect(xmlResult).to.be.a('string');
156
- expect(xmlResult as string).to.include('<?xml version="1.0"');
157
-
158
- // Binary creation
159
- const binaryResult = createPlist(expectedPlistObject, true);
160
- expect(Buffer.isBuffer(binaryResult)).to.be.true;
161
- expect(isBinaryPlist(binaryResult as Buffer)).to.be.true;
162
- });
163
- });
164
-
165
- describe('Edge Cases and Data Types', function () {
166
- it('should handle various data types and edge cases', function () {
167
- const complexObj: PlistDictionary = {
168
- nullValue: null,
169
- emptyString: '',
170
- zero: 0,
171
- negativeNumber: -42,
172
- largeNumber: 9007199254740991, // Max safe integer
173
- emptyArray: [],
174
- emptyDict: {},
175
- booleanArray: [true, false, true],
176
- mixedArray: [1, 'string', true, null, { key: 'value' }],
177
- };
178
-
179
- // Test round-trip through XML format
180
- const xmlResult = createXmlPlist(complexObj);
181
- const parsedXmlObj = parseXmlPlist(xmlResult) as Record<string, any>;
182
-
183
- // Verify key data types are preserved
184
- expect(parsedXmlObj).to.have.property('emptyString', '');
185
- expect(parsedXmlObj).to.have.property('zero', 0);
186
- expect(parsedXmlObj).to.have.property('negativeNumber', -42);
187
- expect(parsedXmlObj).to.have.property('largeNumber', 9007199254740991);
188
- expect(parsedXmlObj)
189
- .to.have.property('emptyArray')
190
- .that.is.an('array')
191
- .with.lengthOf(0);
192
- expect(parsedXmlObj).to.have.property('emptyDict').that.is.an('object');
193
- expect(parsedXmlObj)
194
- .to.have.property('booleanArray')
195
- .that.is.an('array')
196
- .with.lengthOf(3);
197
-
198
- // Empty object test
199
- const emptyObj = {};
200
- const emptyXmlResult = createXmlPlist(emptyObj);
201
- const parsedEmptyXml = parseXmlPlist(emptyXmlResult);
202
- expect(parsedEmptyXml).to.deep.equal({});
203
- });
204
- });
205
- });
@@ -1,90 +0,0 @@
1
- import { expect } from 'chai';
2
-
3
- import { parsePlist as parseXmlPlist } from '../../../src/lib/plist/plist-parser.js';
4
- import {
5
- cleanXmlWithReplacementChar,
6
- findTagsAroundPosition,
7
- } from '../../../src/lib/plist/utils.js';
8
- import type { PlistDictionary } from '../../../src/lib/types.js';
9
-
10
- describe('Tag Position Handling', function () {
11
- describe('findTagsAroundPosition', function () {
12
- it('should correctly find tags around a position', function () {
13
- const xml = '<root><child>text</child></root>';
14
-
15
- const position = xml.indexOf('text') + 2;
16
- const { beforeTag, afterTag } = findTagsAroundPosition(xml, position);
17
-
18
- expect(beforeTag).to.not.be.null;
19
- expect(beforeTag?.tagName).to.equal('child');
20
- expect(beforeTag?.isOpening).to.be.true;
21
-
22
- expect(afterTag).to.not.be.null;
23
- expect(afterTag?.tagName).to.equal('child');
24
- expect(afterTag?.isOpening).to.be.false;
25
- });
26
-
27
- it('should handle the case where prevTagPos >= 0 && nextTagPos > prevTagPos', function () {
28
- const xml = '<root><child>text</child> <next>more</next></root>';
29
-
30
- const position = xml.indexOf('</child>') + '</child>'.length;
31
- const { beforeTag, afterTag } = findTagsAroundPosition(xml, position);
32
-
33
- expect(beforeTag).to.not.be.null;
34
- expect(beforeTag?.tagName).to.equal('child');
35
- expect(beforeTag?.isOpening).to.be.false;
36
-
37
- expect(afterTag).to.not.be.null;
38
- expect(afterTag?.tagName).to.equal('next');
39
- expect(afterTag?.isOpening).to.be.true;
40
-
41
- expect(beforeTag?.end).to.be.lessThanOrEqual(position);
42
- expect(afterTag?.start).to.be.greaterThan(position);
43
- expect(afterTag?.start).to.be.greaterThan(beforeTag?.end || 0);
44
- });
45
-
46
- it('should handle the case where there is a replacement character between tags', function () {
47
- const xml = '<root><child>text</child>�<next>more</next></root>';
48
-
49
- const position = xml.indexOf('�');
50
- const { beforeTag, afterTag } = findTagsAroundPosition(xml, position);
51
-
52
- expect(beforeTag).to.not.be.null;
53
- expect(beforeTag?.tagName).to.equal('child');
54
- expect(beforeTag?.isOpening).to.be.false;
55
-
56
- expect(afterTag).to.not.be.null;
57
- expect(afterTag?.tagName).to.equal('next');
58
- expect(afterTag?.isOpening).to.be.true;
59
-
60
- const cleanedXml = cleanXmlWithReplacementChar(xml, position);
61
-
62
- expect(cleanedXml).to.not.include('�');
63
- expect(cleanedXml).to.equal(
64
- '<root><child>text</child><next>more</next></root>',
65
- );
66
- });
67
- });
68
-
69
- describe('XML Cleaning with Unclosed Tags', function () {
70
- it('should handle XML with unclosed tags', function () {
71
- const xml =
72
- '<?xml version="1.0" encoding="UTF-8"?><plist><dict><key>test</key><string>value</string></dict>';
73
-
74
- try {
75
- parseXmlPlist(xml);
76
- expect.fail('Should have thrown an error for unclosed tag');
77
- } catch (error) {
78
- expect(error).to.exist;
79
- }
80
- });
81
-
82
- it('should handle XML with extra content at the end', function () {
83
- const xml =
84
- '<?xml version="1.0" encoding="UTF-8"?><plist><dict><key>test</key><string>value</string></dict></plist>extra content';
85
-
86
- const result = parseXmlPlist(xml) as PlistDictionary;
87
- expect(result).to.have.property('test', 'value');
88
- });
89
- });
90
- });
@@ -1,227 +0,0 @@
1
- import { expect } from 'chai';
2
- import fs from 'fs';
3
- import path from 'path';
4
- import { fileURLToPath } from 'url';
5
-
6
- import { isBinaryPlist } from '../../../src/lib/plist/binary-plist-parser.js';
7
- import { parsePlist } from '../../../src/lib/plist/unified-plist-parser.js';
8
- import type { PlistDictionary } from '../../../src/lib/types.js';
9
-
10
- // Get the directory name
11
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
12
- const FIXTURES_PATH = path.join(__dirname, 'fixtures');
13
-
14
- describe('Unified Plist Parser', function () {
15
- let sampleXmlPlistPath: string;
16
- let sampleXmlPlistContent: string;
17
- let sampleBinaryPlistPath: string;
18
- let sampleBinaryPlistContent: Buffer;
19
-
20
- before(function () {
21
- sampleXmlPlistPath = path.join(FIXTURES_PATH, 'sample.xml.plist');
22
- sampleXmlPlistContent = fs.readFileSync(sampleXmlPlistPath, 'utf8');
23
-
24
- sampleBinaryPlistPath = path.join(FIXTURES_PATH, 'sample.binary.plist');
25
- sampleBinaryPlistContent = fs.readFileSync(sampleBinaryPlistPath);
26
- });
27
-
28
- describe('Format Detection and Parsing', function () {
29
- it('should correctly detect and parse XML plists', function () {
30
- // Test with string input
31
- const resultFromString = parsePlist(
32
- sampleXmlPlistContent,
33
- ) as PlistDictionary;
34
- expect(resultFromString).to.be.an('object');
35
- expect(resultFromString).to.have.property('stringValue', 'Hello, World!');
36
- expect(resultFromString).to.have.property('integerValue', 42);
37
-
38
- // Test with Buffer input (converted from string)
39
- const xmlBuffer = Buffer.from(sampleXmlPlistContent, 'utf8');
40
- const resultFromBuffer = parsePlist(xmlBuffer) as PlistDictionary;
41
- expect(resultFromBuffer).to.be.an('object');
42
- expect(resultFromBuffer).to.have.property('stringValue', 'Hello, World!');
43
- });
44
-
45
- it('should correctly detect and parse binary plists', function () {
46
- // Verify it's actually a binary plist
47
- expect(isBinaryPlist(sampleBinaryPlistContent)).to.be.true;
48
-
49
- // Parse the binary plist
50
- const result = parsePlist(sampleBinaryPlistContent) as PlistDictionary;
51
- expect(result).to.be.an('object');
52
- expect(result).to.have.property('stringValue', 'Hello, World!');
53
- expect(result).to.have.property('integerValue', 42);
54
- });
55
-
56
- it('should throw an error for invalid plist data', function () {
57
- try {
58
- parsePlist('not a plist at all');
59
- expect.fail('Should have thrown an error for invalid data');
60
- } catch (error) {
61
- expect(error).to.exist;
62
- }
63
-
64
- try {
65
- parsePlist(Buffer.from('not a plist at all'));
66
- expect.fail('Should have thrown an error for invalid data buffer');
67
- } catch (error) {
68
- expect(error).to.exist;
69
- }
70
-
71
- try {
72
- parsePlist('');
73
- expect.fail('Should have thrown an error for empty string');
74
- } catch (error) {
75
- expect(error).to.exist;
76
- }
77
-
78
- try {
79
- parsePlist(Buffer.alloc(0));
80
- expect.fail('Should have thrown an error for empty buffer');
81
- } catch (error) {
82
- expect(error).to.exist;
83
- }
84
-
85
- try {
86
- parsePlist('<plist><dict><key>test</key></dict></plist>');
87
- expect.fail('Should have thrown an error for malformed XML');
88
- } catch (error) {
89
- expect(error).to.exist;
90
- }
91
- });
92
- });
93
-
94
- describe('Edge Cases', function () {
95
- it('should handle XML with processing instructions', function () {
96
- const xmlWithPI = `<?xml version="1.0" encoding="UTF-8"?>
97
- <?xml-stylesheet type="text/css" href="style.css"?>
98
- <plist version="1.0">
99
- <dict>
100
- <key>test</key>
101
- <string>value</string>
102
- </dict>
103
- </plist>`;
104
-
105
- const result = parsePlist(xmlWithPI) as PlistDictionary;
106
- expect(result).to.have.property('test', 'value');
107
- });
108
-
109
- it('should handle XML with DOCTYPE declarations', function () {
110
- const xmlWithDoctype = `<?xml version="1.0" encoding="UTF-8"?>
111
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
112
- <plist version="1.0">
113
- <dict>
114
- <key>test</key>
115
- <string>value</string>
116
- </dict>
117
- </plist>`;
118
-
119
- const result = parsePlist(xmlWithDoctype) as PlistDictionary;
120
- expect(result).to.have.property('test', 'value');
121
- });
122
-
123
- it('should handle XML with Unicode characters', function () {
124
- const xmlWithUnicode = `<?xml version="1.0" encoding="UTF-8"?>
125
- <plist version="1.0">
126
- <dict>
127
- <key>unicodeKey</key>
128
- <string>こんにちは世界</string>
129
- </dict>
130
- </plist>`;
131
-
132
- const result = parsePlist(xmlWithUnicode) as PlistDictionary;
133
- expect(result).to.have.property('unicodeKey', 'こんにちは世界');
134
- });
135
-
136
- it('should handle XML with special characters that need escaping', function () {
137
- const xmlWithSpecialChars = `<?xml version="1.0" encoding="UTF-8"?>
138
- <plist version="1.0">
139
- <dict>
140
- <key>specialChars</key>
141
- <string>&lt;Hello &amp; World&gt;</string>
142
- </dict>
143
- </plist>`;
144
-
145
- const result = parsePlist(xmlWithSpecialChars) as PlistDictionary;
146
- expect(result).to.have.property('specialChars', '<Hello & World>');
147
- });
148
- });
149
-
150
- describe('Robustness Tests', function () {
151
- it('should handle XML with extra whitespace', function () {
152
- const xmlWithWhitespace = `
153
- <?xml version="1.0" encoding="UTF-8"?>
154
-
155
- <plist version="1.0">
156
- <dict>
157
- <key> spaced key </key>
158
- <string> spaced value </string>
159
- </dict>
160
- </plist>
161
-
162
- `;
163
-
164
- const result = parsePlist(xmlWithWhitespace) as PlistDictionary;
165
- expect(result).to.have.property(' spaced key ', ' spaced value ');
166
- });
167
-
168
- it('should handle XML with comments', function () {
169
- const xmlWithComments = `<?xml version="1.0" encoding="UTF-8"?>
170
- <!-- This is a comment -->
171
- <plist version="1.0">
172
- <dict>
173
- <!-- Another comment -->
174
- <key>commentedKey</key>
175
- <string>value</string> <!-- End comment -->
176
- </dict>
177
- </plist>`;
178
-
179
- const result = parsePlist(xmlWithComments) as PlistDictionary;
180
- expect(result).to.have.property('commentedKey', 'value');
181
- });
182
-
183
- it('should handle XML with mixed line endings', function () {
184
- // Create XML with mixed line endings (CR, LF, CRLF)
185
- const xmlWithMixedLineEndings =
186
- '<?xml version="1.0" encoding="UTF-8"?>\r' +
187
- '<plist version="1.0">\n' +
188
- '<dict>\r\n' +
189
- '<key>test</key>\r' +
190
- '<string>value</string>\n' +
191
- '</dict>\r\n' +
192
- '</plist>';
193
-
194
- const result = parsePlist(xmlWithMixedLineEndings) as PlistDictionary;
195
- expect(result).to.have.property('test', 'value');
196
- });
197
-
198
- it('should handle XML with BOM (Byte Order Mark)', function () {
199
- const bomPrefix = Buffer.from([0xef, 0xbb, 0xbf]);
200
- const xmlContent = Buffer.from(
201
- '<?xml version="1.0" encoding="UTF-8"?><plist><dict><key>test</key><string>value</string></dict></plist>',
202
- );
203
- const xmlWithBOM = Buffer.concat([bomPrefix, xmlContent]);
204
-
205
- const result = parsePlist(xmlWithBOM) as PlistDictionary;
206
- expect(result).to.have.property('test', 'value');
207
- });
208
- });
209
-
210
- describe('Error Recovery', function () {
211
- it('should recover from XML with content before XML declaration', function () {
212
- const xmlWithPrefix =
213
- 'Some garbage data<?xml version="1.0" encoding="UTF-8"?><plist><dict><key>test</key><string>value</string></dict></plist>';
214
-
215
- const result = parsePlist(xmlWithPrefix) as PlistDictionary;
216
- expect(result).to.have.property('test', 'value');
217
- });
218
-
219
- it('should recover from XML with multiple XML declarations', function () {
220
- const xmlWithMultipleDeclarations =
221
- '<?xml version="1.0" encoding="UTF-8"?><?xml version="1.1"?><plist><dict><key>test</key><string>value</string></dict></plist>';
222
-
223
- const result = parsePlist(xmlWithMultipleDeclarations) as PlistDictionary;
224
- expect(result).to.have.property('test', 'value');
225
- });
226
- });
227
- });