Skip to content

Commit edbed1a

Browse files
committed
Adds tests for settings endpoints
and reenables dns cert test and fixes problems with schema
1 parent 8497022 commit edbed1a

File tree

15 files changed

+160
-40
lines changed

15 files changed

+160
-40
lines changed

backend/internal/nginx.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ const internalNginx = {
181181
* @param {Object} host
182182
* @returns {Promise}
183183
*/
184-
generateConfig: (host_type, host) => {
184+
generateConfig: (host_type, host_row) => {
185+
// Prevent modifying the original object:
186+
let host = JSON.parse(JSON.stringify(host_row));
185187
const nice_host_type = internalNginx.getFileFriendlyHostType(host_type);
186188

187189
if (config.debug()) {

backend/schema/components/proxy-host-object.json

+1-9
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
"locations",
2424
"hsts_enabled",
2525
"hsts_subdomains",
26-
"certificate",
27-
"use_default_location",
28-
"ipv6"
26+
"certificate"
2927
],
3028
"additionalProperties": false,
3129
"properties": {
@@ -151,12 +149,6 @@
151149
"$ref": "./access-list-object.json"
152150
}
153151
]
154-
},
155-
"use_default_location": {
156-
"type": "boolean"
157-
},
158-
"ipv6": {
159-
"type": "boolean"
160152
}
161153
}
162154
}

backend/schema/components/setting-object.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
},
4747
"meta": {
4848
"description": "Extra metadata",
49-
"example": {},
49+
"example": {
50+
"redirect": "http://example.com",
51+
"html": "<h1>404</h1>"
52+
},
5053
"type": "object"
5154
}
5255
}

backend/schema/paths/nginx/dead-hosts/hostID/put.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@
9494
"avatar": "",
9595
"roles": ["admin"]
9696
},
97-
"certificate": null,
98-
"use_default_location": true,
99-
"ipv6": true
97+
"certificate": null
10098
}
10199
}
102100
},

backend/schema/paths/nginx/dead-hosts/post.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@
7979
"nickname": "Admin",
8080
"avatar": "",
8181
"roles": ["admin"]
82-
},
83-
"use_default_location": true,
84-
"ipv6": true
82+
}
8583
}
8684
}
8785
},

backend/schema/paths/nginx/proxy-hosts/hostID/put.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@
129129
"roles": ["admin"]
130130
},
131131
"certificate": null,
132-
"access_list": null,
133-
"use_default_location": true,
134-
"ipv6": true
132+
"access_list": null
135133
}
136134
}
137135
},

backend/schema/paths/nginx/proxy-hosts/post.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@
114114
"avatar": "//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?default=mm",
115115
"roles": ["admin"]
116116
},
117-
"access_list": null,
118-
"use_default_location": true,
119-
"ipv6": true
117+
"access_list": null
120118
}
121119
}
122120
},

backend/schema/paths/nginx/redirection-hosts/hostID/put.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@
114114
"avatar": "",
115115
"roles": ["admin"]
116116
},
117-
"certificate": null,
118-
"use_default_location": true,
119-
"ipv6": true
117+
"certificate": null
120118
}
121119
}
122120
},

backend/schema/paths/nginx/redirection-hosts/post.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@
9999
"nickname": "Admin",
100100
"avatar": "",
101101
"roles": ["admin"]
102-
},
103-
"use_default_location": true,
104-
"ipv6": true
102+
}
105103
}
106104
}
107105
},

backend/schema/paths/nginx/streams/streamID/put.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@
129129
"roles": ["admin"]
130130
},
131131
"certificate": null,
132-
"access_list": null,
133-
"use_default_location": true,
134-
"ipv6": true
132+
"access_list": null
135133
}
136134
}
137135
},

backend/schema/paths/settings/settingID/put.json

+15-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"name": "settingID",
1414
"schema": {
1515
"type": "string",
16-
"minLength": 1
16+
"minLength": 1,
17+
"enum": ["default-site"]
1718
},
1819
"required": true,
1920
"description": "Setting ID",
@@ -31,10 +32,21 @@
3132
"minProperties": 1,
3233
"properties": {
3334
"value": {
34-
"$ref": "../../../components/setting-object.json#/properties/value"
35+
"type": "string",
36+
"minLength": 1,
37+
"enum": ["congratulations", "404", "444", "redirect", "html"]
3538
},
3639
"meta": {
37-
"$ref": "../../../components/setting-object.json#/properties/meta"
40+
"type": "object",
41+
"additionalProperties": false,
42+
"properties": {
43+
"redirect": {
44+
"type": "string"
45+
},
46+
"html": {
47+
"type": "string"
48+
}
49+
}
3850
}
3951
}
4052
}

test/cypress/e2e/api/FullCertProvision.cy.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('Full Certificate Provisions', () => {
99
});
1010
});
1111

