@webda/core 2.0.0-beta.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/application.d.ts +5 -5
- package/lib/application.js +71 -84
- package/lib/application.js.map +1 -1
- package/lib/application.spec.js +121 -140
- package/lib/application.spec.js.map +1 -1
- package/lib/core.d.ts +21 -25
- package/lib/core.js +233 -320
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +334 -406
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +49 -48
- package/lib/index.js +53 -70
- package/lib/index.js.map +1 -1
- package/lib/models/aclmodel.d.ts +2 -2
- package/lib/models/aclmodel.js +63 -90
- package/lib/models/aclmodel.js.map +1 -1
- package/lib/models/aclmodel.spec.js +128 -152
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +33 -14
- package/lib/models/coremodel.js +160 -117
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +143 -107
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/deployment.js +1 -2
- package/lib/models/ident.d.ts +3 -3
- package/lib/models/ident.js +4 -9
- package/lib/models/ident.js.map +1 -1
- package/lib/models/ident.spec.js +9 -11
- package/lib/models/ident.spec.js.map +1 -1
- package/lib/models/ownermodel.d.ts +2 -2
- package/lib/models/ownermodel.js +39 -62
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/ownermodel.spec.js +126 -168
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/rolemodel.d.ts +1 -1
- package/lib/models/rolemodel.js +24 -40
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +44 -63
- package/lib/models/rolemodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +9 -9
- package/lib/models/user.js +3 -8
- package/lib/models/user.js.map +1 -1
- package/lib/models/user.spec.js +14 -16
- package/lib/models/user.spec.js.map +1 -1
- package/lib/queues/filequeue.d.ts +2 -2
- package/lib/queues/filequeue.js +72 -93
- package/lib/queues/filequeue.js.map +1 -1
- package/lib/queues/filequeue.spec.js +53 -70
- package/lib/queues/filequeue.spec.js.map +1 -1
- package/lib/queues/memoryqueue.d.ts +2 -2
- package/lib/queues/memoryqueue.js +37 -61
- package/lib/queues/memoryqueue.js.map +1 -1
- package/lib/queues/memoryqueue.spec.js +142 -165
- package/lib/queues/memoryqueue.spec.js.map +1 -1
- package/lib/queues/pubsubservice.d.ts +2 -2
- package/lib/queues/pubsubservice.js +3 -7
- package/lib/queues/pubsubservice.js.map +1 -1
- package/lib/queues/queue.spec.d.ts +1 -1
- package/lib/queues/queue.spec.js +42 -56
- package/lib/queues/queue.spec.js.map +1 -1
- package/lib/queues/queueservice.d.ts +3 -3
- package/lib/queues/queueservice.js +51 -67
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.d.ts +3 -3
- package/lib/router.js +46 -47
- package/lib/router.js.map +1 -1
- package/lib/router.spec.js +64 -61
- package/lib/router.spec.js.map +1 -1
- package/lib/services/asyncevents.d.ts +2 -2
- package/lib/services/asyncevents.js +44 -64
- package/lib/services/asyncevents.js.map +1 -1
- package/lib/services/asyncevents.spec.js +81 -98
- package/lib/services/asyncevents.spec.js.map +1 -1
- package/lib/services/authentication.d.ts +23 -13
- package/lib/services/authentication.js +540 -566
- package/lib/services/authentication.js.map +1 -1
- package/lib/services/authentication.spec.js +411 -447
- package/lib/services/authentication.spec.js.map +1 -1
- package/lib/services/binary.d.ts +8 -6
- package/lib/services/binary.js +212 -245
- package/lib/services/binary.js.map +1 -1
- package/lib/services/binary.spec.d.ts +3 -3
- package/lib/services/binary.spec.js +390 -443
- package/lib/services/binary.spec.js.map +1 -1
- package/lib/services/cloudbinary.d.ts +3 -3
- package/lib/services/cloudbinary.js +45 -70
- package/lib/services/cloudbinary.js.map +1 -1
- package/lib/services/cloudbinary.spec.d.ts +3 -3
- package/lib/services/cloudbinary.spec.js +133 -162
- package/lib/services/cloudbinary.spec.js.map +1 -1
- package/lib/services/configuration.d.ts +1 -1
- package/lib/services/configuration.js +78 -105
- package/lib/services/configuration.js.map +1 -1
- package/lib/services/configuration.spec.js +63 -83
- package/lib/services/configuration.spec.js.map +1 -1
- package/lib/services/cron.d.ts +3 -2
- package/lib/services/cron.js +9 -13
- package/lib/services/cron.js.map +1 -1
- package/lib/services/cron.spec.js +18 -21
- package/lib/services/cron.spec.js.map +1 -1
- package/lib/services/cryptoservice.d.ts +9 -4
- package/lib/services/cryptoservice.js +187 -221
- package/lib/services/cryptoservice.js.map +1 -1
- package/lib/services/cryptoservice.spec.js +88 -115
- package/lib/services/cryptoservice.spec.js.map +1 -1
- package/lib/services/debugmailer.d.ts +1 -1
- package/lib/services/debugmailer.js +13 -34
- package/lib/services/debugmailer.js.map +1 -1
- package/lib/services/debugmailer.spec.js +16 -29
- package/lib/services/debugmailer.spec.js.map +1 -1
- package/lib/services/echo.d.ts +2 -2
- package/lib/services/echo.js +15 -31
- package/lib/services/echo.js.map +1 -1
- package/lib/services/echo.spec.js +27 -40
- package/lib/services/echo.spec.js.map +1 -1
- package/lib/services/filebinary.d.ts +5 -5
- package/lib/services/filebinary.js +165 -210
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +2 -1
- package/lib/services/filebinary.spec.js +106 -116
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +1 -1
- package/lib/services/fileconfiguration.js +25 -44
- package/lib/services/fileconfiguration.js.map +1 -1
- package/lib/services/fileconfiguration.spec.js +79 -109
- package/lib/services/fileconfiguration.spec.js.map +1 -1
- package/lib/services/invitationservice.d.ts +8 -8
- package/lib/services/invitationservice.js +274 -314
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +443 -449
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +1 -1
- package/lib/services/kubernetesconfiguration.js +41 -60
- package/lib/services/kubernetesconfiguration.js.map +1 -1
- package/lib/services/kubernetesconfiguration.spec.js +80 -98
- package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
- package/lib/services/mailer.d.ts +4 -4
- package/lib/services/mailer.js +62 -86
- package/lib/services/mailer.js.map +1 -1
- package/lib/services/mailer.spec.js +86 -127
- package/lib/services/mailer.spec.js.map +1 -1
- package/lib/services/notificationservice.d.ts +3 -3
- package/lib/services/notificationservice.js +21 -42
- package/lib/services/notificationservice.js.map +1 -1
- package/lib/services/notificationservice.spec.js +47 -73
- package/lib/services/notificationservice.spec.js.map +1 -1
- package/lib/services/oauth.d.ts +4 -4
- package/lib/services/oauth.js +68 -83
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +130 -156
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/proxy.d.ts +2 -6
- package/lib/services/proxy.js +45 -58
- package/lib/services/proxy.js.map +1 -1
- package/lib/services/proxy.spec.js +34 -53
- package/lib/services/proxy.spec.js.map +1 -1
- package/lib/services/resource.d.ts +2 -2
- package/lib/services/resource.js +12 -18
- package/lib/services/resource.js.map +1 -1
- package/lib/services/resource.spec.js +67 -99
- package/lib/services/resource.spec.js.map +1 -1
- package/lib/services/service.d.ts +26 -3
- package/lib/services/service.js +68 -40
- package/lib/services/service.js.map +1 -1
- package/lib/services/service.spec.js +62 -67
- package/lib/services/service.spec.js.map +1 -1
- package/lib/services/version.d.ts +1 -1
- package/lib/services/version.js +3 -8
- package/lib/services/version.js.map +1 -1
- package/lib/services/version.spec.js +11 -24
- package/lib/services/version.spec.js.map +1 -1
- package/lib/stores/aggregator.d.ts +2 -2
- package/lib/stores/aggregator.js +37 -58
- package/lib/stores/aggregator.js.map +1 -1
- package/lib/stores/file.d.ts +3 -3
- package/lib/stores/file.js +93 -131
- package/lib/stores/file.js.map +1 -1
- package/lib/stores/file.spec.d.ts +2 -2
- package/lib/stores/file.spec.js +262 -289
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +3 -3
- package/lib/stores/mapper.js +110 -137
- package/lib/stores/mapper.js.map +1 -1
- package/lib/stores/mapper.spec.js +133 -150
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.d.ts +3 -3
- package/lib/stores/memory.js +98 -144
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +2 -2
- package/lib/stores/memory.spec.js +124 -145
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +27 -17
- package/lib/stores/store.js +833 -849
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +5 -4
- package/lib/stores/store.spec.js +625 -669
- package/lib/stores/store.spec.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
- package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
- package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
- package/lib/stores/webdaql/query.d.ts +4 -5
- package/lib/stores/webdaql/query.js +16 -19
- package/lib/stores/webdaql/query.js.map +1 -1
- package/lib/stores/webdaql/query.spec.js +30 -32
- package/lib/stores/webdaql/query.spec.js.map +1 -1
- package/lib/test.d.ts +3 -3
- package/lib/test.js +73 -100
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +1 -1
- package/lib/unpackedapplication.js +49 -39
- package/lib/unpackedapplication.js.map +1 -1
- package/lib/utils/abstractdeployer.js +1 -5
- package/lib/utils/abstractdeployer.js.map +1 -1
- package/lib/utils/abstractdeployer.spec.js +6 -8
- package/lib/utils/abstractdeployer.spec.js.map +1 -1
- package/lib/utils/context.d.ts +7 -5
- package/lib/utils/context.js +95 -103
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +139 -163
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +3 -3
- package/lib/utils/cookie.js +42 -61
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +42 -64
- package/lib/utils/cookie.spec.js.map +1 -1
- package/lib/utils/esm.d.ts +4 -0
- package/lib/utils/esm.js +10 -0
- package/lib/utils/esm.js.map +1 -0
- package/lib/utils/httpcontext.d.ts +3 -0
- package/lib/utils/httpcontext.js +48 -65
- package/lib/utils/httpcontext.js.map +1 -1
- package/lib/utils/httpcontext.spec.js +37 -56
- package/lib/utils/httpcontext.spec.js.map +1 -1
- package/lib/utils/logger.d.ts +2 -2
- package/lib/utils/logger.js +15 -28
- package/lib/utils/logger.js.map +1 -1
- package/lib/utils/logger.spec.js +9 -11
- package/lib/utils/logger.spec.js.map +1 -1
- package/lib/utils/serializers.js +17 -20
- package/lib/utils/serializers.js.map +1 -1
- package/lib/utils/serializers.spec.js +43 -44
- package/lib/utils/serializers.spec.js.map +1 -1
- package/lib/utils/session.d.ts +6 -6
- package/lib/utils/session.js +37 -59
- package/lib/utils/session.js.map +1 -1
- package/lib/utils/session.spec.js +38 -51
- package/lib/utils/session.spec.js.map +1 -1
- package/lib/utils/waiter.d.ts +1 -1
- package/lib/utils/waiter.js +32 -52
- package/lib/utils/waiter.js.map +1 -1
- package/lib/utils/waiter.spec.js +75 -92
- package/lib/utils/waiter.spec.js.map +1 -1
- package/package.json +18 -13
- package/test/config-invitation.json +1 -3
- package/test/config.json +1 -2
- package/test/config.old.json +1 -2
- package/test/moddas/annotatedservice.js +5 -5
- package/test/moddas/debugmailer.js +2 -3
- package/test/moddas/fakeservice.js +2 -3
- package/test/moddas/voidstore.js +6 -4
- package/test/models/ident.js +2 -6
- package/test/models/task.js +3 -7
- package/test/package.json +2 -1
- package/webda.module.json +895 -190
|
@@ -1,34 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
exports.BinaryTest = exports.ImageUser = void 0;
|
|
19
|
-
const mocha_1 = require("@testdeck/mocha");
|
|
20
|
-
const assert = require("assert");
|
|
21
|
-
const axios_1 = require("axios");
|
|
22
|
-
const events_1 = require("events");
|
|
23
|
-
const fs = require("fs");
|
|
24
|
-
const sinon = require("sinon");
|
|
25
|
-
const __1 = require("..");
|
|
26
|
-
const test_1 = require("../test");
|
|
27
|
-
const binary_1 = require("./binary");
|
|
28
|
-
class ImageUser extends __1.User {
|
|
7
|
+
import { suite, test } from "@testdeck/mocha";
|
|
8
|
+
import * as assert from "assert";
|
|
9
|
+
import axios from "axios";
|
|
10
|
+
import { EventEmitter } from "events";
|
|
11
|
+
import * as fs from "fs";
|
|
12
|
+
import * as sinon from "sinon";
|
|
13
|
+
import { Binary, User } from "../index.js";
|
|
14
|
+
import { WebdaTest } from "../test.js";
|
|
15
|
+
import { BinaryNotFoundError, LocalBinaryFile, MemoryBinaryFile } from "./binary.js";
|
|
16
|
+
export class ImageUser extends User {
|
|
29
17
|
}
|
|
30
|
-
|
|
31
|
-
class TestBinaryService extends __1.Binary {
|
|
18
|
+
class TestBinaryService extends Binary {
|
|
32
19
|
store(object, property, file, metadatas, index) {
|
|
33
20
|
throw new Error("Method not implemented.");
|
|
34
21
|
}
|
|
@@ -47,11 +34,9 @@ class TestBinaryService extends __1.Binary {
|
|
|
47
34
|
_get() {
|
|
48
35
|
return null;
|
|
49
36
|
}
|
|
50
|
-
cascadeDelete() {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () { });
|
|
52
|
-
}
|
|
37
|
+
async cascadeDelete() { }
|
|
53
38
|
}
|
|
54
|
-
class BinaryTest extends
|
|
39
|
+
class BinaryTest extends WebdaTest {
|
|
55
40
|
getUserStore() {
|
|
56
41
|
return this.getService("Users");
|
|
57
42
|
}
|
|
@@ -67,202 +52,183 @@ class BinaryTest extends test_1.WebdaTest {
|
|
|
67
52
|
getTestFile() {
|
|
68
53
|
return process.cwd() + "/test/Dockerfile.txt";
|
|
69
54
|
}
|
|
70
|
-
before(init = true) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
assert.notStrictEqual(userStore, undefined);
|
|
79
|
-
assert.notStrictEqual(binary, undefined);
|
|
80
|
-
yield userStore.__clean();
|
|
81
|
-
yield binary.__clean();
|
|
82
|
-
});
|
|
55
|
+
async before(init = true) {
|
|
56
|
+
await super.before(init);
|
|
57
|
+
let userStore = this.getUserStore();
|
|
58
|
+
let binary = this.getBinary();
|
|
59
|
+
assert.notStrictEqual(userStore, undefined);
|
|
60
|
+
assert.notStrictEqual(binary, undefined);
|
|
61
|
+
await userStore.__clean();
|
|
62
|
+
await binary.__clean();
|
|
83
63
|
}
|
|
84
|
-
normal() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
eventFired++;
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
// Check CREATE - READ
|
|
98
|
-
var hash;
|
|
99
|
-
var user1;
|
|
100
|
-
var user2;
|
|
101
|
-
var user;
|
|
102
|
-
var ctx;
|
|
103
|
-
this.log("DEBUG", "Initializing users");
|
|
104
|
-
user1 = yield userStore.save({
|
|
105
|
-
test: "plop"
|
|
106
|
-
});
|
|
107
|
-
user2 = yield userStore.save({
|
|
108
|
-
test: "plop"
|
|
109
|
-
});
|
|
110
|
-
this.log("DEBUG", "Store a local file");
|
|
111
|
-
yield binary.store(user1, map, new binary_1.LocalBinaryFile(this.getTestFile()), {});
|
|
112
|
-
user1 = yield userStore.get(user1.uuid);
|
|
113
|
-
assert.notStrictEqual(user1[map], undefined);
|
|
114
|
-
assert.strictEqual(user1[map].length, 1);
|
|
115
|
-
hash = user1[map][0].hash;
|
|
116
|
-
this.log("DEBUG", "Get usage count");
|
|
117
|
-
let value = yield binary.getUsageCount(hash);
|
|
118
|
-
assert.strictEqual(value, 1);
|
|
119
|
-
this.log("DEBUG", "Store same local file on separate object");
|
|
120
|
-
yield binary.store(user2, map, new binary_1.LocalBinaryFile(this.getTestFile()), {});
|
|
121
|
-
user = yield userStore.get(user2.uuid);
|
|
122
|
-
assert.notStrictEqual(user[map], undefined);
|
|
123
|
-
assert.strictEqual(user[map].length, 1);
|
|
124
|
-
assert.strictEqual(user[map][0].constructor.name, "BinaryMap");
|
|
125
|
-
hash = user[map][0].hash;
|
|
126
|
-
this.log("DEBUG", "Verify usage count");
|
|
127
|
-
value = yield binary.getUsageCount(hash);
|
|
128
|
-
assert.strictEqual(value, 2);
|
|
129
|
-
this.log("DEBUG", "Delete one attached object");
|
|
130
|
-
yield binary.delete(user, map, 0);
|
|
131
|
-
user = yield userStore.get(user2.uuid);
|
|
132
|
-
assert.strictEqual(user[map].length, 0);
|
|
133
|
-
this.log("DEBUG", "Verify usage count decreased");
|
|
134
|
-
value = yield binary.getUsageCount(hash);
|
|
135
|
-
assert.strictEqual(value, 1);
|
|
136
|
-
// Try to get images on user1 as user2
|
|
137
|
-
ctx = yield this.newContext({
|
|
138
|
-
type: "CRUD",
|
|
139
|
-
uuid: "PLOP"
|
|
64
|
+
async normal() {
|
|
65
|
+
let userStore = this.getUserStore();
|
|
66
|
+
let binary = this.getBinary();
|
|
67
|
+
let map = this.getMap();
|
|
68
|
+
let exposePath = this.getExposePath();
|
|
69
|
+
var eventFired = 0;
|
|
70
|
+
var events = ["Binary.Get", "Binary.Create", "Binary.Delete"];
|
|
71
|
+
for (let evt in events) {
|
|
72
|
+
binary.on(events[evt], function () {
|
|
73
|
+
eventFired++;
|
|
140
74
|
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
75
|
+
}
|
|
76
|
+
// Check CREATE - READ
|
|
77
|
+
var hash;
|
|
78
|
+
var user1;
|
|
79
|
+
var user2;
|
|
80
|
+
var user;
|
|
81
|
+
var ctx;
|
|
82
|
+
this.log("DEBUG", "Initializing users");
|
|
83
|
+
user1 = await userStore.save({
|
|
84
|
+
test: "plop"
|
|
85
|
+
});
|
|
86
|
+
user2 = await userStore.save({
|
|
87
|
+
test: "plop"
|
|
88
|
+
});
|
|
89
|
+
this.log("DEBUG", "Store a local file");
|
|
90
|
+
await binary.store(user1, map, new LocalBinaryFile(this.getTestFile()), {});
|
|
91
|
+
user1 = await userStore.get(user1.uuid);
|
|
92
|
+
assert.notStrictEqual(user1[map], undefined);
|
|
93
|
+
assert.strictEqual(user1[map].length, 1);
|
|
94
|
+
hash = user1[map][0].hash;
|
|
95
|
+
this.log("DEBUG", "Get usage count");
|
|
96
|
+
let value = await binary.getUsageCount(hash);
|
|
97
|
+
assert.strictEqual(value, 1);
|
|
98
|
+
this.log("DEBUG", "Store same local file on separate object");
|
|
99
|
+
await binary.store(user2, map, new LocalBinaryFile(this.getTestFile()), {});
|
|
100
|
+
user = await userStore.get(user2.uuid);
|
|
101
|
+
assert.notStrictEqual(user[map], undefined);
|
|
102
|
+
assert.strictEqual(user[map].length, 1);
|
|
103
|
+
assert.strictEqual(user[map][0].constructor.name, "BinaryMap");
|
|
104
|
+
hash = user[map][0].hash;
|
|
105
|
+
this.log("DEBUG", "Verify usage count");
|
|
106
|
+
value = await binary.getUsageCount(hash);
|
|
107
|
+
assert.strictEqual(value, 2);
|
|
108
|
+
this.log("DEBUG", "Delete one attached object");
|
|
109
|
+
await binary.delete(user, map, 0);
|
|
110
|
+
user = await userStore.get(user2.uuid);
|
|
111
|
+
assert.strictEqual(user[map].length, 0);
|
|
112
|
+
this.log("DEBUG", "Verify usage count decreased");
|
|
113
|
+
value = await binary.getUsageCount(hash);
|
|
114
|
+
assert.strictEqual(value, 1);
|
|
115
|
+
// Try to get images on user1 as user2
|
|
116
|
+
ctx = await this.newContext({
|
|
117
|
+
type: "CRUD",
|
|
118
|
+
uuid: "PLOP"
|
|
119
|
+
});
|
|
120
|
+
ctx.session.userId = user2.uuid;
|
|
121
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "GET", exposePath + "/users/" + user1.uuid + "/" + map + "/0");
|
|
122
|
+
this.log("DEBUG", "Verify permission check on HTTP GET");
|
|
123
|
+
await assert.rejects(executor.execute(ctx), res => res == 403);
|
|
124
|
+
ctx.session.userId = user1.uuid;
|
|
125
|
+
this.log("DEBUG", "Verify valid permission check on HTTP GET");
|
|
126
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", exposePath + "/users/" + user1.uuid + "/" + map + "/0");
|
|
127
|
+
await executor.execute(ctx);
|
|
128
|
+
// We dont check for result as FileBinary will return datas and S3 a redirect
|
|
129
|
+
if (fs.existsSync("./downloadTo.tmp")) {
|
|
161
130
|
fs.unlinkSync("./downloadTo.tmp");
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
});
|
|
178
|
-
yield assert.rejects(() => binary.downloadTo(user1[map][0], "./downloadTo.tmp"));
|
|
179
|
-
}
|
|
180
|
-
finally {
|
|
181
|
-
stub.restore();
|
|
182
|
-
if (stub2) {
|
|
183
|
-
stub2.restore();
|
|
131
|
+
}
|
|
132
|
+
this.log("DEBUG", "BinaryMap downloadTo");
|
|
133
|
+
await binary.downloadTo(user1[map][0], "./downloadTo.tmp");
|
|
134
|
+
// Check the result is the same
|
|
135
|
+
assert.strictEqual(fs.readFileSync("./downloadTo.tmp").toString(), fs.readFileSync(this.getTestFile()).toString());
|
|
136
|
+
fs.unlinkSync("./downloadTo.tmp");
|
|
137
|
+
this.log("DEBUG", "BinaryMap downloadTo from CoreModel");
|
|
138
|
+
await user1[map][0].downloadTo("./downloadTo.tmp");
|
|
139
|
+
assert.strictEqual(fs.readFileSync("./downloadTo.tmp").toString(), fs.readFileSync(this.getTestFile()).toString());
|
|
140
|
+
fs.unlinkSync("./downloadTo.tmp");
|
|
141
|
+
// Fake IO issue
|
|
142
|
+
let stub = sinon.stub(binary, "_get").callsFake(() => {
|
|
143
|
+
return {
|
|
144
|
+
pipe: stream => {
|
|
145
|
+
stream.emit("error", "bad read");
|
|
184
146
|
}
|
|
185
|
-
}
|
|
186
|
-
this.log("DEBUG", "Check get stream");
|
|
187
|
-
let buf1 = yield __1.Binary.streamToBuffer(yield user1[map][0].get());
|
|
188
|
-
// cov
|
|
189
|
-
let buf2 = yield __1.Binary.streamToBuffer(yield binary._get(user1[map][0]));
|
|
190
|
-
assert.strictEqual(buf1.toString(), buf2.toString());
|
|
191
|
-
this.log("DEBUG", "Delete CoreModel and ensure usage count");
|
|
192
|
-
yield userStore.delete(user1.uuid);
|
|
193
|
-
value = yield binary.getUsageCount(hash);
|
|
194
|
-
assert.strictEqual(value, 0);
|
|
147
|
+
};
|
|
195
148
|
});
|
|
149
|
+
let stub2;
|
|
150
|
+
try {
|
|
151
|
+
this.log("DEBUG", "BinaryMap downloadTo with I/O issues");
|
|
152
|
+
await assert.rejects(() => binary.downloadTo(user1[map][0], "./downloadTo.tmp"));
|
|
153
|
+
assert.ok(!fs.existsSync("./downloadTo.tmp"));
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
stub.restore();
|
|
157
|
+
if (stub2) {
|
|
158
|
+
stub2.restore();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
this.log("DEBUG", "Check get stream");
|
|
162
|
+
let buf1 = await Binary.streamToBuffer(await user1[map][0].get());
|
|
163
|
+
// cov
|
|
164
|
+
let buf2 = await Binary.streamToBuffer(await binary._get(user1[map][0]));
|
|
165
|
+
assert.strictEqual(buf1.toString(), buf2.toString());
|
|
166
|
+
this.log("DEBUG", "Delete CoreModel and ensure usage count");
|
|
167
|
+
await userStore.delete(user1.uuid);
|
|
168
|
+
value = await binary.getUsageCount(hash);
|
|
169
|
+
assert.strictEqual(value, 0);
|
|
196
170
|
}
|
|
197
|
-
notMapped() {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
test: "plop"
|
|
203
|
-
});
|
|
204
|
-
yield assert.rejects(() => binary.store(user1, "images2", new binary_1.LocalBinaryFile(this.getTestFile()), {}), err => true);
|
|
171
|
+
async notMapped() {
|
|
172
|
+
let userStore = this.getUserStore();
|
|
173
|
+
let binary = this.getBinary();
|
|
174
|
+
let user1 = await userStore.save({
|
|
175
|
+
test: "plop"
|
|
205
176
|
});
|
|
177
|
+
await assert.rejects(() => binary.store(user1, "images2", new LocalBinaryFile(this.getTestFile()), {}), err => true);
|
|
206
178
|
}
|
|
207
|
-
update() {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
test: "plop"
|
|
217
|
-
});
|
|
218
|
-
yield binary.store(user1, map, new binary_1.LocalBinaryFile(this.getTestFile()), {});
|
|
219
|
-
user = yield userStore.get(user1.uuid);
|
|
220
|
-
assert.notStrictEqual(user[map], undefined);
|
|
221
|
-
assert.strictEqual(user[map].length, 1);
|
|
222
|
-
let value = yield binary.getUsageCount(user[map][0].hash);
|
|
223
|
-
assert.strictEqual(value, 1);
|
|
179
|
+
async update() {
|
|
180
|
+
let userStore = this.getUserStore();
|
|
181
|
+
let binary = this.getBinary();
|
|
182
|
+
let map = this.getMap();
|
|
183
|
+
var user1;
|
|
184
|
+
var user;
|
|
185
|
+
let hash;
|
|
186
|
+
user1 = await userStore.save({
|
|
187
|
+
test: "plop"
|
|
224
188
|
});
|
|
189
|
+
await binary.store(user1, map, new LocalBinaryFile(this.getTestFile()), {});
|
|
190
|
+
user = await userStore.get(user1.uuid);
|
|
191
|
+
assert.notStrictEqual(user[map], undefined);
|
|
192
|
+
assert.strictEqual(user[map].length, 1);
|
|
193
|
+
let value = await binary.getUsageCount(user[map][0].hash);
|
|
194
|
+
assert.strictEqual(value, 1);
|
|
225
195
|
}
|
|
226
196
|
checkMap() {
|
|
227
197
|
let binary = this.getBinary();
|
|
228
198
|
// @ts-ignore
|
|
229
199
|
assert.throws(() => binary.checkMap("plop", "pouf"), /Unknown mapping/);
|
|
230
200
|
}
|
|
231
|
-
httpCreate() {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
test: "plop"
|
|
236
|
-
});
|
|
237
|
-
let ctx = yield this.newContext();
|
|
238
|
-
let executor = this.getExecutor(ctx, "test.webda.io", "POST", `/binary/users/${user1.getUuid()}/images`, {});
|
|
239
|
-
yield assert.rejects(() => executor.execute(ctx), /403/);
|
|
240
|
-
/**
|
|
241
|
-
* Two modes should be handled
|
|
242
|
-
*
|
|
243
|
-
* POST body + X-Webda-Metadatas header
|
|
244
|
-
* POST multipart
|
|
245
|
-
*/
|
|
246
|
-
ctx.getHttpContext().setBody("MY_IMAGE");
|
|
247
|
-
ctx.getSession().login(user1.getUuid(), "fake");
|
|
248
|
-
// Need to verify
|
|
249
|
-
yield executor.execute(ctx);
|
|
201
|
+
async httpCreate() {
|
|
202
|
+
let userStore = this.getUserStore();
|
|
203
|
+
let user1 = await userStore.save({
|
|
204
|
+
test: "plop"
|
|
250
205
|
});
|
|
206
|
+
let ctx = await this.newContext();
|
|
207
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "POST", `/binary/users/${user1.getUuid()}/images`, {});
|
|
208
|
+
await assert.rejects(() => executor.execute(ctx), /403/);
|
|
209
|
+
/**
|
|
210
|
+
* Two modes should be handled
|
|
211
|
+
*
|
|
212
|
+
* POST body + X-Webda-Metadatas header
|
|
213
|
+
* POST multipart
|
|
214
|
+
*/
|
|
215
|
+
ctx.getHttpContext().setBody("MY_IMAGE");
|
|
216
|
+
ctx.getSession().login(user1.getUuid(), "fake");
|
|
217
|
+
// Need to verify
|
|
218
|
+
await executor.execute(ctx);
|
|
251
219
|
}
|
|
252
|
-
httpDelete() {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
assert.ok(user1.images.length === 0);
|
|
265
|
-
});
|
|
220
|
+
async httpDelete() {
|
|
221
|
+
let { user1, ctx } = await this.setupDefault(false);
|
|
222
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "DELETE", `/binary/users/${user1.getUuid()}/images/0/myhash`, {});
|
|
223
|
+
await assert.rejects(() => executor.execute(ctx), /403/, "DELETE binary w/o permission");
|
|
224
|
+
// Now login
|
|
225
|
+
ctx.getSession().login(user1.getUuid(), "fake");
|
|
226
|
+
executor = this.getExecutor(ctx, "test.webda.io", "DELETE", `/binary/users/${user1.getUuid()}/images/0/myhash`, {});
|
|
227
|
+
await assert.rejects(() => executor.execute(ctx), /412/);
|
|
228
|
+
executor = this.getExecutor(ctx, "test.webda.io", "DELETE", `/binary/users/${user1.getUuid()}/images/0/${user1.images[0].hash}`, {});
|
|
229
|
+
await executor.execute(ctx);
|
|
230
|
+
await user1.refresh();
|
|
231
|
+
assert.ok(user1.images.length === 0);
|
|
266
232
|
}
|
|
267
233
|
getOperationName() {
|
|
268
234
|
let binary = this.getBinary();
|
|
@@ -273,288 +239,269 @@ class BinaryTest extends test_1.WebdaTest {
|
|
|
273
239
|
// @ts-ignore
|
|
274
240
|
assert.strictEqual(binary.getOperationName(), binary.getName());
|
|
275
241
|
}
|
|
276
|
-
httpGetError() {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
};
|
|
286
|
-
});
|
|
287
|
-
yield this.execute(ctx, "test.webda.io", "GET", `/binary/users/${user1.getUuid()}/images/0`, {});
|
|
288
|
-
yield assert.rejects(() => this.execute(ctx, "test.webda.io", "GET", ctx.getResponseHeaders().Location.substring("http://test.webda.io".length)), /500/, "GET binary with I/O");
|
|
289
|
-
stub.restore();
|
|
242
|
+
async httpGetError() {
|
|
243
|
+
let { binary, user1, ctx } = await this.setupDefault();
|
|
244
|
+
// @ts-ignore
|
|
245
|
+
let stub = sinon.stub(binary, "get").callsFake(() => {
|
|
246
|
+
return {
|
|
247
|
+
pipe: stream => {
|
|
248
|
+
stream.emit("error", new Error("I/O"));
|
|
249
|
+
}
|
|
250
|
+
};
|
|
290
251
|
});
|
|
252
|
+
await this.execute(ctx, "test.webda.io", "GET", `/binary/users/${user1.getUuid()}/images/0`, {});
|
|
253
|
+
await assert.rejects(() => this.execute(ctx, "test.webda.io", "GET", ctx.getResponseHeaders().Location.substring("http://test.webda.io".length)), /500/, "GET binary with I/O");
|
|
254
|
+
stub.restore();
|
|
291
255
|
}
|
|
292
|
-
httpGet() {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
yield assert.rejects(() => executor.execute(ctx), /404/);
|
|
308
|
-
});
|
|
256
|
+
async httpGet() {
|
|
257
|
+
let { binary, user1, ctx } = await this.setupDefault(false);
|
|
258
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "GET", `/binary/users/${user1.getUuid()}/images/0`, {});
|
|
259
|
+
// If not logged in
|
|
260
|
+
await assert.rejects(() => executor.execute(ctx), /403/, "GET binary w/o permission");
|
|
261
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", `/binary/users/unknown/images/0`, {});
|
|
262
|
+
await assert.rejects(() => executor.execute(ctx), /404/, "GET binary on unknown object");
|
|
263
|
+
// Login
|
|
264
|
+
ctx.getSession().login(user1.getUuid(), "fake");
|
|
265
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", `/binary/users/${user1.getUuid()}/images/0`, {});
|
|
266
|
+
await executor.execute(ctx);
|
|
267
|
+
await binary.delete(user1, "images", 0);
|
|
268
|
+
// Check 404 now it is gone
|
|
269
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", `/binary/users/${user1.getUuid()}/images/0`, {});
|
|
270
|
+
await assert.rejects(() => executor.execute(ctx), /404/);
|
|
309
271
|
}
|
|
310
|
-
httpMetadata() {
|
|
272
|
+
async httpMetadata() {
|
|
311
273
|
var _a;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
"my-metadata": "updated",
|
|
323
|
-
"my-other-metadata": true
|
|
324
|
-
});
|
|
325
|
-
yield executor.execute(ctx);
|
|
326
|
-
let user = yield ctx.getCurrentUser(true);
|
|
327
|
-
(_a = (_b = user.images[0]).metadata) !== null && _a !== void 0 ? _a : (_b.metadata = {});
|
|
328
|
-
assert.strictEqual(user.images[0].metadata["my-metadata"], "updated");
|
|
329
|
-
assert.strictEqual(user.images[0].metadata["my-other-metadata"], true);
|
|
330
|
-
executor = this.getExecutor(ctx, "test.webda.io", "PUT", `/binary/users/${user1.getUuid()}/images/0/${user1.images[0].hash}`, {
|
|
331
|
-
"my-metadata": "updated".repeat(4096),
|
|
332
|
-
"my-other-metadata": true
|
|
333
|
-
});
|
|
334
|
-
yield assert.rejects(() => executor.execute(ctx), /400/, "PUT metadata with big content should fail");
|
|
274
|
+
let { binary, user1, ctx } = await this.setupDefault(false);
|
|
275
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "PUT", `/binary/users/${user1.getUuid()}/images/0/${user1.images[0].hash}`, {}); // If not logged in
|
|
276
|
+
await assert.rejects(() => executor.execute(ctx), /403/, "PUT metadata w/o permission");
|
|
277
|
+
executor = this.getExecutor(ctx, "test.webda.io", "PUT", `/binary/users/unknown/images/0/${user1.images[0].hash}`, {});
|
|
278
|
+
await assert.rejects(() => executor.execute(ctx), /404/, "GET binary on unknown object");
|
|
279
|
+
// Login
|
|
280
|
+
ctx.getSession().login(user1.getUuid(), "fake");
|
|
281
|
+
executor = this.getExecutor(ctx, "test.webda.io", "PUT", `/binary/users/${user1.getUuid()}/images/0/${user1.images[0].hash}`, {
|
|
282
|
+
"my-metadata": "updated",
|
|
283
|
+
"my-other-metadata": true
|
|
335
284
|
});
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
size: 10
|
|
345
|
-
}), binary_1.BinaryNotFoundError);
|
|
285
|
+
await executor.execute(ctx);
|
|
286
|
+
let user = await ctx.getCurrentUser(true);
|
|
287
|
+
(_a = user.images[0]).metadata ?? (_a.metadata = {});
|
|
288
|
+
assert.strictEqual(user.images[0].metadata["my-metadata"], "updated");
|
|
289
|
+
assert.strictEqual(user.images[0].metadata["my-other-metadata"], true);
|
|
290
|
+
executor = this.getExecutor(ctx, "test.webda.io", "PUT", `/binary/users/${user1.getUuid()}/images/0/${user1.images[0].hash}`, {
|
|
291
|
+
"my-metadata": "updated".repeat(4096),
|
|
292
|
+
"my-other-metadata": true
|
|
346
293
|
});
|
|
294
|
+
await assert.rejects(() => executor.execute(ctx), /400/, "PUT metadata with big content should fail");
|
|
347
295
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
yield user1.refresh();
|
|
357
|
-
let ctx = yield this.newContext();
|
|
358
|
-
if (withLogin) {
|
|
359
|
-
ctx.getSession().login(user1.getUuid(), "fake");
|
|
360
|
-
}
|
|
361
|
-
user1.setContext(ctx);
|
|
362
|
-
return { userStore, binary, user1, ctx };
|
|
363
|
-
});
|
|
296
|
+
async getNotFound() {
|
|
297
|
+
await assert.rejects(() =>
|
|
298
|
+
// @ts-ignore
|
|
299
|
+
this.getBinary().get({
|
|
300
|
+
hash: "none",
|
|
301
|
+
mimetype: "",
|
|
302
|
+
size: 10
|
|
303
|
+
}), BinaryNotFoundError);
|
|
364
304
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
metadata
|
|
376
|
-
});
|
|
377
|
-
yield assert.rejects(() => executor.execute(ctx), /403/);
|
|
305
|
+
async setupDefault(withLogin = true) {
|
|
306
|
+
let userStore = this.getUserStore();
|
|
307
|
+
let binary = this.getBinary();
|
|
308
|
+
let user1 = await userStore.save({
|
|
309
|
+
test: "plop"
|
|
310
|
+
});
|
|
311
|
+
await binary.store(user1, "images", new LocalBinaryFile(this.getTestFile()));
|
|
312
|
+
await user1.refresh();
|
|
313
|
+
let ctx = await this.newContext();
|
|
314
|
+
if (withLogin) {
|
|
378
315
|
ctx.getSession().login(user1.getUuid(), "fake");
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
// If we try to re upload it should be already up
|
|
407
|
-
executor = this.getExecutor(ctx, "test.webda.io", "PUT", `/binary/upload/users/${user1.getUuid()}/images`, {
|
|
408
|
-
hash,
|
|
409
|
-
challenge,
|
|
410
|
-
metadata
|
|
316
|
+
}
|
|
317
|
+
user1.setContext(ctx);
|
|
318
|
+
return { userStore, binary, user1, ctx };
|
|
319
|
+
}
|
|
320
|
+
async testChallenge(remoteCheckHash = true) {
|
|
321
|
+
let { userStore, binary, user1, ctx } = await this.setupDefault(false);
|
|
322
|
+
let { hash, challenge } = await new MemoryBinaryFile(Buffer.from("PLOP"), {}).getHashes();
|
|
323
|
+
let metadata = {
|
|
324
|
+
plop: "test"
|
|
325
|
+
};
|
|
326
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "PUT", `/binary/upload/users/${user1.getUuid()}/images`, {
|
|
327
|
+
hash,
|
|
328
|
+
challenge,
|
|
329
|
+
metadata
|
|
330
|
+
});
|
|
331
|
+
await assert.rejects(() => executor.execute(ctx), /403/);
|
|
332
|
+
ctx.getSession().login(user1.getUuid(), "fake");
|
|
333
|
+
await executor.execute(ctx);
|
|
334
|
+
let info = JSON.parse(ctx.getResponseBody());
|
|
335
|
+
assert.ok(!info.done, "should not be done yet");
|
|
336
|
+
// Execute twice as we should still get an upload
|
|
337
|
+
await executor.execute(ctx);
|
|
338
|
+
let url = new URL(info.url);
|
|
339
|
+
if (url.host === "test.webda.io") {
|
|
340
|
+
executor = this.getExecutor(ctx, "test.webda.io", info.method || "PUT", url.pathname + url.search, "PLOP2", {
|
|
341
|
+
"Content-MD5": info.md5,
|
|
342
|
+
"Content-Type": "application/octet-stream"
|
|
411
343
|
});
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
// Use another user to try adding same binary
|
|
417
|
-
let user2 = yield userStore.save({});
|
|
418
|
-
ctx.getSession().login(user2.getUuid(), "fake");
|
|
419
|
-
executor = this.getExecutor(ctx, "test.webda.io", "PUT", `/binary/upload/users/${user2.getUuid()}/images`, {
|
|
420
|
-
hash,
|
|
421
|
-
challenge,
|
|
422
|
-
metadata
|
|
344
|
+
await assert.rejects(() => executor.execute(ctx));
|
|
345
|
+
executor = this.getExecutor(ctx, "test.webda.io", info.method || "PUT", url.pathname + url.search, "PLOP", {
|
|
346
|
+
"Content-MD5": info.md5,
|
|
347
|
+
"Content-Type": "application/octet-stream"
|
|
423
348
|
});
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
349
|
+
await executor.execute(ctx);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
if (remoteCheckHash) {
|
|
353
|
+
await assert.rejects(() => this.sendChallengeData(info, "PLOP2"), "Should check content");
|
|
354
|
+
}
|
|
355
|
+
await this.sendChallengeData(info, "PLOP");
|
|
356
|
+
}
|
|
357
|
+
await user1.refresh();
|
|
358
|
+
assert.strictEqual(user1.images.length, 2);
|
|
359
|
+
assert.strictEqual((await Binary.streamToBuffer(await binary.get(user1.images[1]))).toString(), "PLOP");
|
|
360
|
+
// If we try to re upload it should be already up
|
|
361
|
+
executor = this.getExecutor(ctx, "test.webda.io", "PUT", `/binary/upload/users/${user1.getUuid()}/images`, {
|
|
362
|
+
hash,
|
|
363
|
+
challenge,
|
|
364
|
+
metadata
|
|
428
365
|
});
|
|
366
|
+
await executor.execute(ctx);
|
|
367
|
+
info = JSON.parse(ctx.getResponseBody());
|
|
368
|
+
assert.ok(info.done, "should be done");
|
|
369
|
+
assert.ok(info.url === undefined);
|
|
370
|
+
// Use another user to try adding same binary
|
|
371
|
+
let user2 = await userStore.save({});
|
|
372
|
+
ctx.getSession().login(user2.getUuid(), "fake");
|
|
373
|
+
executor = this.getExecutor(ctx, "test.webda.io", "PUT", `/binary/upload/users/${user2.getUuid()}/images`, {
|
|
374
|
+
hash,
|
|
375
|
+
challenge,
|
|
376
|
+
metadata
|
|
377
|
+
});
|
|
378
|
+
await executor.execute(ctx);
|
|
379
|
+
info = JSON.parse(ctx.getResponseBody());
|
|
380
|
+
assert.ok(info.done, "should be done");
|
|
381
|
+
assert.ok(info.url === undefined);
|
|
429
382
|
}
|
|
430
|
-
sendChallengeData(info, data) {
|
|
431
|
-
return
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
});
|
|
383
|
+
async sendChallengeData(info, data) {
|
|
384
|
+
return axios.request({
|
|
385
|
+
method: info.method,
|
|
386
|
+
url: info.url,
|
|
387
|
+
data,
|
|
388
|
+
headers: {
|
|
389
|
+
"Content-MD5": info.md5,
|
|
390
|
+
"Content-Type": "application/octet-stream"
|
|
391
|
+
}
|
|
441
392
|
});
|
|
442
393
|
}
|
|
443
394
|
}
|
|
444
395
|
__decorate([
|
|
445
|
-
|
|
396
|
+
test
|
|
446
397
|
], BinaryTest.prototype, "normal", null);
|
|
447
398
|
__decorate([
|
|
448
|
-
|
|
399
|
+
test
|
|
449
400
|
], BinaryTest.prototype, "notMapped", null);
|
|
450
401
|
__decorate([
|
|
451
|
-
|
|
402
|
+
test
|
|
452
403
|
], BinaryTest.prototype, "update", null);
|
|
453
404
|
__decorate([
|
|
454
|
-
|
|
405
|
+
test
|
|
455
406
|
], BinaryTest.prototype, "checkMap", null);
|
|
456
407
|
__decorate([
|
|
457
|
-
|
|
408
|
+
test
|
|
458
409
|
], BinaryTest.prototype, "httpCreate", null);
|
|
459
410
|
__decorate([
|
|
460
|
-
|
|
411
|
+
test
|
|
461
412
|
], BinaryTest.prototype, "httpDelete", null);
|
|
462
413
|
__decorate([
|
|
463
|
-
|
|
414
|
+
test
|
|
464
415
|
], BinaryTest.prototype, "getOperationName", null);
|
|
465
416
|
__decorate([
|
|
466
|
-
|
|
417
|
+
test
|
|
467
418
|
], BinaryTest.prototype, "httpGetError", null);
|
|
468
419
|
__decorate([
|
|
469
|
-
|
|
420
|
+
test
|
|
470
421
|
], BinaryTest.prototype, "httpGet", null);
|
|
471
422
|
__decorate([
|
|
472
|
-
|
|
423
|
+
test
|
|
473
424
|
], BinaryTest.prototype, "httpMetadata", null);
|
|
474
425
|
__decorate([
|
|
475
|
-
|
|
426
|
+
test
|
|
476
427
|
], BinaryTest.prototype, "getNotFound", null);
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
ctx.getHttpContext().setBody({
|
|
485
|
-
hash: "plop"
|
|
486
|
-
});
|
|
487
|
-
yield assert.rejects(() => service.httpChallenge(ctx), /400/);
|
|
488
|
-
ctx = yield this.newContext();
|
|
489
|
-
ctx.getHttpContext().setBody({
|
|
490
|
-
challenge: "plop"
|
|
491
|
-
});
|
|
492
|
-
yield assert.rejects(() => service.httpChallenge(ctx), /400/);
|
|
493
|
-
ctx = yield this.newContext();
|
|
494
|
-
let binary = this.getService("binary");
|
|
495
|
-
ctx.setPathParameters({
|
|
496
|
-
property: "images",
|
|
497
|
-
store: "users",
|
|
498
|
-
uid: "notfound",
|
|
499
|
-
index: 0
|
|
500
|
-
});
|
|
501
|
-
ctx.getHttpContext().setBody({
|
|
502
|
-
hash: "p",
|
|
503
|
-
challenge: "z"
|
|
504
|
-
});
|
|
505
|
-
yield assert.rejects(() => binary.httpChallenge(ctx), /404/);
|
|
506
|
-
let stubs = [];
|
|
507
|
-
try {
|
|
508
|
-
let model = {};
|
|
509
|
-
stubs.push(sinon.stub(binary, "_verifyMapAndStore").callsFake(() => {
|
|
510
|
-
return {
|
|
511
|
-
get: (uuid, ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
512
|
-
return model;
|
|
513
|
-
})
|
|
514
|
-
};
|
|
515
|
-
}));
|
|
516
|
-
yield assert.rejects(() => binary.httpRoute(ctx), /404/);
|
|
517
|
-
model = {
|
|
518
|
-
images: [
|
|
519
|
-
{
|
|
520
|
-
size: 10
|
|
521
|
-
}
|
|
522
|
-
],
|
|
523
|
-
canAct: () => __awaiter(this, void 0, void 0, function* () { return true; })
|
|
524
|
-
};
|
|
525
|
-
stubs.push(
|
|
526
|
-
// @ts-ignore
|
|
527
|
-
sinon.stub(binary, "get").callsFake(() => __awaiter(this, void 0, void 0, function* () {
|
|
528
|
-
return {
|
|
529
|
-
pipe: stream => {
|
|
530
|
-
stream.emit("error", new Error("I/O"));
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
})));
|
|
534
|
-
yield assert.rejects(() => binary.httpRoute(ctx), /500/);
|
|
535
|
-
}
|
|
536
|
-
finally {
|
|
537
|
-
stubs.forEach(stub => stub.restore());
|
|
538
|
-
}
|
|
428
|
+
let BinaryAbstractTest = class BinaryAbstractTest extends WebdaTest {
|
|
429
|
+
async cov() {
|
|
430
|
+
let service = new TestBinaryService(undefined, "plop", {});
|
|
431
|
+
let ctx = await this.newContext();
|
|
432
|
+
await assert.rejects(() => service.putRedirectUrl(undefined), /404/);
|
|
433
|
+
ctx.getHttpContext().setBody({
|
|
434
|
+
hash: "plop"
|
|
539
435
|
});
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
436
|
+
await assert.rejects(() => service.httpChallenge(ctx), /400/);
|
|
437
|
+
ctx = await this.newContext();
|
|
438
|
+
ctx.getHttpContext().setBody({
|
|
439
|
+
challenge: "plop"
|
|
440
|
+
});
|
|
441
|
+
await assert.rejects(() => service.httpChallenge(ctx), /400/);
|
|
442
|
+
ctx = await this.newContext();
|
|
443
|
+
let binary = this.getService("binary");
|
|
444
|
+
ctx.setPathParameters({
|
|
445
|
+
property: "images",
|
|
446
|
+
store: "users",
|
|
447
|
+
uid: "notfound",
|
|
448
|
+
index: 0
|
|
548
449
|
});
|
|
450
|
+
ctx.getHttpContext().setBody({
|
|
451
|
+
hash: "p",
|
|
452
|
+
challenge: "z"
|
|
453
|
+
});
|
|
454
|
+
await assert.rejects(() => binary.httpChallenge(ctx), /404/);
|
|
455
|
+
let stubs = [];
|
|
456
|
+
try {
|
|
457
|
+
let model = {};
|
|
458
|
+
stubs.push(sinon.stub(binary, "_verifyMapAndStore").callsFake(() => {
|
|
459
|
+
return {
|
|
460
|
+
get: async (uuid, ctx) => {
|
|
461
|
+
return model;
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}));
|
|
465
|
+
await assert.rejects(() => binary.httpRoute(ctx), /404/);
|
|
466
|
+
model = {
|
|
467
|
+
images: [
|
|
468
|
+
{
|
|
469
|
+
size: 10
|
|
470
|
+
}
|
|
471
|
+
],
|
|
472
|
+
canAct: async () => true
|
|
473
|
+
};
|
|
474
|
+
stubs.push(
|
|
475
|
+
// @ts-ignore
|
|
476
|
+
sinon.stub(binary, "get").callsFake(async () => {
|
|
477
|
+
return {
|
|
478
|
+
pipe: stream => {
|
|
479
|
+
stream.emit("error", new Error("I/O"));
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}));
|
|
483
|
+
await assert.rejects(() => binary.httpRoute(ctx), /500/);
|
|
484
|
+
}
|
|
485
|
+
finally {
|
|
486
|
+
stubs.forEach(stub => stub.restore());
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
async streamToBufferError() {
|
|
490
|
+
let stream = new EventEmitter();
|
|
491
|
+
// @ts-ignore
|
|
492
|
+
let p = assert.rejects(() => Binary.streamToBuffer(stream), /Bad I\/O/);
|
|
493
|
+
stream.emit("error", new Error("Bad I/O"));
|
|
494
|
+
await p;
|
|
549
495
|
}
|
|
550
496
|
};
|
|
551
497
|
__decorate([
|
|
552
|
-
|
|
498
|
+
test
|
|
553
499
|
], BinaryAbstractTest.prototype, "cov", null);
|
|
554
500
|
__decorate([
|
|
555
|
-
|
|
501
|
+
test
|
|
556
502
|
], BinaryAbstractTest.prototype, "streamToBufferError", null);
|
|
557
503
|
BinaryAbstractTest = __decorate([
|
|
558
|
-
|
|
504
|
+
suite
|
|
559
505
|
], BinaryAbstractTest);
|
|
506
|
+
export { BinaryTest };
|
|
560
507
|
//# sourceMappingURL=binary.spec.js.map
|