Skip to content

Commit

Permalink
Fix #116 Support --checksum flag for ADD instructions
Browse files Browse the repository at this point in the history
This change simply adds preliminary support for the --checksum flag so
that it is not considered as an unrecognizable flag. More fine-grained
checks such as verifying whether the digest format is correct or not may
be implemented in the future.

Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Sep 9, 2023
1 parent 5b08f2d commit 50431b3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [Unreleased]
### Added
- support parsing the new `--checksum` flag for ADD instructions ([#116](https://github.com/rcjsuen/dockerfile-utils/issues/116))

## [0.12.0] - 2023-09-09
### Added
- support parsing the new `--start-interval` flag for HEALTHCHECK instructions ([#115](https://github.com/rcjsuen/dockerfile-utils/issues/115))
Expand Down
6 changes: 3 additions & 3 deletions src/dockerValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ export class Validator {
if (problem !== null) {
problems.push(problem);
}
} else if (name !== "chmod" && name !== "chown") {
} else if (name !== "chmod" && name !== "chown" && name !== "checksum") {
let range = flag.getNameRange();
problems.push(Validator.createUnknownAddFlag(addInstructionRange.start.line, flagRange.start, range.end, name));
}
Expand All @@ -684,8 +684,8 @@ export class Validator {
if (addDestinationDiagnostic !== null) {
problems.push(addDestinationDiagnostic);
}
this.checkFlagValue(addInstructionRange.start.line, addFlags, ["chmod", "chown"], problems);
this.checkDuplicateFlags(addInstructionRange.start.line, addFlags, ["chmod", "chown", "link"], problems);
this.checkFlagValue(addInstructionRange.start.line, addFlags, ["chmod", "chown", "checksum"], problems);
this.checkDuplicateFlags(addInstructionRange.start.line, addFlags, ["chmod", "chown", "checksum", "link"], problems);
this.checkJSONQuotes(instruction, problems);
break;
case "COPY":
Expand Down
20 changes: 20 additions & 0 deletions test/dockerValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,26 @@ describe("Docker Validator Tests", function() {
});
});

describe("checksum", () => {
it("ok", () => {
const diagnostics = validateDockerfile("FROM alpine\nADD --checksum=sha256:24454f830cdb571e2c4ad15481119c43b3cafd48dd869a9b2945d1036d1dc68d https://mirrors.edge.kernel.org/pub/linux/kernel/Historic/linux-0.01.tar.gz /");
assert.strictEqual(diagnostics.length, 0);
});

it("flag no value", () => {
const diagnostics = validateDockerfile("FROM alpine\nADD --checksum https://mirrors.edge.kernel.org/pub/linux/kernel/Historic/linux-0.01.tar.gz /");
assert.strictEqual(diagnostics.length, 1);
assertFlagMissingValue(diagnostics[0], 1, "checksum", 1, 6, 1, 14);
});

it("duplicate flag", () => {
const diagnostics = validateDockerfile("FROM alpine\nADD --checksum=abc --checksum=123 a /b");
assert.strictEqual(diagnostics.length, 2);
assertFlagDuplicate(diagnostics[0], 1, "checksum", 1, 6, 1, 14);
assertFlagDuplicate(diagnostics[1], 1, "checksum", 1, 21, 1, 29);
});
});

it("unknown flag", function() {
let diagnostics = validateDockerfile("FROM alpine\nADD --x=bb . .");
assert.equal(diagnostics.length, 1);
Expand Down

0 comments on commit 50431b3

Please sign in to comment.