Skip to content

Commit

Permalink
Fix #39 Consider private registries when validating
Browse files Browse the repository at this point in the history
Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed May 25, 2018
1 parent 3e33c0b commit 329e571
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
### Fixed
- fix incorrect validaiton warning in ARG, ENV, and LABEL instructions caused by quotes being used in variable replacements ([#36](https://github.com/rcjsuen/dockerfile-utils/issues/36))
- fix incorrect validation of tagged images caused by FROM referencing images in a private registry ([#39](https://github.com/rcjsuen/dockerfile-utils/issues/39))

## [0.0.9] - 2018-04-16
### Fixed
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"main": "./lib/main.js",
"types": "./lib/main.d.ts",
"dependencies": {
"dockerfile-ast": "0.0.6",
"vscode-languageserver-types": "3.5.0"
"dockerfile-ast": "0.0.7",
"vscode-languageserver-types": "3.6.0"
},
"devDependencies": {
"@types/mocha": "^2.2.33",
Expand Down
12 changes: 6 additions & 6 deletions src/dockerValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import {
TextDocument, Range, Position, Diagnostic, DiagnosticSeverity
} from 'vscode-languageserver-types';
import { Dockerfile, Flag, Instruction, JSONInstruction, Add, Cmd, Copy, Entrypoint, Env, From, Healthcheck, Label, Onbuild, ModifiableInstruction, DockerfileParser, Directive } from 'dockerfile-ast';
import { Dockerfile, Flag, Instruction, JSONInstruction, Add, Cmd, Copy, Entrypoint, From, Healthcheck, Onbuild, ModifiableInstruction, PropertyInstruction, DockerfileParser, Directive } from 'dockerfile-ast';
import { ValidationCode, ValidationSeverity, ValidatorSettings } from './main';

export const KEYWORDS = [
Expand Down Expand Up @@ -90,7 +90,7 @@ export class Validator {
*/
private checkArguments(instruction: Instruction, problems: Diagnostic[], expectedArgCount: number[],
validate: Function, createIncompleteDiagnostic?: Function): void {
let args = instruction.getArguments();
let args = instruction instanceof PropertyInstruction ? instruction.getPropertyArguments() : instruction.getArguments();
if (args.length === 0) {
// all instructions are expected to have at least one argument
let range = instruction.getInstructionRange();
Expand Down Expand Up @@ -318,7 +318,7 @@ export class Validator {
this.checkArguments(instruction, problems, [-1], function (): any {
return null;
});
let properties = instruction instanceof Env ? (instruction as Env).getProperties() : (instruction as Label).getProperties();
let properties = (instruction as PropertyInstruction).getProperties();
if (properties.length === 1 && properties[0].getValue() === null) {
let range = properties[0].getNameRange();
problems.push(Validator.createENVRequiresTwoArguments(range.start, range.end));
Expand Down Expand Up @@ -366,11 +366,11 @@ export class Validator {
let from = instruction as From;
let index = argument.indexOf('@');
if (index === -1) {
index = argument.indexOf(':');
if (index === -1) {
let tagRange = from.getImageTagRange();
if (tagRange === null) {
return null;
}
let tag = argument.substring(index + 1);
let tag = document.getText(tagRange);
if (tag.indexOf('$') !== -1) {
return null;
} else if (tag === "") {
Expand Down
36 changes: 36 additions & 0 deletions test/dockerValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,42 @@ describe("Docker Validator Tests", function() {
diagnostics = validateDockerfile("FROM node@sha256:613685c22f65d01f2264bdd49b8a336488e14faf29f3ff9b6bf76a4da23c4700");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM privateregistry.com/image:tag");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM privateregistry.com/image@sha256:613685c22f65d01f2264bdd49b8a336488e14faf29f3ff9b6bf76a4da23c4700");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM privateregistry.com:5000/image:tag");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM privateregistry.com:5000/image@sha256:613685c22f65d01f2264bdd49b8a336488e14faf29f3ff9b6bf76a4da23c4700");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM localhost/node:9");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM localhost/node@sha256:613685c22f65d01f2264bdd49b8a336488e14faf29f3ff9b6bf76a4da23c4700");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM localhost:1234/node:9");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM localhost:1234/node@sha256:613685c22f65d01f2264bdd49b8a336488e14faf29f3ff9b6bf76a4da23c4700");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM 123.22.33.123/user/image:tag2");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM 123.22.33.123/user/image@sha256:613685c22f65d01f2264bdd49b8a336488e14faf29f3ff9b6bf76a4da23c4700");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM 123.22.33.123:2345/user/image:tag2");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM 123.22.33.123:2345/user/image@sha256:613685c22f65d01f2264bdd49b8a336488e14faf29f3ff9b6bf76a4da23c4700");
assert.equal(diagnostics.length, 0);

diagnostics = validateDockerfile("ARG image=node\nFROM $image");
assert.equal(diagnostics.length, 0);

Expand Down

0 comments on commit 329e571

Please sign in to comment.