This repository has been archived by the owner on Mar 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
test_webapp.py
1447 lines (1267 loc) · 49.2 KB
/
test_webapp.py
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
# -*- coding: utf-8 -*-
import os
import tempfile
import types
import json
from mock import patch
from nose.tools import eq_
from helper import TestCase
import appvalidator.constants
from appvalidator.errorbundle import ErrorBundle
from appvalidator.specs.webapps import WebappSpec
import appvalidator.webapp
class TestWebappAccessories(TestCase):
"""
Test that helper functions for webapp manifests work as they are intended
to.
"""
def test_path(self):
"""Test that paths are tested properly for allowances."""
s = WebappSpec("{}", ErrorBundle())
eq_(s._path_valid("*"), False)
eq_(s._path_valid("*", can_be_asterisk=True), True)
eq_(s._path_valid("/foo/bar"), False)
eq_(s._path_valid("/foo/bar", can_be_absolute=True), True)
eq_(s._path_valid("//foo/bar"), False)
eq_(s._path_valid("//foo/bar", can_be_absolute=True), False)
eq_(s._path_valid("//foo/bar", can_be_relative=True), False)
eq_(s._path_valid("http://asdf/"), False)
eq_(s._path_valid("https://asdf/"), False)
eq_(s._path_valid("ftp://asdf/"), False)
eq_(s._path_valid("http://asdf/", can_have_protocol=True), True)
eq_(s._path_valid("https://asdf/", can_have_protocol=True), True)
# No FTP for you!
eq_(s._path_valid("ftp://asdf/", can_have_protocol=True), False)
eq_(s._path_valid("data:asdf"), False)
eq_(s._path_valid("data:asdf", can_be_data=True), True)
class WebappBaseTestCase(TestCase):
def setUp(self):
super(WebappBaseTestCase, self).setUp()
self.listed = False
descr = "Exciting Open Web development action!"
descr += (1024 - len(descr)) * "_"
self.data = {
"version": "1.0",
"name": "MozBall",
"description": descr,
"icons": {
"32": "/img/icon-32.png",
"128": "/img/icon-128.png",
},
"developer": {
"name": "Mozilla Labs",
"url": "http://mozillalabs.com"
},
"installs_allowed_from": [
"https://appstore.mozillalabs.com",
"HTTP://mozilla.com/AppStore"
],
"launch_path": "/index.html",
"locales": {
"es": {
"name": "Foo Bar",
"description": "¡Acción abierta emocionante del desarrollo",
"developer": {
"url": "http://es.mozillalabs.com/"
}
},
"it": {
"description": "Azione aperta emozionante di sviluppo di!",
"developer": {
"url": "http://it.mozillalabs.com/"
}
}
},
"default_locale": "en",
"screen_size": {
"min_width": "600",
"min_height": "300"
},
"required_features": [
"touch", "geolocation", "webgl"
],
"orientation": "landscape",
"fullscreen": "true",
"type": "web",
"precompile": [
"game.js",
"database.js"
],
}
self.resources = [("app_type", "web")]
def make_privileged(self):
self.resources = [("app_type", "privileged"),
("packaged", True)]
self.data["type"] = "privileged"
def analyze(self):
"""Run the webapp tests on the file."""
self.detected_type = appvalidator.constants.PACKAGE_WEBAPP
self.setup_err()
for resource, value in self.resources:
self.err.save_resource(resource, value)
with tempfile.NamedTemporaryFile(delete=False) as t:
if isinstance(self.data, types.StringTypes):
t.write(self.data)
else:
t.write(json.dumps(self.data))
name = t.name
appvalidator.webapp.detect_webapp(self.err, name)
os.unlink(name)
class TestWebapps(WebappBaseTestCase):
def test_pass(self):
"""Test that a bland webapp file throws no errors."""
self.analyze()
self.assert_silent()
output = json.loads(self.err.render_json())
assert "manifest" in output and output["manifest"]
def test_bom(self):
"""Test that a plain webapp with a BOM won't throw errors."""
self.setup_err()
appvalidator.webapp.detect_webapp(
self.err, "tests/resources/unicodehelper/utf8_webapp.json")
self.assert_silent()
def test_fail_parse(self):
"""Test that invalid JSON is reported."""
self.data = "}{"
self.analyze()
self.assert_failed(with_errors=True)
def test_missing_required(self):
"""Test that missing the name element is a bad thing."""
del self.data["name"]
self.analyze()
self.assert_failed(with_errors=True)
def test_invalid_name(self):
"""Test that the name element is a string."""
self.data["name"] = ["foo", "bar"]
self.analyze()
self.assert_failed(with_errors=True)
def test_long_name(self):
"""Test that long names are flagged for truncation in Gaia."""
self.data["name"] = "This is a long name."
self.analyze()
self.assert_failed(with_warnings=True)
def test_long_name_with_locale(self):
"""Test that long localized names are flagged for truncation in
Gaia."""
self.data["locales"]["es"]["name"] = "This is a long name."
self.analyze()
self.assert_failed(with_warnings=True)
def test_role(self):
"""Test that app may contain role element."""
self.data["role"] = "input"
self.analyze()
self.assert_silent()
def test_langpack_role_need_languages_target(self):
"""Test that a language-target is needed for langpacks."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
"apps": {
"app://blah.gaiamobile.org/manifest.webapp": "/de/blah",
"app://email.gaiamobile.org/manifest.webapp": "/de/email"
}
}
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "missing_req_cond", ))
def test_langpack_languages_target_version_value(self):
"""Test that language-target version is in major.minor format."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2.5"
},
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
"apps": {
"app://blah.gaiamobile.org/manifest.webapp": "/de/blah",
"app://email.gaiamobile.org/manifest.webapp": "/de/email"
}
}
},
})
self.analyze()
self.assert_silent()
def test_langpack_languages_target_version_value_suffix(self):
"""Test that language-target version can have a dash suffix."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2.5-xyz"
},
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
"apps": {
"app://blah.gaiamobile.org/manifest.webapp": "/de/blah",
"app://email.gaiamobile.org/manifest.webapp": "/de/email"
}
}
},
})
self.analyze()
self.assert_silent()
def test_langpack_invalid_languages_target_type(self):
"""Test language-target type."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
"apps": {
"app://blah.gaiamobile.org/manifest.webapp": "/de/blah",
"app://email.gaiamobile.org/manifest.webapp": "/de/email"
}
}
},
"languages-target": ["2.2"], # Wrong type.
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "bad_type", ))
def test_langpack_invalid_languages_target_wrong_version_type(self):
"""Test that language-target version number has the correct type."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": 2.2 # Wrong type.
},
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
"apps": {
"app://blah.gaiamobile.org/manifest.webapp": "/de/blah",
"app://email.gaiamobile.org/manifest.webapp": "/de/email"
}
}
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "bad_type", ))
def test_langpack_invalid_languages_target_wrong_version_value(self):
"""Test that language-target version number has the correct value."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2" # Wrong value.
},
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
"apps": {
"app://blah.gaiamobile.org/manifest.webapp": "/de/blah",
"app://email.gaiamobile.org/manifest.webapp": "/de/email"
}
}
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "value_pattern_fail", ))
def test_langpack_invalid_languages_target(self):
"""Test that language-target manifest has the correct value."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://my.manifest.webapp": "2.2" # Manifest is incorrect.
},
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
"apps": {
"app://blah.gaiamobile.org/manifest.webapp": "/de/blah",
"app://email.gaiamobile.org/manifest.webapp": "/de/email"
}
}
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "not_allowed", ))
def test_langpack_role_need_languages_provided(self):
"""Test that a language-provided is needed for langpacks."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2.2"
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "missing_req_cond", ))
def test_langpack_invalid_languages_provided_should_not_be_empty(self):
"""Test that language-provided is not empty."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2.2"
},
"languages-provided": {}
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "empty", ))
def test_langpack_invalid_languages_provided_language_should_be_dict(self):
"""Test that language-provided children are dicts."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2.2"
},
"languages-provided": {
"de": []
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "bad_type", ))
def test_langpack_invalid_languages_provided_need_revision(self):
"""Test that language-provided revision is present."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2.2"
},
"languages-provided": {
"de": {
"name": "Deutsch",
"apps": {
"app://blah.gaiamobile.org/manifest.webapp": "/de/blah",
"app://email.gaiamobile.org/manifest.webapp": "/de/email"
}
}
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "missing_req", ))
def test_langpack_invalid_languages_provided_need_apps(self):
"""Test that language-provided apps is present."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2.2"
},
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
}
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "missing_req", ))
def test_langpack_invalid_languages_provided_apps(self):
"""Test that language-provided apps should be a dict."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2.2"
},
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
"apps": ["app://blah.gaiamobile.org/manifest.webapp"]
}
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "bad_type", ))
def test_langpack_invalid_languages_provided_apps_empty(self):
"""Test that language-provided apps should be non-empty dict."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2.2"
},
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
"apps": {
}
}
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "empty", ))
def test_langpack_invalid_languages_provided_revision(self):
"""Test that language-provided revision should be an int."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2.2"
},
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": "201411051234", # Wrong type, should be a int.
"apps": {
"app://blah.gaiamobile.org/manifest.webapp": "/de/blah",
"app://email.gaiamobile.org/manifest.webapp": "/de/email"
}
}
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "iterate", "bad_type", ))
def test_valid_langpack(self):
"""Test that a valid langpack passes validation."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2.2"
},
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
"apps": {
"app://blah.gaiamobile.org/manifest.webapp": "/de/blah",
"app://email.gaiamobile.org/manifest.webapp": "/de/email"
}
}
},
})
self.analyze()
self.assert_silent()
def test_valid_langpack_30(self):
"""Test that a valid langpack for FxOS 3.0 passes validation."""
self.resources.append(('packaged', True))
self.data.update({
"role": "langpack",
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "3.0"
},
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
"apps": {
"app://blah.gaiamobile.org/manifest.webapp": "/de/blah",
"app://email.gaiamobile.org/manifest.webapp": "/de/email"
}
}
},
})
self.analyze()
self.assert_silent()
def test_languages_target_invalid_for_webapps(self):
"""Test that language-target is invalid for non-langpack webapps."""
self.data.update({
"languages-target": {
"app://*.gaiamobile.org/manifest.webapp": "2.2"
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(
("spec", "webapp", "languages_target_langpacks", ))
def test_languages_provided_invalid_for_webapps(self):
"""Test that language-provided is invalid for non-langpack webapps."""
self.data.update({
"languages-provided": {
"de": {
"name": "Deutsch",
"revision": 201411051234,
"apps": {
"app://blah.gaiamobile.org/manifest.webapp": "/de/blah",
"app://email.gaiamobile.org/manifest.webapp": "/de/email"
}
}
},
})
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(
("spec", "webapp", "languages_provided_langpacks", ))
def test_invalid_role(self):
"""Test that app may not contain invalid role element."""
self.data["role"] = "hello"
self.analyze()
self.assert_failed(with_errors=True)
def test_empty_name(self):
"""Test that empty names are not allowed"""
self.data["name"] = None
self.analyze()
self.assert_failed(with_errors=True)
def test_maxlengths(self):
"""Test that certain elements are capped in length."""
self.data["name"] = "%" * 129
self.analyze()
self.assert_failed(with_errors=True)
def test_invalid_keys(self):
"""Test that unknown elements are flagged"""
self.data["foobar"] = "hello"
self.analyze()
self.assert_failed(with_warnings=True)
def test_warn_extra_keys(self):
"""Test that extra keys are flagged."""
self.data["locales"]["es"]["foo"] = "hello"
self.analyze()
self.assert_failed(with_warnings=True)
def test_icons_not_dict(self):
"""Test that the icons property is a dictionary."""
self.data["icons"] = ["data:foo/bar.png"]
self.analyze()
self.assert_failed(with_errors=True)
def test_icons_empty(self):
"""Test that no icons doesn't cause a traceback."""
self.data["icons"] = {}
self.analyze()
def test_icons_size(self):
"""Test that webapp icon sizes must be integers."""
self.data["icons"]["foo"] = "/foo.png"
self.analyze()
self.assert_failed(with_errors=True)
def test_icons_data_url(self):
"""Test that webapp icons can be data URLs."""
self.data["icons"]["128"] = "data:foo/bar.png"
self.analyze()
self.assert_silent()
def test_icons_relative_url(self):
"""Test that webapp icons cannot be relative URLs."""
self.data["icons"]["128"] = "foo/bar"
self.analyze()
self.assert_silent()
def test_icons_absolute_url(self):
"""Test that webapp icons can be absolute URLs."""
def test_icon(self, icon):
self.setUp()
self.data["icons"]["128"] = icon
self.analyze()
self.assert_silent()
for icon in ['/foo/bar', 'http://foo.com/bar', 'https://foo.com/bar']:
yield test_icon, self, icon
def test_icons_has_min_selfhosted(self):
del self.data["icons"]["128"]
self.analyze()
self.assert_silent()
def test_icons_has_min_listed(self):
self.listed = True
self.data["installs_allowed_from"] = \
appvalidator.constants.DEFAULT_WEBAPP_MRKT_URLS
del self.data["icons"]["128"]
self.analyze()
self.assert_failed(with_errors=True)
def test_no_locales(self):
"""Test that locales are not required."""
del self.data["locales"]
self.analyze()
self.assert_silent()
def test_no_default_locale_no_locales(self):
"""Test that locales are not required if no default_locale."""
del self.data["default_locale"]
del self.data["locales"]
self.analyze()
self.assert_silent()
def test_no_default_locale(self):
"""Test that locales require default_locale."""
del self.data["default_locale"]
self.analyze()
self.assert_failed(with_errors=True)
def test_invalid_locale_keys(self):
"""Test that locales only contain valid keys."""
# Banned locale element.
self.data["locales"]["es"]["default_locale"] = "foo"
self.analyze()
self.assert_failed(with_warnings=True)
def test_invalid_locale_keys_missing(self):
"""Test that locales aren't missing any required elements."""
del self.data["locales"]["es"]["name"]
self.analyze()
self.assert_silent()
def test_installs_allowed_from_not_list(self):
"""Test that the installs_allowed_from path is a list."""
self.data["installs_allowed_from"] = "foobar"
self.analyze()
self.assert_failed(with_errors=True)
def test_bad_installs_allowed_from_path(self):
"""Test that the installs_allowed_from path is valid."""
self.data["installs_allowed_from"].append("foo/bar")
self.analyze()
self.assert_failed(with_errors=True)
def test_no_amo_installs_allowed_from(self):
"""Test that installs_allowed_from should include Marketplace."""
# self.data does not include a marketplace URL by default.
self.listed = True
self.analyze()
self.assert_failed(with_errors=True)
def test_amo_iaf(self):
"""Test that the various Marketplace URLs work."""
# Test that the Marketplace production URL is acceptable.
self.setUp()
orig_iaf = self.data["installs_allowed_from"]
def test_iaf(self, iaf, url):
self.setUp()
self.data["installs_allowed_from"] = iaf + [url]
self.analyze()
self.assert_silent()
for url in appvalidator.constants.DEFAULT_WEBAPP_MRKT_URLS:
yield test_iaf, self, orig_iaf, url
def test_iaf_wildcard(self):
"""Test that installs_allowed_from can contain a wildcard."""
self.listed = True
self.data["installs_allowed_from"].append("*")
self.analyze()
self.assert_silent()
def test_installs_allowed_from_protocol(self):
"""
Test that if the developer includes a URL in the `installs_allowed_from`
parameter that is a valid Marketplace URL but uses HTTP instead of
HTTPS, we flag it as using the wrong protocol and not as an invalid URL.
"""
self.listed = True
bad_url = appvalidator.constants.DEFAULT_WEBAPP_MRKT_URLS[0].replace(
"https", "http")
self.data["installs_allowed_from"] = (bad_url, )
self.analyze()
self.assert_failed(with_errors=True)
self.assert_got_errid(("spec", "webapp", "iaf_bad_mrkt_protocol", ))
def test_launch_path_packaged(self):
"""Test that the launch path is present in a packaged app."""
del self.data["launch_path"]
self.resources.append(('packaged', True))
self.analyze()
self.assert_failed(with_errors=True)
def test_launch_path_not_string(self):
"""Test that the launch path is a string."""
self.data["launch_path"] = [123]
self.analyze()
self.assert_failed(with_errors=True)
def test_bad_launch_path(self):
"""Test that the launch path is valid."""
self.data["launch_path"] = "data:asdf"
self.analyze()
self.assert_failed(with_errors=True)
def test_bad_launch_path_protocol(self):
"""Test that the launch path cannot have a protocol."""
self.data["launch_path"] = "http://foo.com/bar"
self.analyze()
self.assert_failed(with_errors=True)
def test_bad_launch_path_absolute(self):
"""Test that the launch path is absolute."""
self.data["launch_path"] = "/foo/bar"
self.analyze()
self.assert_silent()
def test_widget_deprecated(self):
"""Test that the widget property is deprecated."""
self.data["widget"] = {
"path": "/butts.html",
"width": 100,
"height": 200
}
self.analyze()
self.assert_failed(with_errors=True)
def test_dev_missing(self):
"""Test that the developer property cannot be absent."""
del self.data["developer"]
self.analyze()
self.assert_failed(with_errors=True)
def test_dev_not_dict(self):
"""Test that the developer property must be a dict."""
self.data["developer"] = "foo"
self.analyze()
self.assert_failed(with_errors=True)
def test_bad_dev_keys(self):
"""Test that the developer keys are present."""
del self.data["developer"]["name"]
self.analyze()
self.assert_failed(with_errors=True)
def test_bad_dev_url(self):
"""Test that the developer keys are correct."""
self.data["developer"]["url"] = "foo"
self.analyze()
self.assert_failed(with_errors=True)
def test_screen_size_missing(self):
"""Test that the 'screen_size' property can be absent."""
del self.data["screen_size"]
self.analyze()
self.assert_silent()
def test_screen_size_is_dict(self):
"""Test that the 'screen_size' property must be a dict."""
self.data["screen_size"] = "foo"
self.analyze()
self.assert_failed(with_errors=True)
def test_screen_size_contains_pair(self):
"""Test that 'screen_size' must contain at least one key/value pair."""
self.data["screen_size"] = {}
self.analyze()
self.assert_failed(with_errors=True)
def test_bad_screen_size_key(self):
"""Test that the 'screen_size' keys are correct."""
self.data["screen_size"]["max_width"] = "500"
self.analyze()
self.assert_failed(with_warnings=True)
def test_bad_screen_size_value(self):
"""Test that the 'screen_size' keys are correct."""
self.data["screen_size"]["min_width"] = "500px"
self.analyze()
self.assert_failed(with_errors=True)
def test_required_screen_size_missing(self):
"""Test that the 'screen_size' property can be absent."""
del self.data["screen_size"]
self.analyze()
self.assert_silent()
def test_required_features_is_list(self):
"""Test that the 'required_features' property must be a list."""
self.data["required_features"] = "fart"
self.analyze()
self.assert_failed(with_errors=True)
def test_required_features_missing(self):
"""Test that 'required_features' can be absent."""
del self.data["required_features"]
self.analyze()
self.assert_silent()
def test_required_features_empty(self):
"""Test that 'required_features' can be an empty list."""
self.data["required_features"] = []
self.analyze()
self.assert_silent()
def test_orientation_missing(self):
"""Test that the 'orientation' property can be absent."""
del self.data["orientation"]
self.analyze()
self.assert_silent()
def test_orientation_list(self):
"""Test that the 'orientation' property can be absent."""
self.data["orientation"] = ["portrait", "portrait-secondary"]
self.analyze()
self.assert_silent()
def test_orientation_is_string(self):
"""Test that the 'orientation' property must be a string."""
self.data["orientation"] = {}
self.analyze()
self.assert_failed(with_errors=True)
def test_orientation_cannot_be_empty(self):
"""Test that 'orientation' cannot be an empty string."""
self.data["orientation"] = ""
self.analyze()
self.assert_failed(with_errors=True)
def test_orientation_valid_value(self):
"""Test that 'orientation' must have a valid value."""
def test_orientation(self, orientation):
self.setUp()
self.data["orientation"] = orientation
self.analyze()
self.assert_silent()
for key in ("portrait", "landscape", "portrait-secondary",
"landscape-secondary", "portrait-primary",
"landscape-primary"):
yield test_orientation, self, key
def test_orientation_bad_value(self):
"""Test that 'orientation' cannot have an invalid value."""
self.data["orientation"] = "fart"
self.analyze()
self.assert_failed(with_errors=True)
def test_orientation_empty_list(self):
"""Test that 'orientation' cannot be an empty list."""
self.data["orientation"] = []
self.analyze()
self.assert_failed(with_errors=True)
def test_orientation_list_invalid(self):
"""Test that 'orientation' cannot be a list with invalid values."""
self.data["orientation"] = ["fart"]
self.analyze()
self.assert_failed(with_errors=True)
def test_orientation_list_mixed(self):
"""Test that 'orientation' cannot be a list with mixed values."""
self.data["orientation"] = ["portrait", "fart", "landscape"]
self.analyze()
self.assert_failed(with_errors=True)
def test_orientation_list_type(self):
"""Test that 'orientation' cannot be a list with non-strings."""
self.data["orientation"] = ["portrait", 4]
self.analyze()
self.assert_failed(with_errors=True)
def test_inputs_dict_valid(self):
"""Test with 'inputs' entries throw no errors."""
self.data['inputs'] = {
'input1': {
'name': 'Symbols',
'description': 'Symbols Virtual Keyboard',
'launch_path': '/input1.html',
'types': ['text']
},
'siri': {
'name': 'Voice Control',
'description': 'Voice Control Input',
'launch_path': '/vc.html',
'types': ['text', 'url']
}
}
self.analyze()
self.assert_silent()
def test_inputs_dict_empty(self):
"""Test that 'inputs' may not be empty dict."""
self.data['inputs'] = {}
self.analyze()
self.assert_failed(with_errors=True)
def test_inputs_dict_entry_missing_name(self):
"""Test that 'inputs' with an entry missing 'name'."""
self.data['inputs'] = {
'input1': {
'description': 'Symbols Virtual Keyboard',
'launch_path': '/input1.html',
'types': ['text']
}
}
self.analyze()
self.assert_failed(with_errors=True)
def test_inputs_dict_entry_missing_description(self):
"""Test that 'inputs' with an entry missing 'description'."""
self.data['inputs'] = {
'input1': {
'name': 'Symbols',
'launch_path': '/input1.html',
'types': ['text']
}
}
self.analyze()
self.assert_failed(with_errors=True)
def test_inputs_dict_entry_missing_launch_path(self):
"""Test that 'inputs' with an entry missing 'launch_path'."""
self.data['inputs'] = {
'input1': {
'name': 'Symbols',
'description': 'Symbols Virtual Keyboard',
'types': ['text']
}
}
self.analyze()
self.assert_failed(with_errors=True)
def test_inputs_dict_entry_missing_types(self):
"""Test that 'inputs' with an entry missing 'types'."""
self.data['inputs'] = {
'input1': {
'name': 'Symbols',
'description': 'Symbols Virtual Keyboard',
'launch_path': '/input1.html'
}
}
self.analyze()
self.assert_failed(with_errors=True)
def test_inputs_dict_entry_empty_types(self):
"""Test that 'inputs' with an entry with empty 'types'."""
self.data['inputs'] = {
'input1': {
'name': 'Symbols',
'description': 'Symbols Virtual Keyboard',
'launch_path': '/input1.html',
'types': []
}
}
self.analyze()