-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
dockerValidator.test.ts
4683 lines (3763 loc) · 238 KB
/
dockerValidator.test.ts
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
/* --------------------------------------------------------------------------------------------
* Copyright (c) Remy Suen. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as assert from "assert";
import { Keyword } from "dockerfile-ast";
import { TextDocument } from 'vscode-languageserver-textdocument';
import { Diagnostic, DiagnosticSeverity, DiagnosticTag, uinteger } from 'vscode-languageserver-types';
import { DockerfileDiagnostic, Validator } from '../src/dockerValidator';
import { ValidationCode, ValidatorSettings, ValidationSeverity, validate } from '../src/main';
let source = "dockerfile-utils";
function createDocument(content: string): any {
return TextDocument.create("uri://host/Dockerfile.sample", "dockerfile", 1, content);
}
function validateDockerfile(content: string, settings?: ValidatorSettings) {
if (!settings) {
settings = {
deprecatedMaintainer: ValidationSeverity.IGNORE,
directiveCasing: ValidationSeverity.WARNING,
instructionCasing: ValidationSeverity.WARNING,
instructionCmdMultiple: ValidationSeverity.IGNORE,
instructionEntrypointMultiple: ValidationSeverity.IGNORE,
instructionHealthcheckMultiple: ValidationSeverity.IGNORE,
instructionWorkdirRelative: ValidationSeverity.WARNING,
};
}
return validate(content, settings);
}
function convertValidationSeverity(severity: ValidationSeverity): DiagnosticSeverity {
return severity === ValidationSeverity.ERROR ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning;
}
function assertDiagnostics(diagnostics: Diagnostic[], codes: ValidationCode[], functions: Function[], args: any[][]) {
assert.equal(diagnostics.length, codes.length);
diagnosticCheck: for (let diagnostic of diagnostics) {
for (let i = 0; i < codes.length; i++) {
if (diagnostic.code === codes[i]) {
args[i].unshift(diagnostic);
functions[i].apply(null, args[i]);
continue diagnosticCheck;
}
}
throw new Error("Diagnostic with code " + diagnostic.code + " not expected");
}
}
function assertNoSourceImage(diagnostic: Diagnostic, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.NO_SOURCE_IMAGE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_NoSourceImage());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, null);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertEmptyContinuationLine(diagnostic: Diagnostic, severity: DiagnosticSeverity, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.EMPTY_CONTINUATION_LINE);
assert.equal(diagnostic.severity, severity);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_EmptyContinuationLine());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, null);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertFlagAtLeastOne(diagnostic: Diagnostic, instructionLine: uinteger, flagName: string, flagValue: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.FLAG_AT_LEAST_ONE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_FlagAtLeastOne(flagName, flagValue));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertFlagDuplicate(diagnostic: Diagnostic, instructionLine: uinteger, flag: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.FLAG_DUPLICATE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_FlagDuplicate(flag));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertFlagInvalidDuration(diagnostic: Diagnostic, instructionLine: uinteger, flag: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.FLAG_INVALID_DURATION);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_FlagInvalidDuration(flag));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertFlagLessThan1ms(diagnostic: Diagnostic, instructionLine: uinteger, flag: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.FLAG_LESS_THAN_1MS);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_FlagLessThan1ms(flag));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertFlagMissingDuration(diagnostic: Diagnostic, instructionLine: uinteger, duration: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.FLAG_MISSING_DURATION);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_FlagMissingDuration(duration));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertFlagInvalidFrom(diagnostic: Diagnostic, instructionLine: uinteger, flag: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.FLAG_INVALID_FROM_VALUE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_FlagInvalidFromValue(flag));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertFlagExpectedBooleanValue(diagnostic: Diagnostic, instructionLine: uinteger, flag: string, value: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.FLAG_INVALID_LINK_VALUE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_FlagExpectedBooleanValue(flag, value));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertFlagMissingValue(diagnostic: Diagnostic, instructionLine: uinteger, flag: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.FLAG_MISSING_VALUE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_FlagMissingValue(flag));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertUnknownFlag(diagnostic: Diagnostic, instructionLine: uinteger, flag: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_FlagUnknown(flag));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertUnknownAddFlag(diagnostic: Diagnostic, instructionLine: uinteger, flag: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.UNKNOWN_ADD_FLAG);
assertUnknownFlag(diagnostic, instructionLine, flag, startLine, startCharacter, endLine, endCharacter);
}
function assertUnknownCopyFlag(diagnostic: Diagnostic, instructionLine: uinteger, flag: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.UNKNOWN_COPY_FLAG);
assertUnknownFlag(diagnostic, instructionLine, flag, startLine, startCharacter, endLine, endCharacter);
}
function assertFlagUnknownUnit(diagnostic: Diagnostic, instructionLine: uinteger, unit: string, duration: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.FLAG_UNKNOWN_UNIT);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_FlagUnknownUnit(unit, duration));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertUnknownFromFlag(diagnostic: Diagnostic, instructionLine: uinteger, flag: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.UNKNOWN_FROM_FLAG);
assertUnknownFlag(diagnostic, instructionLine, flag, startLine, startCharacter, endLine, endCharacter);
}
function assertUnknownHealthcheckFlag(diagnostic: Diagnostic, instructionLine: uinteger, flag: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.UNKNOWN_HEALTHCHECK_FLAG);
assertUnknownFlag(diagnostic, instructionLine, flag, startLine, startCharacter, endLine, endCharacter);
}
function assertBaseNameEmpty(diagnostic: Diagnostic, instructionLine: uinteger, name: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.BASE_NAME_EMPTY);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_BaseNameEmpty(name));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInvalidAs(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.INVALID_AS);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InvalidAs());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInvalidPort(diagnostic: Diagnostic, instructionLine: uinteger, port: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.INVALID_PORT);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InvalidPort(port));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInvalidProto(diagnostic: Diagnostic, instructionLine: uinteger, protocol: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.INVALID_PROTO);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InvalidProto(protocol));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInvalidReferenceFormat(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.INVALID_REFERENCE_FORMAT);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InvalidReferenceFormat());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInvalidStopSignal(diagnostic: Diagnostic, instructionLine: uinteger, signal: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.INVALID_SIGNAL);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InvalidSignal(signal));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInvalidSyntax(diagnostic: Diagnostic, instructionLine: uinteger, syntax: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.INVALID_SYNTAX);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InvalidSyntax(syntax));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertDirectiveCasing(diagnostic: Diagnostic, severity: DiagnosticSeverity, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.CASING_DIRECTIVE);
assert.equal(diagnostic.severity, severity);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_DirectiveCasing());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, null);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInstructionCasing(diagnostic: Diagnostic, severity: DiagnosticSeverity, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.CASING_INSTRUCTION);
assert.equal(diagnostic.severity, severity);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InstructionCasing());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInstructionExtraArgument(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.ARGUMENT_EXTRA);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InstructionExtraArgument());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInstructionMissingArgument(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.ARGUMENT_MISSING);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InstructionMissingArgument());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInstructionMultiple(diagnostic: Diagnostic, severity: DiagnosticSeverity, instructionLine: uinteger, instruction: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.MULTIPLE_INSTRUCTIONS);
assert.equal(diagnostic.severity, severity);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags.length, 1);
assert.strictEqual(diagnostic.tags[0], DiagnosticTag.Unnecessary);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InstructionMultiple(instruction));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertHealthcheckCmdArgumentMissing(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.HEALTHCHECK_CMD_ARGUMENT_MISSING);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_HealthcheckCmdArgumentMissing());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertHealthcheckTypeUnknown(diagnostic: Diagnostic, instructionLine: uinteger, type: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.UNKNOWN_TYPE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_HealthcheckTypeUnknown(type));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertADDDestinationNotDirectory(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.INVALID_DESTINATION);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_ADDDestinationNotDirectory());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertADDRequiresAtLeastTwoArguments(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.ARGUMENT_REQUIRES_AT_LEAST_TWO);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_ADDRequiresAtLeastTwoArguments());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertCOPYDestinationNotDirectory(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.INVALID_DESTINATION);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_COPYDestinationNotDirectory());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertCOPYRequiresAtLeastTwoArguments(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.ARGUMENT_REQUIRES_AT_LEAST_TWO);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_COPYRequiresAtLeastTwoArguments());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertENVRequiresTwoArguments(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.ARGUMENT_REQUIRES_TWO);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_ENVRequiresTwoArguments());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertHEALTHCHECKRequiresAtLeastOneArgument(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.ARGUMENT_REQUIRES_AT_LEAST_ONE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_HEALTHCHECKRequiresAtLeastOneArgument());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInstructionRequiresOneOrThreeArguments(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.ARGUMENT_REQUIRES_ONE_OR_THREE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InstructionRequiresOneOrThreeArguments());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInstructionUnnecessaryArgument(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.ARGUMENT_UNNECESSARY);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_HealthcheckNoneUnnecessaryArgument());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInstructionUnknown(diagnostic: Diagnostic, instructionLine: uinteger, instruction: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.UNKNOWN_INSTRUCTION);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InstructionUnknown(instruction));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInstructionJSONInSingleQuotes(diagnostic: Diagnostic, severity: DiagnosticSeverity, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.JSON_IN_SINGLE_QUOTES);
assert.equal(diagnostic.severity, severity);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InstructionJSONInSingleQuotes());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertOnbuildChainingDisallowed(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.ONBUILD_CHAINING_DISALLOWED);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_OnbuildChainingDisallowed());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertShellJsonForm(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.SHELL_JSON_FORM);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_ShellJsonForm());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertShellRequiresOne(diagnostic: Diagnostic, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.SHELL_REQUIRES_ONE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_ShellRequiresOne());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertOnbuildTriggerDisallowed(diagnostic: Diagnostic, instructionLine: uinteger, trigger: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.ONBUILD_TRIGGER_DISALLOWED);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_OnbuildTriggerDisallowed(trigger));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertDirectiveEscapeDuplicated(diagnostic: Diagnostic, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.DUPLICATED_ESCAPE_DIRECTIVE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags.length, 1);
assert.strictEqual(diagnostic.tags[0], DiagnosticTag.Unnecessary);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_DirectiveEscapeDuplicated());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, null);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertDirectiveEscapeInvalid(diagnostic: Diagnostic, value: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.INVALID_ESCAPE_DIRECTIVE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_DirectiveEscapeInvalid(value));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, null);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertDeprecatedMaintainer(diagnostic: Diagnostic, severity: DiagnosticSeverity, instructionLine: uinteger, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.DEPRECATED_MAINTAINER);
assert.equal(diagnostic.severity, severity);
assert.equal(diagnostic.source, source);
assert.equal(diagnostic.tags.length, 1);
assert.equal(diagnostic.tags[0], DiagnosticTag.Deprecated);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_DeprecatedMaintainer());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertSyntaxMissingEquals(diagnostic: Diagnostic, instructionLine: uinteger, argument: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.SYNTAX_MISSING_EQUALS);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_SyntaxMissingEquals(argument));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertSyntaxMissingNames(diagnostic: Diagnostic, instructionLine: uinteger, instrument: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.SYNTAX_MISSING_NAMES);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_SyntaxMissingNames(instrument));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertSyntaxMissingSingleQuote(diagnostic: Diagnostic, instructionLine: uinteger, key: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.SYNTAX_MISSING_SINGLE_QUOTE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_SyntaxMissingSingleQuote(key));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertSyntaxMissingDoubleQuote(diagnostic: Diagnostic, instructionLine: uinteger, key: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.SYNTAX_MISSING_DOUBLE_QUOTE);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_SyntaxMissingDoubleQuote(key));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertDuplicateBuildStageName(diagnostic: Diagnostic, instructionLine: uinteger, name: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.DUPLICATE_BUILD_STAGE_NAME);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_DuplicateBuildStageName(name));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertInvalidBuildStageName(diagnostic: Diagnostic, instructionLine: uinteger, name: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.INVALID_BUILD_STAGE_NAME);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_InvalidBuildStageName(name));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertVariableModifierUnsupported(diagnostic: Diagnostic, instructionLine: uinteger, variable: string, modifier: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.UNSUPPORTED_MODIFIER);
assert.equal(diagnostic.severity, DiagnosticSeverity.Error);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_VariableModifierUnsupported(variable, modifier));
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function assertWorkdirAbsolutePath(diagnostic: Diagnostic, instructionLine: uinteger, severity: DiagnosticSeverity, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
assert.equal(diagnostic.code, ValidationCode.WORKDIR_IS_NOT_ABSOLUTE);
assert.equal(diagnostic.severity, severity);
assert.equal(diagnostic.source, source);
assert.strictEqual(diagnostic.tags, undefined);
assert.equal(diagnostic.message, Validator.getDiagnosticMessage_WORKDIRPathNotAbsolute());
assert.strictEqual((diagnostic as DockerfileDiagnostic).instructionLine, instructionLine);
assert.equal(diagnostic.range.start.line, startLine);
assert.equal(diagnostic.range.start.character, startCharacter);
assert.equal(diagnostic.range.end.line, endLine);
assert.equal(diagnostic.range.end.character, endCharacter);
}
function testValidArgument(instruction: string, argument: string) {
let gaps = [ " ", "\t", " \\\n", " \\\r\n" ];
for (let gap of gaps) {
let diagnostics = validateDockerfile("FROM node\n" + instruction + gap + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + gap + argument + " ");
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + gap + argument + "\n");
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + gap + argument + "\r\n");
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + gap + argument + " \n");
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + gap + argument + " \r\n");
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + gap + argument + "\n ");
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + gap + argument + "\r\n ");
assert.equal(diagnostics.length, 0);
}
}
function testEscape(instruction: string, argumentFront: string, argumentBack: string) {
var argument = argumentFront + argumentBack;
let diagnostics = validateDockerfile("FROM node\n" + instruction + " \\\n" + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\\n " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + "\\\n " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\ \n" + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + "\\ \n " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\ \n " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\ \n " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\\t\n " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\\t\t\n " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\ \r " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\\t\r " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\\t\t\r " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\\r\n" + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + "\\\r\n " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\\r\n " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\ \r\n" + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + "\\ \r\n " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " \\ \r\n " + argument);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " " + argument + "\\\n");
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " " + argumentFront + "\\\n" + argumentBack);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " " + argumentFront + "\\\r\n" + argumentBack);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " " + argumentFront + "\\\r\n" + argumentBack);
assert.equal(diagnostics.length, 0);
diagnostics = validateDockerfile("FROM node\n" + instruction + " " + argumentFront + "\\\r\n" + argumentBack + "\n");
assert.equal(diagnostics.length, 0);
}
describe("Docker Validator Tests", function() {
describe("no content", function() {
it("empty file", function() {
let diagnostics = validateDockerfile("");
assert.equal(diagnostics.length, 1);
assertNoSourceImage(diagnostics[0], 0, 0, 0, 0);
});
it("whitespace only", function() {
let diagnostics = validateDockerfile(" \t\r\n");
assert.equal(diagnostics.length, 1);
assertNoSourceImage(diagnostics[0], 0, 0, 0, 0);
});
it("comments only", function() {
let diagnostics = validateDockerfile("# This is a comment");
assert.equal(diagnostics.length, 1);
assertNoSourceImage(diagnostics[0], 0, 0, 0, 0);
diagnostics = validateDockerfile("#=This is a comment");
assert.equal(diagnostics.length, 1);
assertNoSourceImage(diagnostics[0], 0, 0, 0, 0);
});
it("directive only", function() {
let diagnostics = validateDockerfile("# escape=`");
assert.equal(diagnostics.length, 1);
assertNoSourceImage(diagnostics[0], 0, 0, 0, 0);
diagnostics = validateDockerfile("# escape=\\");
assert.equal(diagnostics.length, 1);
assertNoSourceImage(diagnostics[0], 0, 0, 0, 0);
});
it("FROM in comment", function() {
let diagnostics = validateDockerfile("# FROM node");
assert.equal(diagnostics.length, 1);
assertNoSourceImage(diagnostics[0], 0, 0, 0, 0);
});
});
describe("UTF-8", () => {
function createUTF8Content(content: string): string {
return Buffer.from(`\ufeff${content}`, "UTF-8").toString();
}
it("simple", () => {
const diagnostics = validateDockerfile(createUTF8Content("FROM alpine"));
assert.equal(diagnostics.length, 0);
});
it("has directive", () => {
const diagnostics = validateDockerfile(createUTF8Content("#escape=`\nFROM alpine"));
assert.equal(diagnostics.length, 0);
});
});
function createUppercaseStyleTest(trigger: boolean) {
let onbuild = trigger ? "ONBUILD " : "";
let triggerLength = onbuild.length;
describe("uppercase style check", function() {
function testCasingStyle(mixed: string, argument: string) {
var length = mixed.length;
let diagnostics = validateDockerfile("FROM node\n" + onbuild + mixed.toUpperCase() + " " + argument);
if (trigger) {
switch (mixed.toUpperCase()) {
case "FROM":
case "MAINTAINER":
assert.equal(diagnostics.length, 1);
assertOnbuildTriggerDisallowed(diagnostics[0], 1, mixed.toUpperCase(), 1, triggerLength, 1, triggerLength + length);
break;
case "ONBUILD":
assert.equal(diagnostics.length, 1);
assertOnbuildChainingDisallowed(diagnostics[0], 1, 1, triggerLength, 1, triggerLength + length);
break;
default:
assert.equal(diagnostics.length, 0);
break;
}
} else {
assert.equal(diagnostics.length, 0);
}
diagnostics = validateDockerfile("FROM node\n" + onbuild + mixed.toLowerCase() + " " + argument);
if (trigger) {
switch (mixed.toUpperCase()) {
case "FROM":
case "MAINTAINER":
assert.equal(diagnostics.length, 2);
assertDiagnostics(diagnostics,
[ ValidationCode.ONBUILD_TRIGGER_DISALLOWED, ValidationCode.CASING_INSTRUCTION ],
[ assertOnbuildTriggerDisallowed, assertInstructionCasing ],
[ [ 1, mixed.toUpperCase(), 1, triggerLength, 1, triggerLength + length ],
[ DiagnosticSeverity.Warning, 1, 1, triggerLength, 1, triggerLength + length ] ]);
break;
case "ONBUILD":
assert.equal(diagnostics.length, 2);
assertDiagnostics(diagnostics,
[ ValidationCode.ONBUILD_CHAINING_DISALLOWED, ValidationCode.CASING_INSTRUCTION ],
[ assertOnbuildChainingDisallowed, assertInstructionCasing ],
[ [ 1, 1, triggerLength, 1, triggerLength + length ],
[ DiagnosticSeverity.Warning, 1, 1, triggerLength, 1, triggerLength + length ] ]);
break;
default:
assert.equal(diagnostics.length, 1);
assertInstructionCasing(diagnostics[0], DiagnosticSeverity.Warning, 1, 1, triggerLength, 1, triggerLength + length);
break;
}
} else {
assert.equal(diagnostics.length, 1);
assertInstructionCasing(diagnostics[0], DiagnosticSeverity.Warning, 1, 1, triggerLength, 1, triggerLength + length);
}
diagnostics = validateDockerfile("FROM node\n" + onbuild + mixed + " " + argument);
if (trigger) {
switch (mixed.toUpperCase()) {
case "FROM":
case "MAINTAINER":
assert.equal(diagnostics.length, 2);
assertDiagnostics(diagnostics,
[ ValidationCode.ONBUILD_TRIGGER_DISALLOWED, ValidationCode.CASING_INSTRUCTION ],
[ assertOnbuildTriggerDisallowed, assertInstructionCasing ],
[ [ 1, mixed.toUpperCase(), 1, triggerLength, 1, triggerLength + length ],
[ DiagnosticSeverity.Warning, 1, 1, triggerLength, 1, triggerLength + length ] ]);
break;
case "ONBUILD":
assert.equal(diagnostics.length, 2);
assertDiagnostics(diagnostics,
[ ValidationCode.ONBUILD_CHAINING_DISALLOWED, ValidationCode.CASING_INSTRUCTION ],
[ assertOnbuildChainingDisallowed, assertInstructionCasing ],
[ [ 1, 1, triggerLength, 1, triggerLength + length ],
[ DiagnosticSeverity.Warning, 1, 1, triggerLength, 1, triggerLength + length ] ]);
break;
default:
assert.equal(diagnostics.length, 1);
assertInstructionCasing(diagnostics[0], DiagnosticSeverity.Warning, 1, 1, triggerLength, 1, triggerLength + length);
break;
}
} else {
assert.equal(diagnostics.length, 1);
assertInstructionCasing(diagnostics[0], DiagnosticSeverity.Warning, 1, 1, triggerLength, 1, triggerLength + length);
}
diagnostics = validateDockerfile("FROM node\n#" + onbuild + mixed.toLowerCase() + " " + argument);
assert.equal(diagnostics.length, 0);
}
it("ADD", function() {
testCasingStyle("aDd", "source dest");
});
it("ARG", function() {
testCasingStyle("aRg", "name");
});
it("CMD", function() {
testCasingStyle("cMd", "[ \"/bin/ls\" ]");
});
it("COPY", function() {
testCasingStyle("copY", "source dest");
});