12-
it.only('Should be able to create new http certificate', function() {
12+
it('Should be able to create new http certificate', function() {
1313
cy.task('backendApiPost', {
1414
token: token,
1515
path: '/api/nginx/certificates',
@@ -35,7 +35,7 @@ describe('Full Certificate Provisions', () => {
3535
it('Should be able to create new DNS certificate with Powerdns', function() {
3636
cy.task('backendApiPost', {
3737
token: token,
38-
path: '/api/certificates',
38+
path: '/api/nginx/certificates',
3939
data: {
4040
domain_names: [
4141
'website2.example.com'
@@ -45,7 +45,8 @@ describe('Full Certificate Provisions', () => {
4545
dns_challenge: true,
4646
dns_provider: 'powerdns',
4747
dns_provider_credentials: 'dns_powerdns_api_url = http://ns1.pdns:8081\r\ndns_powerdns_api_key = npm',
48-
letsencrypt_agree: true
48+
letsencrypt_agree: true,
49+
propagation_seconds: 5,
4950
},
5051
provider: 'letsencrypt'
5152
}

test/cypress/e2e/api/Hosts.cy.js test/cypress/e2e/api/ProxyHosts.cy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="cypress" />
22

3-
describe('Hosts endpoints', () => {
3+
describe('Proxy Hosts endpoints', () => {
44
let token;
55

66
before(() => {

test/cypress/e2e/api/Settings.cy.js

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/// <reference types="cypress" />
2+
3+
describe('Settings endpoints', () => {
4+
let token;
5+
6+
before(() => {
7+
cy.getToken().then((tok) => {
8+
token = tok;
9+
});
10+
});
11+
12+
it('Get all settings', function() {
13+
cy.task('backendApiGet', {
14+
token: token,
15+
path: '/api/settings',
16+
}).then((data) => {
17+
cy.validateSwaggerSchema('get', 200, '/settings', data);
18+
expect(data.length).to.be.greaterThan(0);
19+
});
20+
});
21+
22+
it('Get default-site setting', function() {
23+
cy.task('backendApiGet', {
24+
token: token,
25+
path: '/api/settings/default-site',
26+
}).then((data) => {
27+
cy.validateSwaggerSchema('get', 200, '/settings/{settingID}', data);
28+
expect(data).to.have.property('id');
29+
expect(data.id).to.be.equal('default-site');
30+
});
31+
});
32+
33+
it('Default Site congratulations', function() {
34+
cy.task('backendApiPut', {
35+
token: token,
36+
path: '/api/settings/default-site',
37+
data: {
38+
value: 'congratulations',
39+
},
40+
}).then((data) => {
41+
cy.validateSwaggerSchema('put', 200, '/settings/{settingID}', data);
42+
expect(data).to.have.property('id');
43+
expect(data.id).to.be.equal('default-site');
44+
expect(data).to.have.property('value');
45+
expect(data.value).to.be.equal('congratulations');
46+
});
47+
});
48+
49+
it('Default Site 404', function() {
50+
cy.task('backendApiPut', {
51+
token: token,
52+
path: '/api/settings/default-site',
53+
data: {
54+
value: '404',
55+
},
56+
}).then((data) => {
57+
cy.validateSwaggerSchema('put', 200, '/settings/{settingID}', data);
58+
expect(data).to.have.property('id');
59+
expect(data.id).to.be.equal('default-site');
60+
expect(data).to.have.property('value');
61+
expect(data.value).to.be.equal('404');
62+
});
63+
});
64+
65+
it('Default Site 444', function() {
66+
cy.task('backendApiPut', {
67+
token: token,
68+
path: '/api/settings/default-site',
69+
data: {
70+
value: '444',
71+
},
72+
}).then((data) => {
73+
cy.validateSwaggerSchema('put', 200, '/settings/{settingID}', data);
74+
expect(data).to.have.property('id');
75+
expect(data.id).to.be.equal('default-site');
76+
expect(data).to.have.property('value');
77+
expect(data.value).to.be.equal('444');
78+
});
79+
});
80+
81+
it('Default Site redirect', function() {
82+
cy.task('backendApiPut', {
83+
token: token,
84+
path: '/api/settings/default-site',
85+
data: {
86+
value: 'redirect',
87+
meta: {
88+
redirect: 'https://www.google.com',
89+
},
90+
},
91+
}).then((data) => {
92+
cy.validateSwaggerSchema('put', 200, '/settings/{settingID}', data);
93+
expect(data).to.have.property('id');
94+
expect(data.id).to.be.equal('default-site');
95+
expect(data).to.have.property('value');
96+
expect(data.value).to.be.equal('redirect');
97+
expect(data).to.have.property('meta');
98+
expect(data.meta).to.have.property('redirect');
99+
expect(data.meta.redirect).to.be.equal('https://www.google.com');
100+
});
101+
});
102+
103+
it('Default Site html', function() {
104+
cy.task('backendApiPut', {
105+
token: token,
106+
path: '/api/settings/default-site',
107+
data: {
108+
value: 'html',
109+
meta: {
110+
html: '<p>hello world</p>'
111+
},
112+
},
113+
}).then((data) => {
114+
cy.validateSwaggerSchema('put', 200, '/settings/{settingID}', data);
115+
expect(data).to.have.property('id');
116+
expect(data.id).to.be.equal('default-site');
117+
expect(data).to.have.property('value');
118+
expect(data.value).to.be.equal('html');
119+
expect(data).to.have.property('meta');
120+
expect(data.meta).to.have.property('html');
121+
expect(data.meta.html).to.be.equal('<p>hello world</p>');
122+
});
123+
});
124+
});

test/cypress/plugins/backendApi/client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const BackendApi = function(config, token) {
77

88
this.axios = axios.create({
99
baseURL: config.baseUrl,
10-
timeout: 60000,
10+
timeout: 90000,
1111
});
1212
};
1313

0 commit comments

Comments
 (0)