-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathConfig.js
More file actions
190 lines (158 loc) · 6.31 KB
/
Config.js
File metadata and controls
190 lines (158 loc) · 6.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
'use strict';
const assert = require('assert');
const joi = require('joi');
const sinon = require('sinon');
const config = require('../../../lib/Config');
const { Config } = require('../../../lib/Config');
const { authJoi, inheritedAuthJoi } = require('../../../lib/config/configItems.joi');
describe('backbeat config parsing and validation', () => {
it('should parse correctly the default config', () => {
assert.notStrictEqual(config, undefined);
});
describe('inherited auth', () => {
const schema = joi.object({
auth: authJoi.optional(),
child: joi.object({
auth: inheritedAuthJoi,
}),
});
const authObject = {
type: 'service',
account: 'account1',
};
it('fail if auth missing in both parent and child', () => {
const obj = {
child: {},
};
assert(schema.validate(obj).error);
});
it('allow missing auth in child if defined in parent', () => {
const obj = {
auth: authObject,
child: {},
};
return schema.validateAsync(obj);
});
it('allow missing auth in parent if defined in child', () => {
const obj = {
child: {
auth: authObject,
},
};
return schema.validateAsync(obj);
});
it('allow auth in both parent and child', () => {
const obj = {
auth: authObject,
child: {
auth: authObject,
},
};
return schema.validateAsync(obj);
});
});
});
describe('Site name', () => {
let conf;
beforeEach(() => {
conf = new Config();
});
afterEach(() => {
delete process.env.BOOTSTRAP_SITE_NAME;
});
it('should filter bootstrapList based on SITE_NAME', () => {
process.env.BOOTSTRAP_SITE_NAME = 'test-site-2';
const expectedBootstrapList = conf.bootstrapList.filter(item => item.site === 'test-site-2');
const newConfig = new Config();
assert.deepStrictEqual(newConfig.bootstrapList, expectedBootstrapList);
});
it('should not filter bootstrapList if SITE_NAME is not set', () => {
const expectedBootstrapList = conf.bootstrapList;
const newConfig = new Config();
assert.deepStrictEqual(newConfig.bootstrapList, expectedBootstrapList);
});
});
describe('Config', () => {
describe('getReplicationSiteDestConfig', () => {
let ogConfigFileEnv;
before(() => {
ogConfigFileEnv = process.env.BACKBEAT_CONFIG_FILE;
});
afterEach(() => sinon.restore());
after(() => {
if (ogConfigFileEnv) {
process.env.BACKBEAT_CONFIG_FILE = ogConfigFileEnv;
}
});
describe('bootstrapList server normalization', () => {
let conf;
before(() => {
process.env.BACKBEAT_CONFIG_FILE = `${__dirname}/configs/replicationServersConfig.json`;
conf = new Config();
});
it('should normalize server entries with default port 443 for https transport', () => {
const entry = conf.bootstrapList.find(e => e.site === 'https-site');
assert.deepStrictEqual(entry.servers, ['s3.example.com:443']);
});
it('should normalize server entries with default port 80 for http transport', () => {
const entry = conf.bootstrapList.find(e => e.site === 'http-site');
assert.deepStrictEqual(entry.servers, ['s3.example.com:80']);
});
it('should preserve explicit port in server entries', () => {
const entry = conf.bootstrapList.find(e => e.site === 'explicit-port-site');
assert.deepStrictEqual(entry.servers, ['s3.example.com:8443']);
});
it('should not modify endpoint without servers array', () => {
const entry = conf.bootstrapList.find(e => e.site === 'aws-site');
assert.strictEqual(entry.servers, undefined);
assert.strictEqual(entry.type, 'aws_s3');
});
});
describe('getReplicationSiteDestConfig', () => {
it('should return replication site destination config', () => {
process.env.BACKBEAT_CONFIG_FILE = `${__dirname}/configs/replicationMultiDestConfig.json`;
const conf = new Config();
const destConfig = conf.getReplicationSiteDestConfig('aws3');
assert.deepStrictEqual(destConfig, {
transport: 'https',
auth: {
type: 'service',
account: 'service-replication-3',
},
replicationEndpoint: {
site: 'aws3',
type: 'aws_s3',
},
});
});
it('should return default replication destination config when site one is not available', () => {
process.env.BACKBEAT_CONFIG_FILE = `${__dirname}/configs/replicationMultiDestConfig.json`;
const conf = new Config();
sinon.stub(conf.extensions.replication, 'destination').value({
transport: 'https',
auth: {
type: 'service',
account: 'service-replication',
},
bootstrapList: [
{ site: 'aws1', type: 'aws_s3' },
{ site: 'aws2', type: 'aws_s3' },
{ site: 'aws3', type: 'aws_s3' }
]
});
const destConfig = conf.getReplicationSiteDestConfig('aws3');
assert.deepStrictEqual(destConfig, {
transport: 'https',
auth: {
type: 'service',
account: 'service-replication',
},
replicationEndpoint: {
site: 'aws3',
type: 'aws_s3',
},
});
});
});
});
});