Skip to content

Commit

Permalink
Merge pull request #2322 from dcos/ahoskins/fix/DCOS-17262-port-value…
Browse files Browse the repository at this point in the history
…-zero

↩️ fix(NetworkValidatorUtil): add support for 0 vip port
  • Loading branch information
Orlando Hohmeier authored Jul 14, 2017
2 parents 359b8c7 + 219eea7 commit a7f6ea4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plugins/services/src/js/validators/VipLabelsValidators.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function checkServiceEndpoints(ports, pathPrefix) {
if (!NetworkValidatorUtil.isValidPort(vipPort)) {
return errorsMemo.concat({
path: pathPrefix.concat([index, "labels", label]),
message: "Port should be an integrer less than or equal to 65535"
message: "Port should be an integer less than or equal to 65535"
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("VipLabelsValidators", function() {
};
expect(VipLabelsValidators.mustContainPort(spec)).toEqual([
{
message: "Port should be an integrer less than or equal to 65535",
message: "Port should be an integer less than or equal to 65535",
path: ["container", "docker", "portMappings", 0, "labels", "VIP_0"]
}
]);
Expand Down
2 changes: 1 addition & 1 deletion src/js/utils/NetworkValidatorUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const NetworkValidatorUtil = {
isValidPort(value) {
return (
ValidatorUtil.isInteger(value) &&
ValidatorUtil.isNumberInRange(value, { min: 1, max: 65535 })
ValidatorUtil.isNumberInRange(value, { min: 0, max: 65535 })
);
}
};
Expand Down
12 changes: 8 additions & 4 deletions src/js/utils/__tests__/NetworkValidatorUtil-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ describe("NetworkValidatorUtil", function() {
});

it("should handle number like inputs", function() {
expect(NetworkValidatorUtil.isValidPort(0)).toBe(false);
expect(NetworkValidatorUtil.isValidPort("0")).toBe(false);
expect(NetworkValidatorUtil.isValidPort(0)).toBe(true);
expect(NetworkValidatorUtil.isValidPort("0")).toBe(true);
expect(NetworkValidatorUtil.isValidPort(80)).toBe(true);
expect(NetworkValidatorUtil.isValidPort("80")).toBe(true);
expect(NetworkValidatorUtil.isValidPort(8080)).toBe(true);
expect(NetworkValidatorUtil.isValidPort("8080")).toBe(true);
});

it("should verify that port is greater then 0", function() {
it("should verify that port is greater or equal to 0", function() {
expect(NetworkValidatorUtil.isValidPort(-1)).toBe(false);
expect(NetworkValidatorUtil.isValidPort(0)).toBe(false);
expect(NetworkValidatorUtil.isValidPort(0)).toBe(true);
expect(NetworkValidatorUtil.isValidPort(8080)).toBe(true);
});

Expand All @@ -38,5 +38,9 @@ describe("NetworkValidatorUtil", function() {
expect(NetworkValidatorUtil.isValidPort(65535)).toBe(true);
expect(NetworkValidatorUtil.isValidPort(65536)).toBe(false);
});

it("verifies that port 0 is valid", function() {
expect(NetworkValidatorUtil.isValidPort(0)).toBe(true);
});
});
});

0 comments on commit a7f6ea4

Please sign in to comment.