Skip to content

Commit 09c7574

Browse files
authoredMar 7, 2024··
fix(2368): fix api validation (#3050)
1 parent 575f763 commit 09c7574

13 files changed

+39
-26
lines changed
 

‎plugins/builds/getBuildStatuses.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const boom = require('@hapi/boom');
44
const joi = require('joi');
55
const stringSchema = joi.string().regex(/^[0-9]+$/);
6-
const jobIdsSchema = joi.alternatives().try(joi.array().items(stringSchema), stringSchema).required();
6+
const jobIdsSchema = joi.alternatives().try(joi.array().items(stringSchema), stringSchema).example(123345).required();
77

88
module.exports = () => ({
99
method: 'GET',
@@ -46,8 +46,8 @@ module.exports = () => ({
4646
validate: {
4747
query: joi.object({
4848
jobIds: jobIdsSchema,
49-
numBuilds: stringSchema,
50-
offset: stringSchema
49+
numBuilds: joi.number().integer().positive().default(1),
50+
offset: joi.number().integer().min(0).default(0)
5151
})
5252
}
5353
}

‎plugins/builds/metrics.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ module.exports = () => ({
5858
id: buildIdSchema
5959
}),
6060
query: joi.object({
61-
startTime: joi.string().isoDate(),
62-
endTime: joi.string().isoDate()
61+
startTime: joi.string().isoDate().example('1970-01-01T15:00:00Z'),
62+
endTime: joi.string().isoDate().example('1970-01-03T18:00:00Z')
6363
})
6464
}
6565
}

‎plugins/commands/listTags.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ module.exports = () => ({
5252
}),
5353
query: schema.api.pagination.concat(
5454
joi.object({
55-
search: joi.forbidden() // we don't support search for Command list tag
55+
search: joi.forbidden(), // we don't support search for Command list tag
56+
getCount: joi.forbidden(),
57+
sortBy: joi.forbidden()
5658
})
5759
)
5860
}

‎plugins/events/listBuilds.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ module.exports = () => ({
5252
joi.object({
5353
readOnly: joi.boolean().truthy('true').falsy('false').default(false),
5454
fetchSteps: joi.boolean().truthy('true').falsy('false').default(true),
55-
search: joi.forbidden() // we don't support search for Event list builds
55+
search: joi.forbidden(), // we don't support search for Event list builds
56+
getCount: joi.forbidden()
5657
})
5758
)
5859
}

‎plugins/events/metrics.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ module.exports = () => ({
5858
id: eventIdSchema
5959
}),
6060
query: joi.object({
61-
startTime: joi.string().isoDate(),
62-
endTime: joi.string().isoDate()
61+
startTime: joi.string().isoDate().example('1970-01-01T15:00:00Z'),
62+
endTime: joi.string().isoDate().example('1970-01-03T18:00:00Z')
6363
})
6464
}
6565
}

‎plugins/jobs/latestBuild.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const boom = require('@hapi/boom');
44
const joi = require('joi');
55
const schema = require('screwdriver-data-schema');
66
const idSchema = schema.models.job.base.extract('id');
7+
const getSchema = schema.models.build.get;
78
const statusSchema = schema.models.build.base.extract('status');
89

