Skip to content

Commit 2008772

Browse files
authoredApr 2, 2024··
Merge pull request #2528 from kuzzleio/beta
2 parents 7ba9e6e + 5a24bbb commit 2008772

33 files changed

+331
-1077
lines changed
 

‎CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## [2.29.1-beta.2](https://github.com/kuzzleio/kuzzle/compare/v2.29.1-beta.1...v2.29.1-beta.2) (2024-03-22)
2+
3+
4+
### Bug Fixes
5+
6+
* **global:** fix global types ([b4661b9](https://github.com/kuzzleio/kuzzle/commit/b4661b9e1e2d8c169d93e7a17f030338875faed0))
7+
* **ts:** export Kuzzle class so typedef is generated ([448c235](https://github.com/kuzzleio/kuzzle/commit/448c235ef3db8316f02b00d997a48a7e3a30784c))
8+
9+
## [2.29.1-beta.1](https://github.com/kuzzleio/kuzzle/compare/v2.29.0...v2.29.1-beta.1) (2024-03-13)
10+
11+
12+
### Bug Fixes
13+
14+
* **openapi:** remove dedicated components files as we need to generate it automaticaly ([a3036f6](https://github.com/kuzzleio/kuzzle/commit/a3036f6336c1c6e14eb874acde04976f3de1c1ed))
15+
* **settings:** elasticsearch default setting on imports collection ([228482a](https://github.com/kuzzleio/kuzzle/commit/228482af41b822c0e064286083811c9aca95e532))
16+
117
# [2.29.0](https://github.com/kuzzleio/kuzzle/compare/v2.28.0...v2.29.0) (2024-02-01)
218

319

‎docker/scripts/start-kuzzle-test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ app.hook.register("custom:event", async (name) => {
262262
let syncedHello = "World";
263263
let dynamicPipeId;
264264

265+
app.openApi.definition.components = {}
265266
app.openApi.definition.components.LogisticObjects = {
266267
Item: {
267268
type: "object",

‎features/ServerController.feature

-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ Feature: Server Controller
7878
When I successfully execute the action "server":"openapi"
7979
Then I should receive a response matching:
8080
| swagger | "2.0" |
81-
| components.RequestPayload | "_OBJECT_" |
8281
| paths./users/{_id}/_replace.put.tags[0] | "security" |
8382

8483
@http
@@ -87,7 +86,6 @@ Feature: Server Controller
8786
| scope | "app" |
8887
Then I should receive a response matching:
8988
| paths./openapi-test/{company}/{objectType}/{_id}.post.tags[0] | "openapi-test" |
90-
| components.LogisticObjects.Item | "_OBJECT_" |
9189

9290
# server:publicApi ========================================================================
9391
@development @http

‎lib/api/httpRoutes.js

-29
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,6 @@
2323

2424
"use strict";
2525

26-
const {
27-
OpenApiDocumentCount,
28-
OpenApiDocumentDeleteByQuery,
29-
OpenApiDocumentDelete,
30-
OpenApiDocumentScroll,
31-
OpenApiDocumentExists,
32-
OpenApiDocumentUpdate,
33-
OpenApiDocumentReplace,
34-
OpenApiDocumentGet,
35-
OpenApiDocumentCreate,
36-
OpenApiDocumentCreateOrReplace,
37-
OpenApiDocumentValidate,
38-
OpenApiSecurityUpsertUser,
39-
OpenApiDocumentmCreateOrReplace,
40-
} = require("./openapi/components");
41-
4226
const routes = [
4327
// GET (idempotent)
4428
{ verb: "get", path: "/_me", controller: "auth", action: "getCurrentUser" },
@@ -242,7 +226,6 @@ const routes = [
242226
path: "/:index/:collection/:_id",
243227
controller: "document",
244228
action: "get",
245-
openapi: OpenApiDocumentGet,
246229
},
247230
{
248231
verb: "get",
@@ -255,7 +238,6 @@ const routes = [
255238
path: "/:index/:collection/:_id/_exists",
256239
controller: "document",
257240
action: "exists",
258-
openapi: OpenApiDocumentExists,
259241
},
260242
{
261243
verb: "post",
@@ -268,7 +250,6 @@ const routes = [
268250
path: "/_scroll/:scrollId",
269251
controller: "document",
270252
action: "scroll",
271-
openapi: OpenApiDocumentScroll,
272253
},
273254

274255
{
@@ -770,14 +751,12 @@ const routes = [
770751
path: "/:index/:collection/_count",
771752
controller: "document",
772753
action: "count",
773-
openapi: OpenApiDocumentCount,
774754
},
775755
{
776756
verb: "post",
777757
path: "/:index/:collection/_create",
778758
controller: "document",
779759
action: "create",
780-
openapi: OpenApiDocumentCreate,
781760
},
782761
{
783762
verb: "post",
@@ -832,7 +811,6 @@ const routes = [
832811
path: "/:index/:collection/_validate",
833812
controller: "document",
834813
action: "validate",
835-
openapi: OpenApiDocumentValidate,
836814
},
837815

838816
{
@@ -955,7 +933,6 @@ const routes = [
955933
path: "/users/:_id/_upsert",
956934
controller: "security",
957935
action: "upsertUser",
958-
openapi: OpenApiSecurityUpsertUser,
959936
},
960937
{
961938
verb: "post",
@@ -1241,7 +1218,6 @@ const routes = [
12411218
path: "/:index/:collection/:_id",
12421219
controller: "document",
12431220
action: "delete",
1244-
openapi: OpenApiDocumentDelete,
12451221
},
12461222
{
12471223
verb: "delete",
@@ -1254,7 +1230,6 @@ const routes = [
12541230
path: "/:index/:collection/_query",
12551231
controller: "document",
12561232
action: "deleteByQuery",
1257-
openapi: OpenApiDocumentDeleteByQuery,
12581233
},
12591234
{
12601235
verb: "delete",
@@ -1421,21 +1396,18 @@ const routes = [
14211396
path: "/:index/:collection/:_id",
14221397
controller: "document",
14231398
action: "createOrReplace",
1424-
openapi: OpenApiDocumentCreateOrReplace,
14251399
},
14261400
{
14271401
verb: "put",
14281402
path: "/:index/:collection/_mCreateOrReplace",
14291403
controller: "document",
14301404
action: "mCreateOrReplace",
1431-
openapi: OpenApiDocumentmCreateOrReplace,
14321405
},
14331406
{
14341407
verb: "put",
14351408
path: "/:index/:collection/:_id/_replace",
14361409
controller: "document",
14371410
action: "replace",
1438-
openapi: OpenApiDocumentReplace,
14391411
},
14401412
{
14411413
verb: "put",
@@ -1458,7 +1430,6 @@ const routes = [
14581430
path: "/:index/:collection/:_id/_update",
14591431
controller: "document",
14601432
action: "update",
1461-
openapi: OpenApiDocumentUpdate,
14621433
deprecated: {
14631434
since: "2.11.0",
14641435
message: 'Use "document:update" route with PATCH instead of PUT',

‎lib/api/openapi/OpenApiManager.ts

-48
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,6 @@
1919
* limitations under the License.
2020
*/
2121

22-
import {
23-
OpenApiPayloadsDefinitions,
24-
OpenApiDocumentCountComponent,
25-
OpenApiDocumentDeleteByQueryComponent,
26-
OpenApiDocumentDeleteComponent,
27-
OpenApiDocumentScrollComponent,
28-
OpenApiDocumentExistsComponent,
29-
OpenApiDocumentUpdateComponent,
30-
OpenApiDocumentReplaceComponent,
31-
OpenApiDocumentGetComponent,
32-
OpenApiDocumentCreateOrReplaceComponent,
33-
OpenApiDocumentCreateComponent,
34-
OpenApiDocumentValidateComponent,
35-
OpenApiSecurityUpsertUserComponent,
36-
OpenApiDocumentmCreateOrReplaceComponent,
37-
} from "./components";
3822
import { OpenApiDefinition } from "../../types/OpenApiDefinition";
3923
import { version } from "../../../package.json";
4024
import { generateOpenApi } from "./openApiGenerator";
@@ -50,7 +34,6 @@ export class OpenApiManager {
5034
name: "Kuzzle team",
5135
url: "https://kuzzle.io",
5236
email: "support@kuzzle.io",
53-
discord: "http://join.discord.kuzzle.io",
5437
},
5538
license: {
5639
name: "Apache 2",
@@ -62,40 +45,9 @@ export class OpenApiManager {
6245
description: "Kuzzle API Documentation",
6346
url: "https://docs.kuzzle.io/core/2/api/",
6447
},
65-
servers: [
66-
{
67-
url: "https://{baseUrl}:{port}",
68-
description: "Kuzzle Base Url",
69-
variables: {
70-
baseUrl: { default: "localhost" },
71-
port: { default: 7512 },
72-
},
73-
},
74-
],
7548
tags: [],
7649
schemes: ["https", "http"],
7750
paths: {},
78-
components: {
79-
...OpenApiPayloadsDefinitions,
80-
81-
document: {
82-
...OpenApiDocumentCountComponent,
83-
...OpenApiDocumentDeleteByQueryComponent,
84-
...OpenApiDocumentDeleteComponent,
85-
...OpenApiDocumentScrollComponent,
86-
...OpenApiDocumentExistsComponent,
87-
...OpenApiDocumentUpdateComponent,
88-
...OpenApiDocumentReplaceComponent,
89-
...OpenApiDocumentGetComponent,
90-
...OpenApiDocumentCreateOrReplaceComponent,
91-
...OpenApiDocumentCreateComponent,
92-
...OpenApiDocumentValidateComponent,
93-
},
94-
security: {
95-
...OpenApiSecurityUpsertUserComponent,
96-
...OpenApiDocumentmCreateOrReplaceComponent,
97-
},
98-
},
9951
};
10052
/* eslint-enable sort-keys */
10153

‎lib/api/openapi/components/document/count.yaml

-47
This file was deleted.

‎lib/api/openapi/components/document/create.yaml

-46
This file was deleted.

‎lib/api/openapi/components/document/createOrReplace.yaml

-61
This file was deleted.

‎lib/api/openapi/components/document/delete.yaml

-67
This file was deleted.

‎lib/api/openapi/components/document/deleteByQuery.yaml

-90
This file was deleted.

‎lib/api/openapi/components/document/exists.yaml

-35
This file was deleted.

‎lib/api/openapi/components/document/get.yaml

-68
This file was deleted.

‎lib/api/openapi/components/document/index.ts

-82
This file was deleted.

‎lib/api/openapi/components/document/mCreateOrReplace.yaml

-93
This file was deleted.

‎lib/api/openapi/components/document/replace.yaml

-66
This file was deleted.

‎lib/api/openapi/components/document/scroll.yaml

-49
This file was deleted.

‎lib/api/openapi/components/document/update.yaml

-78
This file was deleted.

‎lib/api/openapi/components/document/validate.yaml

-42
This file was deleted.

‎lib/api/openapi/components/index.ts

-9
This file was deleted.

‎lib/api/openapi/components/payloads.yaml

-32
This file was deleted.

‎lib/api/openapi/components/security/index.ts

-8
This file was deleted.

‎lib/api/openapi/components/security/upsertUser.yaml

-58
This file was deleted.

‎lib/api/openapi/openApiGenerator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function generateParameters(route: JSONObject) {
7979
in: "path",
8080
name: m[1],
8181
required: true,
82-
schema: { type: "string" },
82+
type: "string",
8383
});
8484

8585
m = routeUrlMatch.exec(route.path);

‎lib/config/default.config.ts

+13
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,19 @@ const defaultConfig: KuzzleConfiguration = {
425425
},
426426
},
427427
},
428+
imports: {
429+
settings: {
430+
// @deprecated : replace undefined by 1
431+
number_of_shards: 1,
432+
number_of_replicas: 1,
433+
},
434+
mappings: {
435+
dynamic: "strict",
436+
properties: {
437+
hash: { type: "keyword" },
438+
},
439+
},
440+
},
428441
},
429442
},
430443
maxScrollDuration: "1m",

‎lib/core/backend/backendOpenApi.ts

+1-13
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ export class BackendOpenApi extends ApplicationManager {
3333

3434
/* eslint-disable sort-keys */
3535
this.definition = {
36-
openapi: "3.0.0",
36+
openapi: "3.1.0",
3737
info: {
3838
title: `${application.name} API`,
3939
description: `${application.name} HTTP API definition`,
4040
contact: {
4141
name: "Kuzzle team",
4242
url: "https://kuzzle.io",
4343
email: "support@kuzzle.io",
44-
discord: "http://join.discord.kuzzle.io",
4544
},
4645
license: {
4746
name: "Apache 2",
@@ -53,20 +52,9 @@ export class BackendOpenApi extends ApplicationManager {
5352
description: "Kuzzle API Documentation",
5453
url: "https://docs.kuzzle.io/core/2/api/",
5554
},
56-
servers: [
57-
{
58-
url: "https://{baseUrl}:{port}",
59-
description: `${application.name} Base Url`,
60-
variables: {
61-
baseUrl: { default: "localhost" },
62-
port: { default: 7512 },
63-
},
64-
},
65-
],
6655
tags: [],
6756
schemes: ["https", "http"],
6857
paths: {},
69-
components: {},
7058
};
7159
/* eslint-enable sort-keys */
7260
}

‎lib/kuzzle/kuzzle.ts

+116-18
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,89 @@ class Kuzzle extends KuzzleEventEmitter {
626626
}
627627
}
628628

629+
private isConfigsEmpty(importConfig, supportConfig) {
630+
if (
631+
_.isEmpty(importConfig.mappings) &&
632+
_.isEmpty(importConfig.profiles) &&
633+
_.isEmpty(importConfig.roles) &&
634+
_.isEmpty(importConfig.userMappings) &&
635+
_.isEmpty(importConfig.users) &&
636+
_.isEmpty(supportConfig.fixtures) &&
637+
_.isEmpty(supportConfig.mappings) &&
638+
_.isEmpty(supportConfig.securities)
639+
) {
640+
return true;
641+
}
642+
return false;
643+
}
644+
645+
private async persistHashedImport({
646+
existingRedisHash,
647+
existingESHash,
648+
importPayloadHash,
649+
type,
650+
}) {
651+
if (!existingRedisHash && !existingESHash) {
652+
// If the import is not initialized in the redis cache and in the ES, we initialize it
653+
this.log.info(`${type} import is not initialized, initializing...`);
654+
655+
await this.ask(
656+
"core:storage:private:document:create",
657+
"kuzzle",
658+
"imports",
659+
{
660+
hash: importPayloadHash,
661+
},
662+
{ id: `${BACKEND_IMPORT_KEY}:${type}` },
663+
);
664+
await this.ask(
665+
"core:cache:internal:store",
666+
`${BACKEND_IMPORT_KEY}:${type}`,
667+
importPayloadHash,
668+
);
669+
} else if (existingRedisHash && !existingESHash) {
670+
// If the import is initialized in the redis cache but not in the ES
671+
// We initialize it in the ES
672+
this.log.info(
673+
`${type} import is not initialized in %kuzzle.imports, initializing...`,
674+
);
675+
676+
const redisCache = await this.ask(
677+
"core:cache:internal:get",
678+
`${BACKEND_IMPORT_KEY}:${type}`,
679+
);
680+
681+
await this.ask(
682+
"core:storage:private:document:create",
683+
"kuzzle",
684+
"imports",
685+
{
686+
hash: redisCache,
687+
},
688+
{ id: `${BACKEND_IMPORT_KEY}:${type}` },
689+
);
690+
} else if (!existingRedisHash && existingESHash) {
691+
// If the import is initialized in the ES but not in the redis cache
692+
// We initialize it in the redis cache
693+
this.log.info(
694+
`${type} import is not initialized in the redis cache, initializing...`,
695+
);
696+
697+
const esDocument = await this.ask(
698+
"core:storage:private:document:get",
699+
"kuzzle",
700+
"imports",
701+
`${BACKEND_IMPORT_KEY}:${type}`,
702+
);
703+
704+
await this.ask(
705+
"core:cache:internal:store",
706+
`${BACKEND_IMPORT_KEY}:${type}`,
707+
esDocument._source.hash,
708+
);
709+
}
710+
}
711+
629712
/**
630713
* Load into the app several imports
631714
*
@@ -638,16 +721,7 @@ class Kuzzle extends KuzzleEventEmitter {
638721
toImport: ImportConfig = {},
639722
toSupport: SupportConfig = {},
640723
): Promise<void> {
641-
if (
642-
_.isEmpty(toImport.mappings) &&
643-
_.isEmpty(toImport.profiles) &&
644-
_.isEmpty(toImport.roles) &&
645-
_.isEmpty(toImport.userMappings) &&
646-
_.isEmpty(toImport.users) &&
647-
_.isEmpty(toSupport.fixtures) &&
648-
_.isEmpty(toSupport.mappings) &&
649-
_.isEmpty(toSupport.securities)
650-
) {
724+
if (this.isConfigsEmpty(toImport, toSupport)) {
651725
return;
652726
}
653727

@@ -676,31 +750,54 @@ class Kuzzle extends KuzzleEventEmitter {
676750
const importPayloadHash = sha256(stringify(importPayload));
677751
const mutex = new Mutex(`backend:import:${type}`, { timeout: 0 });
678752

679-
const existingHash = await this.ask(
753+
const existingRedisHash = await this.ask(
680754
"core:cache:internal:get",
681755
`${BACKEND_IMPORT_KEY}:${type}`,
682756
);
683757

684-
const initialized = existingHash === importPayloadHash;
758+
const existingESHash = await this.ask(
759+
"core:storage:private:document:exist",
760+
"kuzzle",
761+
"imports",
762+
`${BACKEND_IMPORT_KEY}:${type}`,
763+
);
764+
765+
let initialized = false;
766+
767+
if (existingRedisHash) {
768+
// Check if the import is already initialized inside the redis cache
769+
initialized = existingRedisHash === importPayloadHash;
770+
} else if (existingESHash) {
771+
// Check if the import is already initialized inside the ES
772+
const esDocument = await this.ask(
773+
"core:storage:private:document:get",
774+
"kuzzle",
775+
"imports",
776+
`${BACKEND_IMPORT_KEY}:${type}`,
777+
);
778+
initialized = esDocument._source.hash === importPayloadHash;
779+
}
780+
685781
const locked = await mutex.lock();
686782

687783
await importMethod(
688784
{ toImport, toSupport },
689785
{
690786
firstCall: !initialized && locked,
691-
initialized,
787+
initialized: initialized,
692788
locked,
693789
},
694790
);
695791

696-
if (!initialized && locked) {
792+
if (locked) {
697793
lockedMutex.push(mutex);
698794

699-
await this.ask(
700-
"core:cache:internal:store",
701-
`${BACKEND_IMPORT_KEY}:${type}`,
795+
await this.persistHashedImport({
796+
existingESHash,
797+
existingRedisHash,
702798
importPayloadHash,
703-
);
799+
type,
800+
});
704801
}
705802
}
706803

@@ -829,4 +926,5 @@ class Kuzzle extends KuzzleEventEmitter {
829926
}
830927
}
831928

929+
export { Kuzzle };
832930
module.exports = Kuzzle;

‎lib/types/Global.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { Backend } from "../core/backend";
2+
import { Kuzzle } from "../kuzzle";
23

3-
/* eslint-disable @typescript-eslint/no-namespace */
4+
/**
5+
* This file contains global type declarations for Kuzzle.
6+
* We need to use `var` so Typescript extends the globalThis type.
7+
* See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#type-checking-for-globalthis
8+
*/
9+
10+
/* eslint-disable no-var, vars-on-top */
411

512
declare global {
6-
namespace NodeJS {
7-
interface Global {
8-
kuzzle: any;
9-
app: Backend;
10-
NODE_ENV: string;
11-
}
12-
}
13+
var app: Backend;
14+
var kuzzle: Kuzzle;
15+
var NODE_ENV: string;
1316
}
1417

1518
global.NODE_ENV = process.env.NODE_ENV;
1619

1720
export {};
1821

19-
/* eslint-enable @typescript-eslint/no-namespace */
22+
/* eslint-enable no-var, vars-on-top*/

‎lib/types/OpenApiDefinition.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export type OpenApiDefinition = {
1111
name: string;
1212
url: string;
1313
email: string;
14-
discord: string;
1514
};
1615
license: {
1716
name: string;
@@ -23,19 +22,11 @@ export type OpenApiDefinition = {
2322
description: string;
2423
url: string;
2524
};
26-
servers: Array<{
27-
url: string;
28-
description: string;
29-
variables: {
30-
baseUrl: { default: string };
31-
port: { default: number };
32-
};
33-
}>;
3425
tags: Array<{
3526
description: string;
3627
name: string;
3728
}>;
3829
schemes: string[];
3930
paths: JSONObject;
40-
components: JSONObject;
31+
components?: JSONObject;
4132
};

‎lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.ts

+20
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,26 @@ export type StorageEngineElasticsearch = {
317317
};
318318
};
319319
};
320+
imports: {
321+
settings: {
322+
/**
323+
* @default 1
324+
*/
325+
number_of_shards: number;
326+
327+
/**
328+
* @default 1
329+
*/
330+
number_of_replicas: number;
331+
};
332+
333+
mappings: {
334+
dynamic: "strict";
335+
properties: {
336+
hash: { type: "keyword" };
337+
};
338+
};
339+
};
320340
};
321341
};
322342
maxScrollDuration: string;

‎package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kuzzle",
33
"author": "The Kuzzle Team <support@kuzzle.io>",
4-
"version": "2.29.0",
4+
"version": "2.29.1-beta.2",
55
"description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
66
"bin": "bin/start-kuzzle-server",
77
"scripts": {

‎test/api/OpenApiManager.test.js

-11
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,9 @@ describe("OpenApiManager", () => {
3737
description: "Kuzzle API Documentation",
3838
url: "https://docs.kuzzle.io/core/2/api/",
3939
},
40-
servers: [
41-
{
42-
url: "https://{baseUrl}:{port}",
43-
description: "Kuzzle Base Url",
44-
variables: {
45-
baseUrl: { default: "localhost" },
46-
port: { default: 7512 },
47-
},
48-
},
49-
],
5040
tags: [],
5141
schemes: ["https", "http"],
5242
paths: {},
53-
components: {},
5443
};
5544

5645
pluginsRoutes = [

‎test/kuzzle/kuzzle.test.js

+147-2
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,11 @@ describe("/lib/kuzzle/kuzzle.js", () => {
370370
let mappingsPayload;
371371
let permissionsPayload;
372372
let fixturesPayload;
373+
let userMappingsPayload;
373374

374375
beforeEach(() => {
376+
userMappingsPayload = { something: "here" };
377+
375378
mappingsPayload = {
376379
toImport: {
377380
mappings: { something: "here" },
@@ -407,13 +410,13 @@ describe("/lib/kuzzle/kuzzle.js", () => {
407410
onExistingUsers: "skip",
408411
profiles: permissionsPayload.toImport.profiles,
409412
roles: permissionsPayload.toImport.roles,
410-
userMappings: { something: "here" },
413+
userMappings: userMappingsPayload,
411414
users: permissionsPayload.toImport.users,
412415
};
413416

414417
toSupport = {
415-
mappings: mappingsPayload.toSupport.mappings,
416418
fixtures: fixturesPayload.toSupport.fixtures,
419+
mappings: mappingsPayload.toSupport.mappings,
417420
securities: permissionsPayload.toSupport.securities,
418421
};
419422

@@ -576,5 +579,147 @@ describe("/lib/kuzzle/kuzzle.js", () => {
576579
),
577580
).be.rejectedWith({ id: "plugin.runtime.incompatible" });
578581
});
582+
583+
it("should ensure to persist hash of the importedPayload when nor Redis nor ES have a hash", async () => {
584+
kuzzle.ask.withArgs("core:cache:internal:get").resolves(null);
585+
kuzzle.ask
586+
.withArgs("core:storage:private:document:exist")
587+
.resolves(false);
588+
kuzzle._waitForImportToFinish = sinon.stub().resolves();
589+
kuzzle.persistHashedImport = sinon.stub().resolves();
590+
591+
await kuzzle.loadInitialState(toImport, {});
592+
593+
should(kuzzle.persistHashedImport).calledWith({
594+
existingESHash: false,
595+
existingRedisHash: null,
596+
importPayloadHash: sha256(
597+
stringify({
598+
toImport: fixturesPayload.toImport,
599+
toSupport: {},
600+
}),
601+
),
602+
type: "fixtures",
603+
});
604+
605+
should(kuzzle.persistHashedImport).calledWith({
606+
existingESHash: false,
607+
existingRedisHash: null,
608+
importPayloadHash: sha256(
609+
stringify({
610+
toImport: mappingsPayload.toImport,
611+
toSupport: {},
612+
}),
613+
),
614+
type: "mappings",
615+
});
616+
617+
should(kuzzle.persistHashedImport).calledWith({
618+
existingESHash: false,
619+
existingRedisHash: null,
620+
importPayloadHash: sha256(
621+
stringify({
622+
toImport: permissionsPayload.toImport,
623+
toSupport: {},
624+
}),
625+
),
626+
type: "permissions",
627+
});
628+
});
629+
630+
it("should ensure to persist hash of the importedPayload when ES have a hash and not redis", async () => {
631+
kuzzle.ask.withArgs("core:cache:internal:get").resolves(null);
632+
kuzzle.ask.withArgs("core:storage:private:document:exist").resolves(true);
633+
kuzzle.ask
634+
.withArgs("core:storage:private:document:get")
635+
.resolves({ _source: { hash: "123" } });
636+
kuzzle._waitForImportToFinish = sinon.stub().resolves();
637+
kuzzle.persistHashedImport = sinon.stub().resolves();
638+
639+
await kuzzle.loadInitialState(toImport, {});
640+
641+
should(kuzzle.persistHashedImport).calledWith({
642+
existingESHash: true,
643+
existingRedisHash: null,
644+
importPayloadHash: sha256(
645+
stringify({
646+
toImport: fixturesPayload.toImport,
647+
toSupport: {},
648+
}),
649+
),
650+
type: "fixtures",
651+
});
652+
653+
should(kuzzle.persistHashedImport).calledWith({
654+
existingESHash: true,
655+
existingRedisHash: null,
656+
importPayloadHash: sha256(
657+
stringify({
658+
toImport: mappingsPayload.toImport,
659+
toSupport: {},
660+
}),
661+
),
662+
type: "mappings",
663+
});
664+
665+
should(kuzzle.persistHashedImport).calledWith({
666+
existingESHash: true,
667+
existingRedisHash: null,
668+
importPayloadHash: sha256(
669+
stringify({
670+
toImport: permissionsPayload.toImport,
671+
toSupport: {},
672+
}),
673+
),
674+
type: "permissions",
675+
});
676+
});
677+
678+
it("should ensure to persist hash of the importedPayload when Redis have a hash and not ES", async () => {
679+
kuzzle.ask.withArgs("core:cache:internal:get").resolves("123");
680+
kuzzle.ask
681+
.withArgs("core:storage:private:document:exist")
682+
.resolves(false);
683+
kuzzle._waitForImportToFinish = sinon.stub().resolves();
684+
kuzzle.persistHashedImport = sinon.stub().resolves();
685+
686+
await kuzzle.loadInitialState(toImport, {});
687+
688+
should(kuzzle.persistHashedImport).calledWith({
689+
existingESHash: false,
690+
existingRedisHash: "123",
691+
importPayloadHash: sha256(
692+
stringify({
693+
toImport: fixturesPayload.toImport,
694+
toSupport: {},
695+
}),
696+
),
697+
type: "fixtures",
698+
});
699+
700+
should(kuzzle.persistHashedImport).calledWith({
701+
existingESHash: false,
702+
existingRedisHash: "123",
703+
importPayloadHash: sha256(
704+
stringify({
705+
toImport: mappingsPayload.toImport,
706+
toSupport: {},
707+
}),
708+
),
709+
type: "mappings",
710+
});
711+
712+
should(kuzzle.persistHashedImport).calledWith({
713+
existingESHash: false,
714+
existingRedisHash: "123",
715+
importPayloadHash: sha256(
716+
stringify({
717+
toImport: permissionsPayload.toImport,
718+
toSupport: {},
719+
}),
720+
),
721+
type: "permissions",
722+
});
723+
});
579724
});
580725
});

0 commit comments

Comments
 (0)
Please sign in to comment.