@webda/aws 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/deployers/cloudformation.d.ts +3 -3
- package/lib/deployers/cloudformation.js +673 -694
- package/lib/deployers/cloudformation.js.map +1 -1
- package/lib/deployers/cloudformation.spec.js +428 -477
- package/lib/deployers/cloudformation.spec.js.map +1 -1
- package/lib/deployers/index.js +282 -342
- package/lib/deployers/index.js.map +1 -1
- package/lib/deployers/index.spec.d.ts +1 -1
- package/lib/deployers/index.spec.js +445 -510
- package/lib/deployers/index.spec.js.map +1 -1
- package/lib/deployers/lambda-entrypoint.js +4 -16
- package/lib/deployers/lambda-entrypoint.js.map +1 -1
- package/lib/deployers/lambdapackager.d.ts +1 -1
- package/lib/deployers/lambdapackager.js +14 -53
- package/lib/deployers/lambdapackager.js.map +1 -1
- package/lib/deployers/lambdapackager.spec.js +25 -61
- package/lib/deployers/lambdapackager.spec.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -17
- package/lib/index.js.map +1 -1
- package/lib/index.spec.d.ts +1 -1
- package/lib/index.spec.js +28 -75
- package/lib/index.spec.js.map +1 -1
- package/lib/services/aws-mixin.d.ts +2 -0
- package/lib/services/aws-mixin.js +2 -7
- package/lib/services/aws-mixin.js.map +1 -1
- package/lib/services/cloudwatchlogger.d.ts +3 -1
- package/lib/services/cloudwatchlogger.js +63 -104
- package/lib/services/cloudwatchlogger.js.map +1 -1
- package/lib/services/cloudwatchlogger.spec.js +57 -100
- package/lib/services/cloudwatchlogger.spec.js.map +1 -1
- package/lib/services/dynamodb.d.ts +4 -2
- package/lib/services/dynamodb.js +457 -498
- package/lib/services/dynamodb.js.map +1 -1
- package/lib/services/dynamodb.spec.d.ts +2 -2
- package/lib/services/dynamodb.spec.js +231 -302
- package/lib/services/dynamodb.spec.js.map +1 -1
- package/lib/services/index.d.ts +9 -9
- package/lib/services/index.js +8 -24
- package/lib/services/index.js.map +1 -1
- package/lib/services/lambdacaller.d.ts +2 -0
- package/lib/services/lambdacaller.js +15 -29
- package/lib/services/lambdacaller.js.map +1 -1
- package/lib/services/lambdacaller.spec.js +43 -81
- package/lib/services/lambdacaller.spec.js.map +1 -1
- package/lib/services/lambdaserver.js +167 -190
- package/lib/services/lambdaserver.js.map +1 -1
- package/lib/services/lambdaserver.spec.js +266 -354
- package/lib/services/lambdaserver.spec.js.map +1 -1
- package/lib/services/route53.js +112 -137
- package/lib/services/route53.js.map +1 -1
- package/lib/services/route53.spec.js +56 -92
- package/lib/services/route53.spec.js.map +1 -1
- package/lib/services/s3binary.d.ts +6 -2
- package/lib/services/s3binary.js +189 -251
- package/lib/services/s3binary.js.map +1 -1
- package/lib/services/s3binary.spec.js +185 -254
- package/lib/services/s3binary.spec.js.map +1 -1
- package/lib/services/secretsmanager.d.ts +2 -0
- package/lib/services/secretsmanager.js +32 -56
- package/lib/services/secretsmanager.js.map +1 -1
- package/lib/services/secretsmanager.spec.js +50 -93
- package/lib/services/secretsmanager.spec.js.map +1 -1
- package/lib/services/sqsqueue.d.ts +5 -7
- package/lib/services/sqsqueue.js +70 -99
- package/lib/services/sqsqueue.js.map +1 -1
- package/lib/services/sqsqueue.spec.js +95 -145
- package/lib/services/sqsqueue.spec.js.map +1 -1
- package/lib/shell.js +19 -38
- package/lib/shell.js.map +1 -1
- package/package.json +12 -9
- package/webda.module.json +54 -6
|
@@ -1,67 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
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;
|
|
22
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
6
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
exports.MockAWSDeployerMethods = void 0;
|
|
42
|
-
const client_acm_1 = require("@aws-sdk/client-acm");
|
|
43
|
-
const client_ec2_1 = require("@aws-sdk/client-ec2");
|
|
44
|
-
const client_route_53_1 = require("@aws-sdk/client-route-53");
|
|
45
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
46
|
-
const client_sts_1 = require("@aws-sdk/client-sts");
|
|
47
|
-
const mocha_1 = require("@testdeck/mocha");
|
|
48
|
-
const core_1 = require("@webda/core");
|
|
49
|
-
const deployertest_1 = require("@webda/shell/lib/deployers/deployertest");
|
|
50
|
-
const assert = __importStar(require("assert"));
|
|
51
|
-
const aws_sdk_client_mock_1 = require("aws-sdk-client-mock");
|
|
52
|
-
const sinon = __importStar(require("sinon"));
|
|
53
|
-
const _1 = require(".");
|
|
54
|
-
class TestAWSDeployer extends _1.AWSDeployer {
|
|
55
|
-
deploy() {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () { });
|
|
57
|
-
}
|
|
58
|
-
restrictedCall(method, ...args) {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
return this[method](...args);
|
|
61
|
-
});
|
|
7
|
+
import { ACM, DescribeCertificateCommand, ListCertificatesCommand, RequestCertificateCommand } from "@aws-sdk/client-acm";
|
|
8
|
+
import { DescribeSubnetsCommand, DescribeVpcsCommand, EC2 } from "@aws-sdk/client-ec2";
|
|
9
|
+
import { ChangeResourceRecordSetsCommand, ListHostedZonesCommand, Route53 } from "@aws-sdk/client-route-53";
|
|
10
|
+
import { CreateBucketCommand, HeadBucketCommand, ListObjectsV2Command, NotFound, PutBucketTaggingCommand, PutObjectCommand, S3 } from "@aws-sdk/client-s3";
|
|
11
|
+
import { GetCallerIdentityCommand, STS } from "@aws-sdk/client-sts";
|
|
12
|
+
import { suite, test } from "@testdeck/mocha";
|
|
13
|
+
import { CacheService, getCommonJS } from "@webda/core";
|
|
14
|
+
import { DeployerTest } from "@webda/shell/lib/deployers/deployertest.js";
|
|
15
|
+
import * as assert from "assert";
|
|
16
|
+
import { mockClient } from "aws-sdk-client-mock";
|
|
17
|
+
import * as sinon from "sinon";
|
|
18
|
+
import { AWSDeployer } from "./index.js";
|
|
19
|
+
const { __dirname, __filename } = getCommonJS(import.meta.url);
|
|
20
|
+
class TestAWSDeployer extends AWSDeployer {
|
|
21
|
+
async deploy() { }
|
|
22
|
+
async restrictedCall(method, ...args) {
|
|
23
|
+
return this[method](...args);
|
|
62
24
|
}
|
|
63
25
|
}
|
|
64
|
-
function MockAWSDeployerMethods(service, test) {
|
|
26
|
+
export function MockAWSDeployerMethods(service, test) {
|
|
65
27
|
test.mocks["putFilesOnBucket"] = sinon.stub(service, "putFilesOnBucket").resolves();
|
|
66
28
|
test.mocks["createBucket"] = sinon.stub(service, "createBucket").resolves();
|
|
67
29
|
test.mocks["doCreateCertificate"] = sinon.stub(service, "doCreateCertificate").resolves({});
|
|
@@ -84,12 +46,9 @@ function MockAWSDeployerMethods(service, test) {
|
|
|
84
46
|
Statement: []
|
|
85
47
|
});
|
|
86
48
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
return new TestAWSDeployer(manager, {});
|
|
92
|
-
});
|
|
49
|
+
let AWSDeployerTest = class AWSDeployerTest extends DeployerTest {
|
|
50
|
+
async getDeployer(manager) {
|
|
51
|
+
return new TestAWSDeployer(manager, {});
|
|
93
52
|
}
|
|
94
53
|
mapToArrayTags() {
|
|
95
54
|
let deployer = new TestAWSDeployer(this.manager, { Tags: { Test: "Plop" } });
|
|
@@ -98,473 +57,449 @@ let AWSDeployerTest = class AWSDeployerTest extends deployertest_1.DeployerTest
|
|
|
98
57
|
{ Key: "Test", Value: "Plop" }
|
|
99
58
|
]);
|
|
100
59
|
}
|
|
101
|
-
putFilesOnBucket() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return {};
|
|
118
|
-
});
|
|
119
|
-
sinon.stub(this.deployer, "createBucket").resolves();
|
|
120
|
-
yield this.deployer.putFolderOnBucket("plop", "./test/moddas");
|
|
121
|
-
assert.strictEqual(uploads.length, 0);
|
|
122
|
-
Contents[0].ETag = "plop";
|
|
123
|
-
yield this.deployer.putFolderOnBucket("plop", "./test/moddas");
|
|
124
|
-
assert.strictEqual(uploads.length, 1);
|
|
125
|
-
uploads = [];
|
|
126
|
-
Contents[0].ETag = '"312d05552187d3fdfdda3860fbeef48f"';
|
|
127
|
-
Contents[0].Size = 123;
|
|
128
|
-
yield this.deployer.putFolderOnBucket("plop", "./test/moddas");
|
|
129
|
-
assert.strictEqual(uploads.length, 1);
|
|
60
|
+
async putFilesOnBucket() {
|
|
61
|
+
await this.deployer.putFilesOnBucket("plop", []);
|
|
62
|
+
await assert.rejects(
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
() => this.deployer.putFilesOnBucket("plop", [{ key: "/test" }]), /Should have src and key defined/);
|
|
65
|
+
let Contents = [{ Key: "awsevents.js", Size: 527, ETag: '"ea1db4bb1545c62c50e6f0893e9f0992"' }];
|
|
66
|
+
let stub = sinon.stub().resolves({ Contents });
|
|
67
|
+
// Fake any uploads
|
|
68
|
+
let uploads = [];
|
|
69
|
+
mockClient(S3)
|
|
70
|
+
.on(ListObjectsV2Command)
|
|
71
|
+
.callsFake(stub)
|
|
72
|
+
.on(PutObjectCommand)
|
|
73
|
+
.callsFake(arg => {
|
|
74
|
+
uploads.push(arg);
|
|
75
|
+
return {};
|
|
130
76
|
});
|
|
77
|
+
sinon.stub(this.deployer, "createBucket").resolves();
|
|
78
|
+
await this.deployer.putFolderOnBucket("plop", "./test/moddas");
|
|
79
|
+
assert.strictEqual(uploads.length, 0);
|
|
80
|
+
Contents[0].ETag = "plop";
|
|
81
|
+
await this.deployer.putFolderOnBucket("plop", "./test/moddas");
|
|
82
|
+
assert.strictEqual(uploads.length, 1);
|
|
83
|
+
uploads = [];
|
|
84
|
+
Contents[0].ETag = '"312d05552187d3fdfdda3860fbeef48f"';
|
|
85
|
+
Contents[0].Size = 123;
|
|
86
|
+
await this.deployer.putFolderOnBucket("plop", "./test/moddas");
|
|
87
|
+
assert.strictEqual(uploads.length, 1);
|
|
131
88
|
}
|
|
132
|
-
testGetPolicyDocument() {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
Account: "test"
|
|
136
|
-
});
|
|
137
|
-
try {
|
|
138
|
-
// @ts-ignore
|
|
139
|
-
this.manager.getWebda().getServices()["customservice"].getARNPolicy = () => {
|
|
140
|
-
return [
|
|
141
|
-
{ Sid: "", Effect: "Allow", Action: [], Resource: "*" },
|
|
142
|
-
{ Sid: "", Effect: "Allow", Action: [], Resource: "*" }
|
|
143
|
-
];
|
|
144
|
-
};
|
|
145
|
-
let result = yield this.deployer.getPolicyDocument();
|
|
146
|
-
assert.strictEqual(result.Statement.length, 4);
|
|
147
|
-
}
|
|
148
|
-
finally {
|
|
149
|
-
mock.restore();
|
|
150
|
-
}
|
|
89
|
+
async testGetPolicyDocument() {
|
|
90
|
+
const mock = mockClient(STS).on(GetCallerIdentityCommand).resolves({
|
|
91
|
+
Account: "test"
|
|
151
92
|
});
|
|
93
|
+
try {
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
this.manager.getWebda().getServices()["customservice"].getARNPolicy = () => {
|
|
96
|
+
return [
|
|
97
|
+
{ Sid: "", Effect: "Allow", Action: [], Resource: "*" },
|
|
98
|
+
{ Sid: "", Effect: "Allow", Action: [], Resource: "*" }
|
|
99
|
+
];
|
|
100
|
+
};
|
|
101
|
+
let result = await this.deployer.getPolicyDocument();
|
|
102
|
+
assert.strictEqual(result.Statement.length, 4);
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
mock.restore();
|
|
106
|
+
}
|
|
152
107
|
}
|
|
153
|
-
testGetDefaultVpc() {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (vpcsSpy.callCount === 1) {
|
|
157
|
-
return {
|
|
158
|
-
Vpcs: []
|
|
159
|
-
};
|
|
160
|
-
}
|
|
108
|
+
async testGetDefaultVpc() {
|
|
109
|
+
var vpcsSpy = sinon.stub().callsFake(async () => {
|
|
110
|
+
if (vpcsSpy.callCount === 1) {
|
|
161
111
|
return {
|
|
162
|
-
Vpcs: [
|
|
163
|
-
{
|
|
164
|
-
VpcId: "vpc-667",
|
|
165
|
-
IsDefault: false
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
VpcId: "vpc-666",
|
|
169
|
-
IsDefault: true
|
|
170
|
-
}
|
|
171
|
-
]
|
|
112
|
+
Vpcs: []
|
|
172
113
|
};
|
|
173
|
-
}));
|
|
174
|
-
var subnetsSpy = sinon.stub().callsFake(() => __awaiter(this, void 0, void 0, function* () {
|
|
175
|
-
return {
|
|
176
|
-
Subnets: [
|
|
177
|
-
{
|
|
178
|
-
SubnetId: "subnet-1"
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
SubnetId: "subnet-2"
|
|
182
|
-
}
|
|
183
|
-
]
|
|
184
|
-
};
|
|
185
|
-
}));
|
|
186
|
-
const mock = (0, aws_sdk_client_mock_1.mockClient)(client_ec2_1.EC2)
|
|
187
|
-
.on(client_ec2_1.DescribeVpcsCommand)
|
|
188
|
-
.callsFake(vpcsSpy)
|
|
189
|
-
.on(client_ec2_1.DescribeSubnetsCommand)
|
|
190
|
-
.callsFake(subnetsSpy);
|
|
191
|
-
try {
|
|
192
|
-
let result = yield this.deployer.getDefaultVpc();
|
|
193
|
-
assert.strictEqual(vpcsSpy.calledOnce, true);
|
|
194
|
-
assert.strictEqual(subnetsSpy.notCalled, true);
|
|
195
|
-
assert.strictEqual(result, undefined);
|
|
196
|
-
core_1.CacheService.clearAllCache();
|
|
197
|
-
result = yield this.deployer.getDefaultVpc();
|
|
198
|
-
assert.deepStrictEqual(result, {
|
|
199
|
-
Id: "vpc-666",
|
|
200
|
-
Subnets: [{ SubnetId: "subnet-1" }, { SubnetId: "subnet-2" }]
|
|
201
|
-
});
|
|
202
|
-
assert.strictEqual(subnetsSpy.calledWith({
|
|
203
|
-
Filters: [
|
|
204
|
-
{
|
|
205
|
-
Name: "vpc-id",
|
|
206
|
-
Values: ["vpc-666"]
|
|
207
|
-
}
|
|
208
|
-
]
|
|
209
|
-
}), true);
|
|
210
|
-
}
|
|
211
|
-
finally {
|
|
212
|
-
mock.restore();
|
|
213
114
|
}
|
|
115
|
+
return {
|
|
116
|
+
Vpcs: [
|
|
117
|
+
{
|
|
118
|
+
VpcId: "vpc-667",
|
|
119
|
+
IsDefault: false
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
VpcId: "vpc-666",
|
|
123
|
+
IsDefault: true
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
};
|
|
214
127
|
});
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
128
|
+
var subnetsSpy = sinon.stub().callsFake(async () => {
|
|
129
|
+
return {
|
|
130
|
+
Subnets: [
|
|
131
|
+
{
|
|
132
|
+
SubnetId: "subnet-1"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
SubnetId: "subnet-2"
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
};
|
|
222
139
|
});
|
|
140
|
+
const mock = mockClient(EC2)
|
|
141
|
+
.on(DescribeVpcsCommand)
|
|
142
|
+
.callsFake(vpcsSpy)
|
|
143
|
+
.on(DescribeSubnetsCommand)
|
|
144
|
+
.callsFake(subnetsSpy);
|
|
145
|
+
try {
|
|
146
|
+
let result = await this.deployer.getDefaultVpc();
|
|
147
|
+
assert.strictEqual(vpcsSpy.calledOnce, true);
|
|
148
|
+
assert.strictEqual(subnetsSpy.notCalled, true);
|
|
149
|
+
assert.strictEqual(result, undefined);
|
|
150
|
+
CacheService.clearAllCache();
|
|
151
|
+
result = await this.deployer.getDefaultVpc();
|
|
152
|
+
assert.deepStrictEqual(result, {
|
|
153
|
+
Id: "vpc-666",
|
|
154
|
+
Subnets: [{ SubnetId: "subnet-1" }, { SubnetId: "subnet-2" }]
|
|
155
|
+
});
|
|
156
|
+
assert.strictEqual(subnetsSpy.calledWith({
|
|
157
|
+
Filters: [
|
|
158
|
+
{
|
|
159
|
+
Name: "vpc-id",
|
|
160
|
+
Values: ["vpc-666"]
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
}), true);
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
mock.restore();
|
|
167
|
+
}
|
|
223
168
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const mock = (0, aws_sdk_client_mock_1.mockClient)(client_s3_1.S3)
|
|
245
|
-
.on(client_s3_1.HeadBucketCommand)
|
|
246
|
-
.callsFake(headSpy)
|
|
247
|
-
.on(client_s3_1.CreateBucketCommand)
|
|
248
|
-
.callsFake(createSpy)
|
|
249
|
-
.on(client_s3_1.PutBucketTaggingCommand)
|
|
250
|
-
.callsFake(tagSpy);
|
|
251
|
-
try {
|
|
252
|
-
yield this.deployer.createBucket("plop");
|
|
253
|
-
// Bucket exists
|
|
254
|
-
assert.strictEqual(headSpy.callCount, 1);
|
|
255
|
-
assert.strictEqual(headSpy.calledWith({ Bucket: "plop" }), true);
|
|
256
|
-
assert.strictEqual(createSpy.notCalled, true);
|
|
257
|
-
assert.strictEqual(tagSpy.notCalled, true);
|
|
258
|
-
// Bucket exists in another account or we do not have rights
|
|
259
|
-
yield this.deployer.createBucket("plop");
|
|
260
|
-
assert.strictEqual(headSpy.callCount, 2);
|
|
261
|
-
assert.strictEqual(createSpy.notCalled, true);
|
|
262
|
-
yield this.deployer.createBucket("plop");
|
|
263
|
-
assert.strictEqual(headSpy.callCount, 3);
|
|
264
|
-
assert.strictEqual(createSpy.calledOnce, true);
|
|
265
|
-
assert.strictEqual(createSpy.calledWith({ Bucket: "plop" }), true);
|
|
266
|
-
assert.strictEqual(tagSpy.calledOnce, true);
|
|
267
|
-
assert.strictEqual(tagSpy.calledWith({ Bucket: "plop", Tagging: { TagSet: [{ Key: "test", Value: "mytag" }] } }), true);
|
|
268
|
-
}
|
|
269
|
-
finally {
|
|
270
|
-
mock.restore();
|
|
169
|
+
async testCommonPrefix() {
|
|
170
|
+
assert.strictEqual(this.deployer.commonPrefix("/test/bouzf", "/test/reffff"), "/test/");
|
|
171
|
+
assert.strictEqual(this.deployer.commonPrefix("test/bouzf", "/test/reffff"), "");
|
|
172
|
+
assert.strictEqual(this.deployer.commonPrefix("/tes", "/test/reffff"), "/tes");
|
|
173
|
+
assert.strictEqual(this.deployer.commonPrefix("test/bouzf", "test/bouzf212"), "test/bouzf");
|
|
174
|
+
}
|
|
175
|
+
async testCreateBucket() {
|
|
176
|
+
this.deployer.resources.Tags = this.deployer.transformMapTagsToArray({ test: "mytag" });
|
|
177
|
+
var headSpy = sinon.stub();
|
|
178
|
+
headSpy.callsFake(async () => {
|
|
179
|
+
let res = {};
|
|
180
|
+
switch (headSpy.callCount) {
|
|
181
|
+
case 2:
|
|
182
|
+
throw {
|
|
183
|
+
name: "Forbidden"
|
|
184
|
+
};
|
|
185
|
+
case 3:
|
|
186
|
+
throw new NotFound({
|
|
187
|
+
$metadata: {}
|
|
188
|
+
});
|
|
271
189
|
}
|
|
190
|
+
return res;
|
|
272
191
|
});
|
|
192
|
+
var createSpy = sinon.stub().resolves();
|
|
193
|
+
var tagSpy = sinon.stub().resolves();
|
|
194
|
+
const mock = mockClient(S3)
|
|
195
|
+
.on(HeadBucketCommand)
|
|
196
|
+
.callsFake(headSpy)
|
|
197
|
+
.on(CreateBucketCommand)
|
|
198
|
+
.callsFake(createSpy)
|
|
199
|
+
.on(PutBucketTaggingCommand)
|
|
200
|
+
.callsFake(tagSpy);
|
|
201
|
+
try {
|
|
202
|
+
await this.deployer.createBucket("plop");
|
|
203
|
+
// Bucket exists
|
|
204
|
+
assert.strictEqual(headSpy.callCount, 1);
|
|
205
|
+
assert.strictEqual(headSpy.calledWith({ Bucket: "plop" }), true);
|
|
206
|
+
assert.strictEqual(createSpy.notCalled, true);
|
|
207
|
+
assert.strictEqual(tagSpy.notCalled, true);
|
|
208
|
+
// Bucket exists in another account or we do not have rights
|
|
209
|
+
await this.deployer.createBucket("plop");
|
|
210
|
+
assert.strictEqual(headSpy.callCount, 2);
|
|
211
|
+
assert.strictEqual(createSpy.notCalled, true);
|
|
212
|
+
await this.deployer.createBucket("plop");
|
|
213
|
+
assert.strictEqual(headSpy.callCount, 3);
|
|
214
|
+
assert.strictEqual(createSpy.calledOnce, true);
|
|
215
|
+
assert.strictEqual(createSpy.calledWith({ Bucket: "plop" }), true);
|
|
216
|
+
assert.strictEqual(tagSpy.calledOnce, true);
|
|
217
|
+
assert.strictEqual(tagSpy.calledWith({ Bucket: "plop", Tagging: { TagSet: [{ Key: "test", Value: "mytag" }] } }), true);
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
mock.restore();
|
|
221
|
+
}
|
|
273
222
|
}
|
|
274
|
-
testPutBucket() {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
223
|
+
async testPutBucket() {
|
|
224
|
+
var putSpy = sinon.stub();
|
|
225
|
+
var listSpy = sinon.stub();
|
|
226
|
+
var createBucket = sinon.stub(this.deployer, "createBucket");
|
|
227
|
+
createBucket.resolves();
|
|
228
|
+
putSpy.resolves();
|
|
229
|
+
listSpy.resolves({ Contents: [] });
|
|
230
|
+
const mock = mockClient(S3).on(PutObjectCommand).callsFake(putSpy).on(ListObjectsV2Command).callsFake(listSpy);
|
|
231
|
+
try {
|
|
232
|
+
// @ts-ignore shortcut to test both in one
|
|
233
|
+
await this.deployer.putFilesOnBucket("plop", [
|
|
234
|
+
{ src: __filename },
|
|
235
|
+
{ src: __dirname + "/index.ts", key: "plop.ts" },
|
|
236
|
+
{ key: "buffer.out", src: Buffer.from("bouzouf"), mimetype: "text/plain" }
|
|
237
|
+
]);
|
|
238
|
+
assert.strictEqual(putSpy.callCount, 3);
|
|
239
|
+
// checks call
|
|
240
|
+
assert.strictEqual(putSpy.firstCall.firstArg.Body.constructor.name, "ReadStream");
|
|
241
|
+
assert.strictEqual(putSpy.secondCall.firstArg.Body.constructor.name, "ReadStream");
|
|
242
|
+
assert.deepStrictEqual(putSpy.thirdCall.firstArg.Body.constructor.name, "Buffer");
|
|
243
|
+
assert.deepStrictEqual(putSpy.thirdCall.firstArg.Body.toString(), "bouzouf");
|
|
244
|
+
assert.strictEqual(createBucket.calledOnce, true);
|
|
245
|
+
// TODO Check upload optimization
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
mock.restore();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
async testGetCertificate() {
|
|
252
|
+
var putSpy = sinon.stub();
|
|
253
|
+
var getZoneForDomainName = sinon.stub(this.deployer, "getZoneForDomainName");
|
|
254
|
+
var doCreateCertificate = sinon.stub(this.deployer, "doCreateCertificate");
|
|
255
|
+
getZoneForDomainName.callsFake(async () => {
|
|
256
|
+
if (getZoneForDomainName.callCount === 1) {
|
|
257
|
+
return undefined;
|
|
298
258
|
}
|
|
299
|
-
|
|
300
|
-
|
|
259
|
+
return { Id: "1234", HostedZone: "", Name: "", CallerReference: "" };
|
|
260
|
+
});
|
|
261
|
+
doCreateCertificate.resolves({ DomainName: "newlyCreated" });
|
|
262
|
+
putSpy.callsFake(async () => {
|
|
263
|
+
switch (putSpy.callCount) {
|
|
264
|
+
case 1:
|
|
265
|
+
return {
|
|
266
|
+
CertificateSummaryList: [
|
|
267
|
+
{
|
|
268
|
+
DomainName: "none.com"
|
|
269
|
+
}
|
|
270
|
+
],
|
|
271
|
+
NextToken: "page2"
|
|
272
|
+
};
|
|
273
|
+
case 2:
|
|
274
|
+
return {
|
|
275
|
+
CertificateSummaryList: [
|
|
276
|
+
{
|
|
277
|
+
DomainName: "test.webda.io"
|
|
278
|
+
}
|
|
279
|
+
]
|
|
280
|
+
};
|
|
281
|
+
default:
|
|
282
|
+
return { CertificateSummaryList: [] };
|
|
301
283
|
}
|
|
302
284
|
});
|
|
285
|
+
const mock = mockClient(ACM).on(ListCertificatesCommand).callsFake(putSpy);
|
|
286
|
+
try {
|
|
287
|
+
let certificate = await this.deployer.getCertificate("test.webda.io.");
|
|
288
|
+
assert.strictEqual(putSpy.calledTwice, true);
|
|
289
|
+
assert.strictEqual(doCreateCertificate.notCalled, true);
|
|
290
|
+
assert.strictEqual(getZoneForDomainName.notCalled, true);
|
|
291
|
+
assert.deepStrictEqual(certificate, { DomainName: "test.webda.io" });
|
|
292
|
+
await assert.rejects(async () => await this.deployer.getCertificate("test.webda.io"), /Cannot create certificate as Route53 Zone was not found/g);
|
|
293
|
+
assert.strictEqual(getZoneForDomainName.calledWith("test.webda.io"), true);
|
|
294
|
+
assert.strictEqual(doCreateCertificate.notCalled, true);
|
|
295
|
+
await this.deployer.getCertificate("test.webda.io", "us-east-1");
|
|
296
|
+
assert.strictEqual(doCreateCertificate.calledWith("test.webda.io", {
|
|
297
|
+
Id: "1234",
|
|
298
|
+
HostedZone: "",
|
|
299
|
+
Name: "",
|
|
300
|
+
CallerReference: ""
|
|
301
|
+
}), true);
|
|
302
|
+
}
|
|
303
|
+
finally {
|
|
304
|
+
mock.restore();
|
|
305
|
+
}
|
|
303
306
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
return
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
return {
|
|
320
|
-
CertificateSummaryList: [
|
|
321
|
-
{
|
|
322
|
-
DomainName: "none.com"
|
|
323
|
-
}
|
|
324
|
-
],
|
|
325
|
-
NextToken: "page2"
|
|
326
|
-
};
|
|
327
|
-
case 2:
|
|
328
|
-
return {
|
|
329
|
-
CertificateSummaryList: [
|
|
330
|
-
{
|
|
331
|
-
DomainName: "test.webda.io"
|
|
332
|
-
}
|
|
333
|
-
]
|
|
334
|
-
};
|
|
335
|
-
default:
|
|
336
|
-
return { CertificateSummaryList: [] };
|
|
337
|
-
}
|
|
338
|
-
}));
|
|
339
|
-
const mock = (0, aws_sdk_client_mock_1.mockClient)(client_acm_1.ACM).on(client_acm_1.ListCertificatesCommand).callsFake(putSpy);
|
|
340
|
-
try {
|
|
341
|
-
let certificate = yield this.deployer.getCertificate("test.webda.io.");
|
|
342
|
-
assert.strictEqual(putSpy.calledTwice, true);
|
|
343
|
-
assert.strictEqual(doCreateCertificate.notCalled, true);
|
|
344
|
-
assert.strictEqual(getZoneForDomainName.notCalled, true);
|
|
345
|
-
assert.deepStrictEqual(certificate, { DomainName: "test.webda.io" });
|
|
346
|
-
yield assert.rejects(() => __awaiter(this, void 0, void 0, function* () { return yield this.deployer.getCertificate("test.webda.io"); }), /Cannot create certificate as Route53 Zone was not found/g);
|
|
347
|
-
assert.strictEqual(getZoneForDomainName.calledWith("test.webda.io"), true);
|
|
348
|
-
assert.strictEqual(doCreateCertificate.notCalled, true);
|
|
349
|
-
yield this.deployer.getCertificate("test.webda.io", "us-east-1");
|
|
350
|
-
assert.strictEqual(doCreateCertificate.calledWith("test.webda.io", {
|
|
351
|
-
Id: "1234",
|
|
352
|
-
HostedZone: "",
|
|
353
|
-
Name: "",
|
|
354
|
-
CallerReference: ""
|
|
355
|
-
}), true);
|
|
356
|
-
}
|
|
357
|
-
finally {
|
|
358
|
-
mock.restore();
|
|
307
|
+
async testGetZoneForDomainName() {
|
|
308
|
+
var callSpy = sinon.stub();
|
|
309
|
+
callSpy.callsFake(async () => {
|
|
310
|
+
switch (callSpy.callCount) {
|
|
311
|
+
case 1:
|
|
312
|
+
return { HostedZones: [], NextMarker: "plop" };
|
|
313
|
+
default:
|
|
314
|
+
return {
|
|
315
|
+
HostedZones: [
|
|
316
|
+
{ Name: "webda.io." },
|
|
317
|
+
{ Name: "bouzouf.io." },
|
|
318
|
+
{ Name: "test2.test.webda.io." },
|
|
319
|
+
{ Name: "test.webda.io." }
|
|
320
|
+
]
|
|
321
|
+
};
|
|
359
322
|
}
|
|
360
323
|
});
|
|
324
|
+
const mock = mockClient(Route53).on(ListHostedZonesCommand).callsFake(callSpy);
|
|
325
|
+
try {
|
|
326
|
+
let result = await this.deployer.getZoneForDomainName("subdomain.test2.test.webda.io.");
|
|
327
|
+
assert.deepStrictEqual(result, {
|
|
328
|
+
Name: "test2.test.webda.io."
|
|
329
|
+
});
|
|
330
|
+
assert.strictEqual(callSpy.calledTwice, true);
|
|
331
|
+
result = await this.deployer.getZoneForDomainName("subdomain.webda.io");
|
|
332
|
+
assert.deepStrictEqual(result, {
|
|
333
|
+
Name: "webda.io."
|
|
334
|
+
});
|
|
335
|
+
result = await this.deployer.getZoneForDomainName("loopingz.com.");
|
|
336
|
+
assert.strictEqual(result, undefined);
|
|
337
|
+
}
|
|
338
|
+
finally {
|
|
339
|
+
mock.restore();
|
|
340
|
+
}
|
|
361
341
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
342
|
+
async testDoCreateCertificate() {
|
|
343
|
+
var requestCertificate = sinon.stub();
|
|
344
|
+
var describeCertificate = sinon.stub();
|
|
345
|
+
var createDNSEntry = sinon.stub(this.deployer, "createDNSEntry");
|
|
346
|
+
var waitFor = sinon.stub(this.deployer, "waitFor");
|
|
347
|
+
createDNSEntry.callsFake(async () => { });
|
|
348
|
+
describeCertificate.resolves({});
|
|
349
|
+
const mock = mockClient(ACM)
|
|
350
|
+
.on(RequestCertificateCommand)
|
|
351
|
+
.callsFake(requestCertificate)
|
|
352
|
+
.on(DescribeCertificateCommand)
|
|
353
|
+
.callsFake(describeCertificate);
|
|
354
|
+
try {
|
|
355
|
+
waitFor.callsFake(async (callback) => {
|
|
356
|
+
switch (waitFor.callCount) {
|
|
367
357
|
case 1:
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
return
|
|
371
|
-
HostedZones: [
|
|
372
|
-
{ Name: "webda.io." },
|
|
373
|
-
{ Name: "bouzouf.io." },
|
|
374
|
-
{ Name: "test2.test.webda.io." },
|
|
375
|
-
{ Name: "test.webda.io." }
|
|
376
|
-
]
|
|
377
|
-
};
|
|
358
|
+
await callback();
|
|
359
|
+
case 2:
|
|
360
|
+
return new Promise(resolve => callback(resolve));
|
|
378
361
|
}
|
|
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
|
-
createDNSEntry.
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
.on(client_acm_1.DescribeCertificateCommand)
|
|
411
|
-
.callsFake(describeCertificate);
|
|
412
|
-
try {
|
|
413
|
-
waitFor.callsFake((callback) => __awaiter(this, void 0, void 0, function* () {
|
|
414
|
-
switch (waitFor.callCount) {
|
|
415
|
-
case 1:
|
|
416
|
-
yield callback();
|
|
417
|
-
case 2:
|
|
418
|
-
return new Promise(resolve => callback(resolve));
|
|
419
|
-
}
|
|
420
|
-
}));
|
|
421
|
-
describeCertificate.callsFake(() => __awaiter(this, void 0, void 0, function* () {
|
|
422
|
-
if (describeCertificate.callCount === 1) {
|
|
423
|
-
return {
|
|
424
|
-
Certificate: {
|
|
425
|
-
DomainValidationOptions: [{}]
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
362
|
+
});
|
|
363
|
+
describeCertificate.callsFake(async () => {
|
|
364
|
+
if (describeCertificate.callCount === 1) {
|
|
365
|
+
return {
|
|
366
|
+
Certificate: {
|
|
367
|
+
DomainValidationOptions: [{}]
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
return {
|
|
373
|
+
Certificate: {
|
|
374
|
+
Status: "FAILED",
|
|
375
|
+
DomainValidationOptions: [{ ResourceRecord: "bouzouf" }]
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
requestCertificate.callsFake(async () => {
|
|
381
|
+
return { CertificateArn: "plop" };
|
|
382
|
+
});
|
|
383
|
+
await assert.rejects(async () => await this.deployer.doCreateCertificate("test.webda.io.", { Id: "1234" }), /Certificate validation has failed/g);
|
|
384
|
+
waitFor.callsFake(() => undefined);
|
|
385
|
+
await assert.rejects(async () => await this.deployer.doCreateCertificate("test.webda.io.", { Id: "1234" }), /Certificate validation has failed/g);
|
|
386
|
+
waitFor.resetHistory();
|
|
387
|
+
describeCertificate.resetHistory();
|
|
388
|
+
assert.strictEqual(createDNSEntry.notCalled, true);
|
|
389
|
+
// @ts-ignore
|
|
390
|
+
waitFor.callsFake(c => {
|
|
391
|
+
switch (waitFor.callCount) {
|
|
392
|
+
case 1:
|
|
430
393
|
return {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
394
|
+
Status: "PENDING_VALIDATION",
|
|
395
|
+
DomainValidationOptions: [{ ResourceRecord: { Value: "plop.com.", Name: "bouzouf.com" } }],
|
|
396
|
+
CertificateArn: "arn:plop"
|
|
435
397
|
};
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
yield assert.rejects(() => __awaiter(this, void 0, void 0, function* () { return yield this.deployer.doCreateCertificate("test.webda.io.", { Id: "1234" }); }), /Certificate validation has failed/g);
|
|
442
|
-
waitFor.callsFake(() => undefined);
|
|
443
|
-
yield assert.rejects(() => __awaiter(this, void 0, void 0, function* () { return yield this.deployer.doCreateCertificate("test.webda.io.", { Id: "1234" }); }), /Certificate validation has failed/g);
|
|
444
|
-
waitFor.resetHistory();
|
|
445
|
-
describeCertificate.resetHistory();
|
|
446
|
-
assert.strictEqual(createDNSEntry.notCalled, true);
|
|
447
|
-
// @ts-ignore
|
|
448
|
-
waitFor.callsFake(c => {
|
|
449
|
-
switch (waitFor.callCount) {
|
|
450
|
-
case 1:
|
|
451
|
-
return {
|
|
452
|
-
Status: "PENDING_VALIDATION",
|
|
453
|
-
DomainValidationOptions: [{ ResourceRecord: { Value: "plop.com.", Name: "bouzouf.com" } }],
|
|
454
|
-
CertificateArn: "arn:plop"
|
|
455
|
-
};
|
|
456
|
-
default:
|
|
457
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
458
|
-
for (let i = 0; i < 5; i++) {
|
|
459
|
-
if (yield c(resolve, reject)) {
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
398
|
+
default:
|
|
399
|
+
return new Promise(async (resolve, reject) => {
|
|
400
|
+
for (let i = 0; i < 5; i++) {
|
|
401
|
+
if (await c(resolve, reject)) {
|
|
402
|
+
return;
|
|
462
403
|
}
|
|
463
|
-
reject("max");
|
|
464
|
-
}));
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
describeCertificate.callsFake(() => __awaiter(this, void 0, void 0, function* () {
|
|
468
|
-
if (describeCertificate.callCount < 3) {
|
|
469
|
-
return {
|
|
470
|
-
Certificate: {
|
|
471
|
-
Status: "PENDING_VALIDATION"
|
|
472
404
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
else {
|
|
476
|
-
return {
|
|
477
|
-
Certificate: {
|
|
478
|
-
Status: "ISSUED"
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
}));
|
|
483
|
-
yield this.deployer.doCreateCertificate("test.webda.io.", { Id: "1234", Name: "", CallerReference: "" });
|
|
484
|
-
assert.strictEqual(createDNSEntry.calledWith("bouzouf.com", "CNAME", "plop.com.", { Id: "1234", Name: "", CallerReference: "" }), true);
|
|
485
|
-
assert.strictEqual(describeCertificate.callCount, 3);
|
|
486
|
-
waitFor.resetHistory();
|
|
487
|
-
describeCertificate.resolves({ Certificate: { Status: "ERROR" } });
|
|
488
|
-
let exception = false;
|
|
489
|
-
try {
|
|
490
|
-
// Should be able to use assert.rejects
|
|
491
|
-
yield this.deployer.doCreateCertificate("test.webda.io.", { Id: "1234" });
|
|
405
|
+
reject("max");
|
|
406
|
+
});
|
|
492
407
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
408
|
+
});
|
|
409
|
+
describeCertificate.callsFake(async () => {
|
|
410
|
+
if (describeCertificate.callCount < 3) {
|
|
411
|
+
return {
|
|
412
|
+
Certificate: {
|
|
413
|
+
Status: "PENDING_VALIDATION"
|
|
414
|
+
}
|
|
415
|
+
};
|
|
496
416
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
testCreateDNSEntry() {
|
|
505
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
506
|
-
var callSpy = sinon.stub();
|
|
507
|
-
var getZoneForDomainName = sinon.stub(this.deployer, "getZoneForDomainName");
|
|
508
|
-
getZoneForDomainName.callsFake(() => __awaiter(this, void 0, void 0, function* () {
|
|
509
|
-
if (getZoneForDomainName.callCount === 1) {
|
|
510
|
-
return undefined;
|
|
417
|
+
else {
|
|
418
|
+
return {
|
|
419
|
+
Certificate: {
|
|
420
|
+
Status: "ISSUED"
|
|
421
|
+
}
|
|
422
|
+
};
|
|
511
423
|
}
|
|
512
|
-
|
|
513
|
-
})
|
|
514
|
-
|
|
515
|
-
|
|
424
|
+
});
|
|
425
|
+
await this.deployer.doCreateCertificate("test.webda.io.", { Id: "1234", Name: "", CallerReference: "" });
|
|
426
|
+
assert.strictEqual(createDNSEntry.calledWith("bouzouf.com", "CNAME", "plop.com.", { Id: "1234", Name: "", CallerReference: "" }), true);
|
|
427
|
+
assert.strictEqual(describeCertificate.callCount, 3);
|
|
428
|
+
waitFor.resetHistory();
|
|
429
|
+
describeCertificate.resolves({ Certificate: { Status: "ERROR" } });
|
|
430
|
+
let exception = false;
|
|
516
431
|
try {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
yield this.deployer.restrictedCall("createDNSEntry", "webda.io.", "CNAME", "loopingz.com");
|
|
520
|
-
assert.strictEqual(callSpy.calledOnce, true);
|
|
521
|
-
assert.deepStrictEqual(callSpy.firstCall.firstArg, {
|
|
522
|
-
HostedZoneId: "1234",
|
|
523
|
-
ChangeBatch: {
|
|
524
|
-
Changes: [
|
|
525
|
-
{
|
|
526
|
-
Action: "UPSERT",
|
|
527
|
-
ResourceRecordSet: {
|
|
528
|
-
Name: "webda.io.",
|
|
529
|
-
ResourceRecords: [
|
|
530
|
-
{
|
|
531
|
-
Value: "loopingz.com"
|
|
532
|
-
}
|
|
533
|
-
],
|
|
534
|
-
TTL: 360,
|
|
535
|
-
Type: "CNAME"
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
],
|
|
539
|
-
Comment: "webda-automated-deploiement"
|
|
540
|
-
}
|
|
541
|
-
});
|
|
432
|
+
// Should be able to use assert.rejects
|
|
433
|
+
await this.deployer.doCreateCertificate("test.webda.io.", { Id: "1234" });
|
|
542
434
|
}
|
|
543
|
-
|
|
544
|
-
|
|
435
|
+
catch (err) {
|
|
436
|
+
assert.deepStrictEqual(err, { Status: "ERROR" });
|
|
437
|
+
exception = true;
|
|
545
438
|
}
|
|
546
|
-
|
|
439
|
+
assert.strictEqual(exception, true);
|
|
440
|
+
}
|
|
441
|
+
finally {
|
|
442
|
+
mock.restore();
|
|
443
|
+
}
|
|
547
444
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
445
|
+
async testCreateDNSEntry() {
|
|
446
|
+
var callSpy = sinon.stub();
|
|
447
|
+
var getZoneForDomainName = sinon.stub(this.deployer, "getZoneForDomainName");
|
|
448
|
+
getZoneForDomainName.callsFake(async () => {
|
|
449
|
+
if (getZoneForDomainName.callCount === 1) {
|
|
450
|
+
return undefined;
|
|
451
|
+
}
|
|
452
|
+
return { Id: "1234", CallerReference: "", Name: "" };
|
|
554
453
|
});
|
|
454
|
+
callSpy.resolves();
|
|
455
|
+
const mock = mockClient(Route53).on(ChangeResourceRecordSetsCommand).callsFake(callSpy);
|
|
456
|
+
try {
|
|
457
|
+
await assert.rejects(async () => await this.deployer.restrictedCall("createDNSEntry", "webda.io", "CNAME", "loopingz.com"), /Domain is not handled on AWS/g);
|
|
458
|
+
assert.strictEqual(callSpy.notCalled, true);
|
|
459
|
+
await this.deployer.restrictedCall("createDNSEntry", "webda.io.", "CNAME", "loopingz.com");
|
|
460
|
+
assert.strictEqual(callSpy.calledOnce, true);
|
|
461
|
+
assert.deepStrictEqual(callSpy.firstCall.firstArg, {
|
|
462
|
+
HostedZoneId: "1234",
|
|
463
|
+
ChangeBatch: {
|
|
464
|
+
Changes: [
|
|
465
|
+
{
|
|
466
|
+
Action: "UPSERT",
|
|
467
|
+
ResourceRecordSet: {
|
|
468
|
+
Name: "webda.io.",
|
|
469
|
+
ResourceRecords: [
|
|
470
|
+
{
|
|
471
|
+
Value: "loopingz.com"
|
|
472
|
+
}
|
|
473
|
+
],
|
|
474
|
+
TTL: 360,
|
|
475
|
+
Type: "CNAME"
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
],
|
|
479
|
+
Comment: "webda-automated-deploiement"
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
finally {
|
|
484
|
+
mock.restore();
|
|
485
|
+
}
|
|
555
486
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
});
|
|
487
|
+
async testHash() {
|
|
488
|
+
assert.strictEqual(await this.deployer.restrictedCall("md5", "bouzouf"), "fc45f69f910da129848cd265448a5d00");
|
|
489
|
+
assert.strictEqual(await this.deployer.restrictedCall("hash", "bouzouf"), "fc45f69f910da129848cd265448a5d00");
|
|
490
|
+
assert.strictEqual(await this.deployer.restrictedCall("hash", "bouzouf", "md5", "base64"), "/EX2n5ENoSmEjNJlRIpdAA==");
|
|
491
|
+
assert.strictEqual(await this.deployer.restrictedCall("hash", "bouzouf", "sha256", "hex"), "af6773b1075007089c46a6d0b8e9ac03abfdb526de0683bfeb723f2448ea3f66");
|
|
492
|
+
}
|
|
493
|
+
async cov() {
|
|
494
|
+
assert.strictEqual(this.deployer.getRegion(), "us-east-1");
|
|
495
|
+
this.deployer.waitFor(async (resolve) => {
|
|
496
|
+
resolve();
|
|
497
|
+
return true;
|
|
498
|
+
}, 1, "test", 1);
|
|
499
|
+
this.deployer.resources.Tags = [{ Key: "plop", Value: "test" }];
|
|
500
|
+
// @ts-ignore
|
|
501
|
+
this.deployer.resources.Plop = { Tags: { plop2: "oké yep" } };
|
|
502
|
+
assert.strictEqual(this.deployer.getDefaultTagsAsS3Tagging("Plop"), "plop2=ok%C3%A9%20yep&plop=test");
|
|
568
503
|
}
|
|
569
504
|
replaceForAWS() {
|
|
570
505
|
assert.strictEqual(this.deployer._replaceForAWS("my/id"), "my_id");
|
|
@@ -578,51 +513,51 @@ let AWSDeployerTest = class AWSDeployerTest extends deployertest_1.DeployerTest
|
|
|
578
513
|
}
|
|
579
514
|
};
|
|
580
515
|
__decorate([
|
|
581
|
-
|
|
516
|
+
test
|
|
582
517
|
], AWSDeployerTest.prototype, "mapToArrayTags", null);
|
|
583
518
|
__decorate([
|
|
584
|
-
|
|
519
|
+
test
|
|
585
520
|
], AWSDeployerTest.prototype, "putFilesOnBucket", null);
|
|
586
521
|
__decorate([
|
|
587
|
-
|
|
522
|
+
test
|
|
588
523
|
], AWSDeployerTest.prototype, "testGetPolicyDocument", null);
|
|
589
524
|
__decorate([
|
|
590
|
-
|
|
525
|
+
test
|
|
591
526
|
], AWSDeployerTest.prototype, "testGetDefaultVpc", null);
|
|
592
527
|
__decorate([
|
|
593
|
-
|
|
528
|
+
test
|
|
594
529
|
], AWSDeployerTest.prototype, "testCommonPrefix", null);
|
|
595
530
|
__decorate([
|
|
596
|
-
|
|
531
|
+
test
|
|
597
532
|
], AWSDeployerTest.prototype, "testCreateBucket", null);
|
|
598
533
|
__decorate([
|
|
599
|
-
|
|
534
|
+
test
|
|
600
535
|
], AWSDeployerTest.prototype, "testPutBucket", null);
|
|
601
536
|
__decorate([
|
|
602
|
-
|
|
537
|
+
test
|
|
603
538
|
], AWSDeployerTest.prototype, "testGetCertificate", null);
|
|
604
539
|
__decorate([
|
|
605
|
-
|
|
540
|
+
test
|
|
606
541
|
], AWSDeployerTest.prototype, "testGetZoneForDomainName", null);
|
|
607
542
|
__decorate([
|
|
608
|
-
|
|
543
|
+
test
|
|
609
544
|
], AWSDeployerTest.prototype, "testDoCreateCertificate", null);
|
|
610
545
|
__decorate([
|
|
611
|
-
|
|
546
|
+
test
|
|
612
547
|
], AWSDeployerTest.prototype, "testCreateDNSEntry", null);
|
|
613
548
|
__decorate([
|
|
614
|
-
|
|
549
|
+
test
|
|
615
550
|
], AWSDeployerTest.prototype, "testHash", null);
|
|
616
551
|
__decorate([
|
|
617
|
-
|
|
552
|
+
test
|
|
618
553
|
], AWSDeployerTest.prototype, "cov", null);
|
|
619
554
|
__decorate([
|
|
620
|
-
|
|
555
|
+
test
|
|
621
556
|
], AWSDeployerTest.prototype, "replaceForAWS", null);
|
|
622
557
|
__decorate([
|
|
623
|
-
|
|
558
|
+
test
|
|
624
559
|
], AWSDeployerTest.prototype, "transformArrayTagsToMap", null);
|
|
625
560
|
AWSDeployerTest = __decorate([
|
|
626
|
-
|
|
561
|
+
suite
|
|
627
562
|
], AWSDeployerTest);
|
|
628
563
|
//# sourceMappingURL=index.spec.js.map
|