910
module.exports = () => ({
@@ -44,7 +45,7 @@ module.exports = () => ({
4445
});
4546
},
4647
response: {
47-
schema: joi.object()
48+
schema: getSchema
4849
},
4950
validate: {
5051
params: joi.object({

‎plugins/jobs/listBuilds.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ module.exports = () => ({
7272
}),
7373
query: schema.api.pagination.concat(
7474
joi.object({
75-
readOnly: joi.boolean().truthy('true').falsy('false').default(false),
75+
readOnly: joi.boolean().truthy('true').falsy('false').default(true),
7676
fetchSteps: joi.boolean().truthy('true').falsy('false').default(true),
7777
status: statusSchema,
78-
search: joi.forbidden() // we don't support search for Job list builds
78+
search: joi.forbidden(), // we don't support search for Job list builds
79+
getCount: joi.forbidden()
7980
})
8081
)
8182
}

‎plugins/jobs/metrics.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ module.exports = () => ({
6262
id: jobIdSchema
6363
}),
6464
query: joi.object({
65-
startTime: joi.string().isoDate(),
66-
endTime: joi.string().isoDate(),
65+
startTime: joi.string().isoDate().example('1970-01-01T15:00:00Z'),
66+
endTime: joi.string().isoDate().example('1970-01-03T18:00:00Z'),
6767
aggregateInterval: joi.string().valid('none', 'day', 'week', 'month', 'year').messages({
6868
'any.only': '{{#label}} fails because it must be one of none, day, week, month, year'
6969
})

‎plugins/pipelines/latestCommitEvent.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const boom = require('@hapi/boom');
44
const joi = require('joi');
55
const schema = require('screwdriver-data-schema');
6+
const getSchema = schema.models.event.get;
67
const idSchema = schema.models.pipeline.base.extract('id');
78

89
module.exports = () => ({
@@ -43,7 +44,7 @@ module.exports = () => ({
4344
});
4445
},
4546
response: {
46-
schema: joi.object()
47+
schema: getSchema
4748
},
4849
validate: {
4950
params: joi.object({

‎plugins/pipelines/listJobs.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ module.exports = () => ({
6161
joi.object({
6262
archived: joi.boolean().truthy('true').falsy('false').default(false),
6363
jobName: jobNameSchema,
64-
search: joi.forbidden() // we don't support search for Pipeline list jobs
64+
search: joi.forbidden(), // we don't support search for Pipeline list jobs
65+
getCount: joi.forbidden(),
66+
sortBy: joi.forbidden()
6567
})
6668
)
6769
}

‎plugins/pipelines/metrics.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ module.exports = () => ({
9292
}),
9393
query: schema.api.pagination.concat(
9494
joi.object({
95-
startTime: joi.string().isoDate(),
96-
endTime: joi.string().isoDate(),
95+
startTime: joi.string().isoDate().example('1970-01-01T15:00:00Z'),
96+
endTime: joi.string().isoDate().example('1970-01-03T18:00:00Z'),
9797
aggregateInterval: joi.string().valid('none', 'day', 'week', 'month', 'year'),
9898
'downtimeJobs[]': jobIdsSchema.optional(),
9999
'downtimeStatuses[]': statusesSchema.optional(),

‎plugins/templates/listVersionsWithMetric.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ module.exports = () => ({
6565
query: schema.api.pagination.concat(
6666
joi.object({
6767
search: joi.forbidden(), // we don't support search for Template list versions with metrics,
68-
startTime: joi.string().isoDate(),
69-
endTime: joi.string().isoDate()
68+
startTime: joi.string().isoDate().example('1970-01-01T15:00:00Z'),
69+
endTime: joi.string().isoDate().example('1970-01-03T18:00:00Z'),
70+
getCount: joi.forbidden(),
71+
sortBy: joi.forbidden()
7072
})
7173
)
7274
}

‎test/plugins/jobs.test.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -330,20 +330,20 @@ describe('job plugin test', () => {
330330
assert.equal(reply.statusCode, 200);
331331
assert.calledWith(job.getBuilds, {
332332
sort: 'descending',
333-
sortBy: 'createTime'
333+
sortBy: 'createTime',
334+
readOnly: true
334335
});
335336
assert.deepEqual(reply.result, testBuilds);
336337
}));
337338

338339
it('returns 200 for getting builds with query params', () => {
339-
options.url = `/jobs/${id}/builds?fetchSteps=false&readOnly=true`;
340+
options.url = `/jobs/${id}/builds?fetchSteps=false&readOnly=false`;
340341

341342
return server.inject(options).then(reply => {
342343
assert.equal(reply.statusCode, 200);
343344
assert.calledWith(job.getBuilds, {
344345
sort: 'descending',
345-
sortBy: 'createTime',
346-
readOnly: true
346+
sortBy: 'createTime'
347347
});
348348
assert.deepEqual(reply.result, testBuilds);
349349
});
@@ -360,7 +360,8 @@ describe('job plugin test', () => {
360360
page: 2
361361
},
362362
sort: 'ascending',
363-
sortBy: 'createTime'
363+
sortBy: 'createTime',
364+
readOnly: true
364365
});
365366
assert.deepEqual(reply.result, testBuilds);
366367
});
@@ -378,6 +379,7 @@ describe('job plugin test', () => {
378379
},
379380
sort: 'ascending',
380381
sortBy: 'id',
382+
readOnly: true,
381383
status: 'RUNNING'
382384
});
383385
assert.deepEqual(reply.result, testBuilds);
@@ -395,7 +397,8 @@ describe('job plugin test', () => {
395397
count: 30
396398
},
397399
sort: 'descending',
398-
sortBy: 'createTime'
400+
sortBy: 'createTime',
401+
readOnly: true
399402
});
400403
assert.deepEqual(reply.result, testBuilds);
401404
});

0 commit comments

Comments
 (0)
Please sign in to comment.