[Snapshot Restore] Fix validation schemas (#148787)

This commit is contained in:
Ignacio Rivas 2023-01-16 17:53:10 +01:00 committed by GitHub
parent 0ce1452bb0
commit 77c3f95d33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 50 deletions

View file

@ -380,6 +380,29 @@ describe('[Snapshot and Restore API Routes] Repositories', () => {
await expect(router.runRequest(mockRequest)).resolves.toEqual({ body: expectedResponse });
});
it('should return successful ES response when using unknown setting', async () => {
const mockEsResponse = {
[name]: { type: 's3', settings: { awsAccount: 'test-account' } },
};
getRepoFn.mockResolvedValue({ [name]: {} });
createRepoFn.mockResolvedValue(mockEsResponse);
const expectedResponse = mockEsResponse;
await expect(
router.runRequest({
...mockRequest,
body: {
name,
type: 's3',
settings: {
path_style_access: 'test-account',
},
},
})
).resolves.toEqual({ body: expectedResponse });
});
it('should throw if ES error', async () => {
getRepoFn.mockRejectedValue(new Error());
await expect(router.runRequest(mockRequest)).rejects.toThrowError();

View file

@ -62,14 +62,8 @@ export const policySchema = schema.object({
isManagedPolicy: schema.boolean(),
});
const fsRepositorySettings = schema.object({
location: schema.string(),
compress: schema.maybe(schema.boolean()),
chunkSize: schema.maybe(schema.oneOf([schema.string(), schema.literal(null)])),
maxRestoreBytesPerSec: schema.maybe(schema.string()),
maxSnapshotBytesPerSec: schema.maybe(schema.string()),
readonly: schema.maybe(schema.boolean()),
});
// Only validate required settings, everything else is optional
const fsRepositorySettings = schema.object({ location: schema.string() }, { unknowns: 'allow' });
const fsRepositorySchema = schema.object({
name: schema.string(),
@ -87,20 +81,8 @@ const readOnlyRepository = schema.object({
settings: readOnlyRepositorySettings,
});
const s3RepositorySettings = schema.object({
bucket: schema.string(),
client: schema.maybe(schema.string()),
basePath: schema.maybe(schema.string()),
compress: schema.maybe(schema.boolean()),
chunkSize: schema.maybe(schema.oneOf([schema.string(), schema.literal(null)])),
serverSideEncryption: schema.maybe(schema.boolean()),
bufferSize: schema.maybe(schema.string()),
cannedAcl: schema.maybe(schema.string()),
storageClass: schema.maybe(schema.string()),
maxRestoreBytesPerSec: schema.maybe(schema.string()),
maxSnapshotBytesPerSec: schema.maybe(schema.string()),
readonly: schema.maybe(schema.boolean()),
});
// Only validate required settings, everything else is optional
const s3RepositorySettings = schema.object({ bucket: schema.string() }, { unknowns: 'allow' });
const s3Repository = schema.object({
name: schema.string(),
@ -108,17 +90,11 @@ const s3Repository = schema.object({
settings: s3RepositorySettings,
});
// Only validate required settings, everything else is optional
const hdsRepositorySettings = schema.object(
{
uri: schema.string(),
path: schema.string(),
loadDefaults: schema.maybe(schema.boolean()),
compress: schema.maybe(schema.boolean()),
chunkSize: schema.maybe(schema.oneOf([schema.string(), schema.literal(null)])),
maxRestoreBytesPerSec: schema.maybe(schema.string()),
maxSnapshotBytesPerSec: schema.maybe(schema.string()),
readonly: schema.maybe(schema.boolean()),
['security.principal']: schema.maybe(schema.string()),
},
{ unknowns: 'allow' }
);
@ -129,17 +105,7 @@ const hdsfRepository = schema.object({
settings: hdsRepositorySettings,
});
const azureRepositorySettings = schema.object({
client: schema.maybe(schema.string()),
container: schema.maybe(schema.string()),
basePath: schema.maybe(schema.string()),
locationMode: schema.maybe(schema.string()),
compress: schema.maybe(schema.boolean()),
chunkSize: schema.maybe(schema.oneOf([schema.string(), schema.literal(null)])),
maxRestoreBytesPerSec: schema.maybe(schema.string()),
maxSnapshotBytesPerSec: schema.maybe(schema.string()),
readonly: schema.maybe(schema.boolean()),
});
const azureRepositorySettings = schema.object({}, { unknowns: 'allow' });
const azureRepository = schema.object({
name: schema.string(),
@ -147,16 +113,8 @@ const azureRepository = schema.object({
settings: azureRepositorySettings,
});
const gcsRepositorySettings = schema.object({
bucket: schema.string(),
client: schema.maybe(schema.string()),
basePath: schema.maybe(schema.string()),
compress: schema.maybe(schema.boolean()),
chunkSize: schema.maybe(schema.oneOf([schema.string(), schema.literal(null)])),
maxRestoreBytesPerSec: schema.maybe(schema.string()),
maxSnapshotBytesPerSec: schema.maybe(schema.string()),
readonly: schema.maybe(schema.boolean()),
});
// Only validate required settings, everything else is optional
const gcsRepositorySettings = schema.object({ bucket: schema.string() }, { unknowns: 'allow' });
const gcsRepository = schema.object({
name: schema.string(),