/
integration-tests.js
1286 lines (1109 loc) · 54.9 KB
/
integration-tests.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const stream = require("stream");
const wtfnode = require("wtfnode");
const Corellium = require("../src/corellium").Corellium;
const { Input } = require("../src/input");
const CONFIGURATION = require("./config.json");
/** @typedef {import('../src/instance.js')} Instance */
/** @typedef {import('../src/project.js')} Project */
process.title = "integration-tests";
process.on("SIGUSR2", () => wtfnode.dump());
global.hookOrTestFailed = false;
function setFlagIfHookFailedDecorator(fn) {
return function () {
return Promise.resolve(fn.apply(this, arguments)).catch((error) => {
global.hookOrTestFailed = true;
throw error;
});
};
}
async function turnOff(instance) {
await instance.stop();
await instance.waitForState("off");
assert.strictEqual(instance.state, "off");
}
async function turnOn(instance) {
await instance.start();
await instance.waitForState("on");
assert.strictEqual(instance.state, "on");
}
describe("Corellium API", function () {
let BASE_LIFECYCLE_TIMEOUT = 0;
let BASE_SNAPSHOT_TIMEOUT = 0;
let INSTANCE_VERSIONS = [];
if (CONFIGURATION.testFlavor === "ranchu") {
this.slow(10000);
this.timeout(20000);
BASE_LIFECYCLE_TIMEOUT = 40000;
BASE_SNAPSHOT_TIMEOUT = 20000;
INSTANCE_VERSIONS = ["7.1.2", "8.1.0", "9.0.0", "10.0.0", "11.0.0", "12.0.0"];
} else {
this.slow(40000);
this.timeout(50000);
BASE_LIFECYCLE_TIMEOUT = 700000;
BASE_SNAPSHOT_TIMEOUT = 300000;
INSTANCE_VERSIONS = ["10.3.3", "11.4.1", "12.4.1", "13.7", "14.1"];
}
const instanceMap = new Map();
let corellium = null;
let loggedIn = false;
before(
"should have a configuration",
setFlagIfHookFailedDecorator(function () {
if (
CONFIGURATION.endpoint === undefined ||
CONFIGURATION.password === undefined ||
CONFIGURATION.project === undefined ||
CONFIGURATION.testFlavor === undefined ||
CONFIGURATION.username === undefined
) {
throw new Error(
"The configuration must include endpoint, username, password, project and testFlavor properties.",
);
}
}),
);
before(
"should log in",
setFlagIfHookFailedDecorator(async function () {
corellium = new Corellium(CONFIGURATION);
await corellium.login();
const token = await corellium.token;
assert(token && token.token, "Token was never set, login must have silently failed");
loggedIn = true;
}),
);
INSTANCE_VERSIONS.forEach((instanceVersion) => {
after(
setFlagIfHookFailedDecorator(async function () {
this.timeout(80000);
const instance = instanceMap.get(instanceVersion);
if (!instance) {
return;
}
// To facilitate debugging, don't destroy instances if a test or hook failed.
if (global.hookOrTestFailed) {
// Stop updating the instance. Otherwise the updater keeps at it and the
// integration tests don't terminate.
instance.project.updater.remove(instance);
return;
}
await instance.destroy();
await instance.waitForState("deleted");
}),
);
});
describe("projects", function () {
let project = /** @type {Project} */ (null);
before(
"should be logged in",
setFlagIfHookFailedDecorator(function () {
assert(loggedIn, "All tests will fail as login failed");
}),
);
it("lists projects", async function () {
project = await corellium.projects().then((projects) => {
const foundProject = projects.find(
(project) => project.info.name === CONFIGURATION.project,
);
assert(
foundProject !== undefined,
new Error(
`Your test configuration specifies a project named "${CONFIGURATION.project}", but no such project was found on ${CONFIGURATION.endpoint}`,
),
);
return foundProject;
});
});
it(`has room for ${INSTANCE_VERSIONS.length} new VMs (get quota / quotasUsed)`, async function () {
assert(project, "Unable to test as no project was returned from previous tests");
assert(project.quotas !== project.quotasUsed);
if (project.quotas.cores - project.quotasUsed.cores < 2 * INSTANCE_VERSIONS.length)
throw new Error(
`no room for an extra device to be made, please free at least ${
2 * INSTANCE_VERSIONS.length
} cores`,
);
});
INSTANCE_VERSIONS.forEach((instanceVersion) => {
it(`can start create ${instanceVersion}`, async function () {
assert(project, "Unable to test as no project was returned from previous tests");
const name = `API Test ${instanceVersion}`;
let instanceConfig = {};
if (CONFIGURATION.testFlavor === "ranchu") {
instanceConfig = {
flavor: CONFIGURATION.testFlavor,
name: name,
os: instanceVersion,
};
} else {
instanceConfig = {
flavor: CONFIGURATION.testFlavor,
name: name,
os: instanceVersion,
bootOptions: {
udid: "9564a02c6255d8c449a3f691aeb8296dd352f3d6",
},
};
}
const instance = await project.createInstance(instanceConfig);
instanceMap.set(instanceVersion, instance);
await instance.waitForState("creating");
assert.strictEqual(instance.flavor, CONFIGURATION.testFlavor);
assert.strictEqual(instance.name, name);
});
});
it("can list supported devices", async function () {
const supportedDevices = await corellium.supported();
const firmware = supportedDevices.find(
(device) => device.name === CONFIGURATION.testFlavor,
);
assert(firmware);
});
it("can get teams and users", async function () {
let teamsAndUsers = await corellium.getTeamsAndUsers();
teamsAndUsers.users.forEach((value, key) => {
assert.strictEqual(value, corellium._users.get(key));
});
teamsAndUsers.teams.forEach((value, key) => {
assert.strictEqual(value, corellium._teams.get(key));
});
});
it("can get roles", async function () {
const roles = await corellium.roles();
assert(roles, "Roles should not be undefined, even if there have been no roles");
});
// Not visible to cloud users with one project:
it("can add and remove keys", async function () {
let keyInfo = await project
.addKey(
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqpvRmc/JQoH9P6XVlHnod0wRCg+7iSGfpyoBoe+nWwp2iEqPyM7A2RzW7ZIX2FZmlD5ldR6Oj5Z+LUR/GXfCFQvpQkidL5htzGMoI59SwntpSMvHlFLOcbyS7VmI4MKbdIF+UrelPCcCJjOaZIFOJfNtuLWDx0L14jW/4wflzcj6Fd1rBTVh2SB3mvhsraOuv9an74zr/PMSHtpFnt5m4SYWpE4HLTf0FJksEe/Qda9jQu5i86Mhu6ewSAVccUDLzgz6E4i8hvSqfctcYGT7asqxsubPTpTPfuOkc3WOxlqZYnnAbpGh8NvCu9uC+5gfWRcLoyRBE4J2Y3wcfOueP example-key",
)
.then((projectKey) => {
assert(
projectKey.label === "example-key",
"label defaults to public key comment",
);
assert(
projectKey.fingerprint ===
"9c:71:e5:40:08:fb:cd:88:1b:6d:8e:4f:c0:4c:0f:dd",
);
return projectKey;
})
.catch((error) => {
throw error;
});
const keys = await project.keys();
assert(!!keys.find((key) => key.identifier === keyInfo.identifier));
await project.deleteKey(keyInfo.identifier);
});
it("can refresh", async function () {
let tempName = project.info.name;
await project.refresh();
assert(tempName === project.info.name);
});
INSTANCE_VERSIONS.forEach((instanceVersion) => {
it(`can getInstance ${instanceVersion}`, async function () {
const instanceFromMap = instanceMap.get(instanceVersion);
assert(instanceFromMap, "Instance failed to create, test will fail");
const instance = await project.getInstance(instanceFromMap.id);
assert(instance.id === instanceFromMap.id);
});
});
it("can get openvpn profile", async function () {
let expected = Buffer.from("client");
await project
.vpnConfig("ovpn", undefined)
.then((profile) => {
assert(profile.length > expected.length);
assert(profile.compare(expected, 0, expected.length, 0, expected.length) === 0);
return profile;
})
.catch((error) => {
// Hack to ignore onsite installs for this test
if (!error.toString().includes("500 Internal Server Error")) {
throw error;
}
console.log(
"Forcing pass, this does not appear to be a server which supports vpns",
);
return undefined;
});
});
it("can get tunnelblick profile", async function () {
let expected = Buffer.from("504b0304", "hex");
await project
.vpnConfig("tblk", undefined)
.then((profile) => {
assert(profile.length > expected.length);
assert(profile.compare(expected, 0, expected.length, 0, expected.length) === 0);
return profile;
})
.catch((error) => {
// Hack to ignore onsite installs for this test
if (!error.toString().includes("500 Internal Server Error")) {
throw error;
}
console.log(
"Forcing pass, this does not appear to be a server which supports vpns",
);
return undefined;
});
});
INSTANCE_VERSIONS.forEach((instanceVersion) => {
it(`can finish create ${instanceVersion}`, async function () {
this.slow(BASE_LIFECYCLE_TIMEOUT);
this.timeout(BASE_LIFECYCLE_TIMEOUT + 30000);
const instance = instanceMap.get(instanceVersion);
assert(instance, "Instance failed to create, test will fail");
await instance.finishRestore();
});
});
});
INSTANCE_VERSIONS.forEach((instanceVersion) => {
describe(`panics ${instanceVersion}`, function () {
before(
"should have an instance",
setFlagIfHookFailedDecorator(function () {
assert(
instanceMap.get(instanceVersion),
"No instances available for testing, tests will fail",
);
}),
);
it("can request panics", async function () {
const instance = instanceMap.get(instanceVersion);
const panics = instance.panics();
assert(panics, "Panics should not be undefined, even if there have been no panics");
});
it("can clear panics", async function () {
const instance = instanceMap.get(instanceVersion);
instance.clearPanics();
});
});
});
INSTANCE_VERSIONS.forEach((instanceVersion) => {
describe(`instances ${instanceVersion}`, function () {
before(
"should have an instance",
setFlagIfHookFailedDecorator(async function () {
assert(
instanceMap.get(instanceVersion),
"No instances available for testing, tests will fail",
);
const instance = instanceMap.get(instanceVersion);
await instance.waitForState("on");
}),
);
describe(`billing ${instanceVersion}`, function () {
it("can get rate information", async function () {
const instance = instanceMap.get(instanceVersion);
const rate = await instance.rate();
assert.strictEqual(
((rate.onRateMicrocents * (60 * 60 * 24)) / 1000000 / 100).toFixed(2) > 0,
true,
`'On' rate should be larger than 0`,
);
assert.strictEqual(
((rate.offRateMicrocents * (60 * 60 * 24)) / 1000000 / 100).toFixed(2) > 0,
true,
`'Off' rate should be larger than 0`,
);
});
});
describe(`device lifecycle ${instanceVersion}`, function () {
this.slow(BASE_LIFECYCLE_TIMEOUT / 2);
this.timeout(BASE_LIFECYCLE_TIMEOUT);
beforeEach(async function () {
const instance = instanceMap.get(instanceVersion);
await instance.update();
});
it("can pause", async function () {
const instance = instanceMap.get(instanceVersion);
await instance.waitForState("on");
await instance.pause();
await instance.waitForState("paused");
});
it("can unpause", async function () {
const instance = instanceMap.get(instanceVersion);
if (instance.state !== "paused") {
await instance.pause();
await instance.waitForState("paused");
}
await instance.unpause();
await instance.waitForState("on");
});
it("can reboot", async function () {
const instance = instanceMap.get(instanceVersion);
if (instance.state !== "on") {
await turnOn(instance);
}
await instance.reboot();
if (CONFIGURATION.testFlavor !== "ranchu") {
await instance.waitForAgentReady();
}
});
it("can stop", async function () {
const instance = instanceMap.get(instanceVersion);
if (instance.state !== "on") {
await turnOn(instance);
}
await turnOff(instance);
});
it("can start", async function () {
const instance = instanceMap.get(instanceVersion);
if (instance.state !== "off") {
await turnOff(instance);
}
await turnOn(instance);
});
});
describe(`snapshots ${instanceVersion}`, function () {
this.slow(BASE_SNAPSHOT_TIMEOUT);
this.timeout(BASE_SNAPSHOT_TIMEOUT * 2);
before(
"should have an up-to-date instance",
setFlagIfHookFailedDecorator(async function () {
const instance = instanceMap.get(instanceVersion);
await instance.update();
}),
);
it("has a fresh snapshot", async function () {
const instance = instanceMap.get(instanceVersion);
const snapshots = await instance.snapshots();
const fresh = snapshots.find((snap) => snap.fresh);
assert(fresh.status.created === true);
});
let latestSnapshot;
if (CONFIGURATION.testFlavor === "ranchu") {
it("refuses to take snapshot if instance is on", async function () {
const instance = instanceMap.get(instanceVersion);
if (instance.state !== "on") {
await turnOn(instance);
}
await assert.rejects(() => instance.takeSnapshot());
});
it("can take snapshot if instance is off", async function () {
const instance = instanceMap.get(instanceVersion);
if (instance.state !== "off") {
await turnOff(instance);
}
latestSnapshot = await instance.takeSnapshot();
while (latestSnapshot.status.created !== true) {
await latestSnapshot.update();
}
await turnOn(instance);
});
} else {
it("can take snapshot if instance is on", async function () {
const instance = instanceMap.get(instanceVersion);
latestSnapshot = await instance.takeSnapshot();
while (latestSnapshot.status.created !== true) {
await latestSnapshot.update();
}
});
}
it("can restore a snapshot", async function () {
assert(
latestSnapshot,
"This test cannot run because there is no latestSnapshot to use",
);
const instance = instanceMap.get(instanceVersion);
if (CONFIGURATION.testFlavor === "ranchu") {
if (instance.state !== "on") {
await turnOn(instance);
}
await latestSnapshot.restore();
await instance.waitForAgentReady();
} else {
await instance.pause();
await instance.waitForState("paused");
await latestSnapshot.restore();
await instance.waitForAgentReady();
}
});
it("can delete a snapshot", async function () {
assert(
latestSnapshot,
"This test cannot run because there is no latestSnapshot to use",
);
const instance = instanceMap.get(instanceVersion);
assert(
(await instance.snapshots()).some(
(snapshot) => snapshot.id === latestSnapshot.id,
),
);
if (instance.state !== "on") {
await turnOn(instance);
}
await latestSnapshot.delete();
while (
(await instance.snapshots()).some(
(snapshot) => snapshot.id === latestSnapshot.id,
)
);
});
after("should be on", async function () {
const instance = instanceMap.get(instanceVersion);
await turnOn(instance);
});
});
it("can take a screenshot", async function () {
const expected = Buffer.from("89504E470D0A1A0A", "hex");
const instance = instanceMap.get(instanceVersion);
await instance.takeScreenshot().then((png) => {
assert(png.length > expected.length);
assert(png.compare(expected, 0, expected.length, 0, expected.length) === 0);
});
});
it("can rename", async function () {
const instance = instanceMap.get(instanceVersion);
const instanceName = instance.name;
async function rename(name) {
await instance.rename(name);
await instance.update();
assert.strictEqual(instance.name, name);
}
await rename("test rename foo");
await rename(instanceName);
});
it("has a console log", async function () {
const instance = instanceMap.get(instanceVersion);
const log = await instance.consoleLog();
if (log === undefined) {
throw new Error("Unable to acquire any console log");
}
});
it("has a console", async function () {
const instance = instanceMap.get(instanceVersion);
const consoleStream = await instance.console();
// Wait for the socket to open before killing it,
// otherwise this will throw an error
consoleStream.socket.on("open", function () {
consoleStream.socket.close();
});
// When the socket closes, it will be safe to destroy the console duplexify object
consoleStream.socket.on("close", function () {
consoleStream.destroy();
});
});
it("can send input", async function () {
const input = new Input();
const instance = instanceMap.get(instanceVersion);
instance.sendInput(input.pressRelease("home"));
});
if (CONFIGURATION.testFlavor === "ranchu") {
// Peripherals/sensor are only supported for android currently
describe(`peripherals ${instanceVersion}`, function () {
before(
setFlagIfHookFailedDecorator(async function () {
this.timeout(BASE_LIFECYCLE_TIMEOUT + 60000);
const instance = instanceMap.get(instanceVersion);
await instance.waitForState("on");
}),
);
it("can get peripheral data", async function () {
const instance = instanceMap.get(instanceVersion);
let peripheralData = await instance.getPeripherals();
assert(
peripheralData !== undefined && Object.keys(peripheralData).length > 0,
);
});
it("can set and get updated peripheral data", async function () {
const instance = instanceMap.get(instanceVersion);
await instance.modifyPeripherals({ batteryCapacity: "42" });
let peripheralData = await instance.getPeripherals();
assert(
peripheralData !== undefined &&
parseInt(peripheralData.batteryCapacity) === 42,
);
});
});
}
describe(`agent ${instanceVersion}`, function () {
let agent;
let installSuccess = false;
before(
setFlagIfHookFailedDecorator(async function () {
this.timeout(BASE_LIFECYCLE_TIMEOUT + 60000);
const instance = instanceMap.get(instanceVersion);
await instance.waitForState("on");
await instance.waitForAgentReady();
}),
);
beforeEach(async function () {
const instance = instanceMap.get(instanceVersion);
if (agent === undefined || !agent.connected) {
agent = await instance.agent();
await agent.ready();
}
});
after(
setFlagIfHookFailedDecorator(async function () {
if (agent !== undefined && agent.connected) agent.disconnect();
}),
);
it("can list device apps", async function () {
let appList = await agent.appList();
assert(appList !== undefined && appList.length > 0);
});
it("can use shellExec", async function () {
let uname = await agent.shellExec("uname");
assert(uname.output !== undefined && uname.output.length > 0);
assert(uname["success"], true);
});
describe(`Files ${instanceVersion}`, function () {
let expectedData = Buffer.from("D1FF", "hex");
let testPath;
it("can get temp file", async function () {
testPath = await agent.tempFile();
});
it("can upload a file", async function () {
let rs = stream.Readable.from(expectedData);
let lastStatus;
try {
await agent.upload(testPath, rs, (_progress, status) => {
lastStatus = status;
});
} catch (err) {
assert(
false,
`Error uploading file during '${lastStatus} stage: ${err}`,
);
}
});
it("can stat a file", async function () {
let stat = await agent.stat(testPath);
assert.strictEqual(stat.name, testPath);
});
it("can change a files attributes", async function () {
await agent.changeFileAttributes(testPath, { mode: 511 });
let stat = await agent.stat(testPath);
assert.strictEqual(stat.mode, 33279);
});
it("can download files", async function () {
try {
let downloaded = await new Promise((resolve) => {
const rs = agent.download(testPath);
let bufs = [];
rs.on("data", function (chunk) {
bufs.push(chunk);
});
rs.on("end", function () {
resolve(Buffer.concat(bufs));
});
});
assert(Buffer.compare(downloaded, expectedData) === 0);
} catch (err) {
assert(false, `Error reading downloadable file ${err}`);
}
});
it("can delete files", async function () {
await agent.deleteFile(testPath).then((path) => {
assert(path === undefined);
});
// We should get an OperationFailed since the file is gone
try {
await agent.stat(testPath);
} catch (error) {
if (CONFIGURATION.testFlavor === "ranchu") {
assert(error.toString().includes("No such file or directory"));
} else {
assert(
error
.toString()
.includes("Stat of file '" + testPath + "' failed."),
);
}
}
});
});
describe(`configuration profiles ${instanceVersion}`, function () {
if (CONFIGURATION.testFlavor === "ranchu") {
// These are unimplemented on ranchu devices
it("cannot use profile/list", async function () {
assert.rejects(() => agent.profileList());
});
it("cannot use profile/install", async function () {
assert.rejects(() => agent.installProfile("test"));
});
it("cannot use profile/remove", async function () {
assert.rejects(() => agent.removeProfile("test"));
});
it("cannot use profile/get", async function () {
assert.rejects(() => agent.getProfile("test"));
});
} else {
let profileID = "TBA";
it.skip("can use profile/list", async function () {
await agent.profileList();
});
it.skip("can use profile/install", async function () {
var profile = fs.readFileSync(path.join(__dirname, "TBA.mobileconfig"));
await agent.installProfile(profile);
});
it.skip("can use profile/get", async function () {
await agent.getProfile(profileID);
});
it.skip("can use profile/remove", async function () {
await agent.removeProfile(profileID);
});
}
});
describe(`provisioning profiles ${instanceVersion}`, function () {
if (CONFIGURATION.testFlavor === "ranchu") {
// These are unimplemented on ranchu devices
it("cannot use provisioning/list", async function () {
assert.rejects(() => agent.listProvisioningProfiles());
});
it("cannot use provisioning/install", async function () {
assert.rejects(() => agent.installProvisioningProfile("test", true));
});
it("cannot use provisioning/remove", async function () {
assert.rejects(() => agent.removeProvisioningProfile("test"));
});
it("cannot use provisioning/preapprove", async function () {
assert.rejects(() => agent.preApproveProvisioningProfile());
});
} else {
let certID = "TBA";
let profileID = "TBA";
it.skip("can use provisioning/install", async function () {
var profile = fs.readFileSync(
path.join(__dirname, "embedded.mobileprovision"),
);
await agent.installProvisioningProfile(profile, true);
});
it.skip("can use provisioning/list", async function () {
await agent.listProvisioningProfiles();
});
it.skip("can use provisioning/remove", async function () {
await agent.removeProvisioningProfile(profileID);
});
it.skip("can use provisioning/preapprove", async function () {
await agent.preApproveProvisioningProfile(certID, profileID);
});
}
});
describe(`locks ${instanceVersion}`, function () {
if (CONFIGURATION.testFlavor === "ranchu") {
// These are unimplemented on ranchu devices
it("cannot use lock", async function () {
assert.rejects(() => agent.lockDevice());
});
it("cannot use unlock", async function () {
assert.rejects(() => agent.unlockDevice());
});
it("cannot use acquireDisableAutolockAssertion", async function () {
assert.rejects(() => agent.acquireDisableAutolockAssertion());
});
it("cannot use releaseDisableAutolockAssertion", async function () {
assert.rejects(() => agent.releaseDisableAutolockAssertion());
});
} else {
it("can use lock", async function () {
await agent.lockDevice();
});
it("can use unlock", async function () {
await agent.unlockDevice();
});
it("can use acquireDisableAutolockAssertion", async function () {
await agent.acquireDisableAutolockAssertion();
});
it("can use releaseDisableAutolockAssertion", async function () {
await agent.releaseDisableAutolockAssertion();
});
}
});
describe(`UI automation ${instanceVersion}`, function () {
if (CONFIGURATION.testFlavor === "ranchu") {
// These are unimplemented on ranchu devices
it("cannot use enableUIAutomation", async function () {
assert.rejects(() => agent.enableUIAutomation());
});
it("cannot use disableUIAutomation", async function () {
assert.rejects(() => agent.disableUIAutomation());
});
} else {
it("can use enableUIAutomation", async function () {
await agent.enableUIAutomation();
});
it("can use disableUIAutomation", async function () {
await agent.disableUIAutomation();
});
}
});
describe(`WiFi ${instanceVersion}`, function () {
if (CONFIGURATION.testFlavor === "ranchu") {
// These are unimplemented on ranchu devices
it("cannot use connectToWifi", async function () {
assert.rejects(() => agent.connectToWifi());
});
it("cannot use disconnectFromWifi", async function () {
assert.rejects(() => agent.disconnectFromWifi());
});
} else {
it("can use disconnectFromWifi", async function () {
await agent.disconnectFromWifi();
// Wait a bit to avoid WiFi connection race on some devices
await new Promise((resolve) => setTimeout(resolve, 1000));
});
it("can use connectToWifi", async function () {
await agent.connectToWifi();
});
}
});
let bundleID = "";
if (CONFIGURATION.testFlavor === "ranchu") bundleID = "com.corellium.test.app";
else bundleID = "com.corellium.Red";
describe(`Applications ${instanceVersion}`, function () {
it("can install a signed apk/ipa", function () {
this.slow(50000);
this.timeout(100000);
let appFile = "";
if (CONFIGURATION.testFlavor === "ranchu") {
appFile = "api-test.apk";
} else {
appFile = "Red.ipa";
}
return agent
.installFile(fs.createReadStream(path.join(__dirname, appFile)))
.then(() => (installSuccess = true));
});
it("can run an app", async function () {
assert(
installSuccess,
"This test cannot run because application installation failed",
);
await agent.run(bundleID);
});
it("can kill an app", async function () {
assert(
installSuccess,
"This test cannot run because application installation failed",
);
await agent.kill(bundleID);
});
});
describe(`crash watcher ${instanceVersion}`, function () {
let crashListener;
before(
setFlagIfHookFailedDecorator(async function () {
const instance = instanceMap.get(instanceVersion);
await instance.waitForState("on");
await instance.waitForAgentReady();
crashListener = await instance.newAgent();
}),
);
after(
setFlagIfHookFailedDecorator(async function () {
if (crashListener !== undefined && crashListener.connected)
crashListener.disconnect();
}),
);
it("can catch an expected crash", function () {
return new Promise((resolve) => {
assert(
installSuccess,
"This test cannot run because application installation failed",
);
let targetLine = "";
if (CONFIGURATION.testFlavor === "ranchu") {
targetLine = "com.corellium.test.app";
} else {
targetLine = "com.apple.Maps";
}
return crashListener.ready().then(() => {
crashListener
.crashes(targetLine, (err, crashReport) => {
assert(!err, err);
assert(
crashReport !== undefined,
"The crash report is undefined",
);
assert(
crashReport.includes(targetLine),
`The crash reported doesn't include "${targetLine}":\n\n${crashReport}`,
);
resolve();
})
.catch((error) => {
if (
error.message &&
error.message.includes("disconnected")
) {
return;
}
throw error;
});
if (CONFIGURATION.testFlavor === "ranchu") {
return agent.runActivity(
"com.corellium.test.app",
"com.corellium.test.app/com.corellium.test.app.CrashActivity",
);
} else {
return agent.run("com.apple.Maps");
}
});
});
});
});
describe(`SSL pinning control ${instanceVersion}`, function () {
if (CONFIGURATION.testFlavor === "ranchu") {
// These are unimplemented on ranchu devices
it("cannot use enableSSLPinning", async function () {
assert.rejects(() => agent.enableSSLPinning());
});