Skip to content
Permalink
Browse files

Added job name length check in job constructor

Job seems to be correct place to implement name check instead of
brigadier.
  • Loading branch information
codegagan committed Oct 27, 2018
1 parent 4b1c5b9 commit 76dd5faa14f04ea207ebfa3d49514033789daf8c
Showing with 10 additions and 2 deletions.
  1. +2 −2 brigade-worker/src/job.ts
  2. +8 −0 brigade-worker/test/job.ts
@@ -243,7 +243,7 @@ export abstract class Job {
) {
if (!jobNameIsValid(name)) {
throw new Error(
"job name must be letters, numbers, and '-', and must not start or end with '-'"
"job name must be letters, numbers, and '-', and must not start or end with '-', having max length 36"
);
}
this.name = name.toLocaleLowerCase();
@@ -270,5 +270,5 @@ export abstract class Job {
* jobNameIsValid checks the validity of a job's name.
*/
export function jobNameIsValid(name: string): boolean {
return /^(([a-z0-9][-a-z0-9.]*)?[a-z0-9])+$/.test(name);
return (name.length < 37) && /^(([a-z0-9][-a-z0-9.]*)?[a-z0-9])+$/.test(name);
}
@@ -96,6 +96,14 @@ describe("job", function() {
j = new mock.MockJob("name");
assert.equal(j.host.nodeSelector.size, 0);
});
it("longer than expected name", function(done){
try {
new mock.MockJob("justmakingthesethirtysevencharacterss");
done("Expecting to fail for more than 36 characters");
} catch (error) {
done();
}
});
context("when image is supplied", function() {
it("sets image property", function() {
j = new mock.MockJob("my-name", "alpine:3.4");

0 comments on commit 76dd5fa

Please sign in to comment.
You can’t perform that action at this time.