Skip to content

Commit 351ba8d

Browse files
committed
More tests for certificates, fixed schema problems
1 parent 3b89d5f commit 351ba8d

File tree

6 files changed

+98
-17
lines changed

6 files changed

+98
-17
lines changed

backend/internal/certificate.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@ const fs = require('fs');
33
const https = require('https');
44
const tempWrite = require('temp-write');
55
const moment = require('moment');
6+
const archiver = require('archiver');
7+
const path = require('path');
8+
const { isArray } = require('lodash');
69
const logger = require('../logger').ssl;
710
const config = require('../lib/config');
811
const error = require('../lib/error');
912
const utils = require('../lib/utils');
13+
const certbot = require('../lib/certbot');
1014
const certificateModel = require('../models/certificate');
1115
const tokenModel = require('../models/token');
1216
const dnsPlugins = require('../global/certbot-dns-plugins.json');
1317
const internalAuditLog = require('./audit-log');
1418
const internalNginx = require('./nginx');
1519
const internalHost = require('./host');
16-
const certbot = require('../lib/certbot');
17-
const archiver = require('archiver');
18-
const path = require('path');
19-
const { isArray } = require('lodash');
20+
2021

2122
const letsencryptStaging = config.useLetsencryptStaging();
2223
const letsencryptConfig = '/etc/letsencrypt.ini';
2324
const certbotCommand = 'certbot';
2425

2526
function omissions() {
26-
return ['is_deleted'];
27+
return ['is_deleted', 'owner.is_deleted'];
2728
}
2829

2930
const internalCertificate = {

backend/schema/components/certificate-object.json

+21-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,23 @@
2424
"description": "Nice Name for the custom certificate"
2525
},
2626
"domain_names": {
27-
"$ref": "../common.json#/properties/domain_names"
27+
"description": "Domain Names separated by a comma",
28+
"type": "array",
29+
"maxItems": 100,
30+
"uniqueItems": true,
31+
"items": {
32+
"type": "string",
33+
"pattern": "^[^&| @!#%^();:/\\\\}{=+?<>,~`'\"]+$"
34+
}
2835
},
2936
"expires_on": {
3037
"description": "Date and time of expiration",
3138
"readOnly": true,
3239
"type": "string"
3340
},
41+
"owner": {
42+
"$ref": "./user-object.json"
43+
},
3444
"meta": {
3545
"type": "object",
3646
"additionalProperties": false,
@@ -51,12 +61,16 @@
5161
"type": "string"
5262
},
5363
"propagation_seconds": {
54-
"anyOf": [
55-
{
56-
"type": "integer",
57-
"minimum": 0
58-
}
59-
]
64+
"type": "integer",
65+
"minimum": 0
66+
},
67+
"certificate": {
68+
"type": "string",
69+
"minLength": 1
70+
},
71+
"certificate_key": {
72+
"type": "string",
73+
"minLength": 1
6074
}
6175
}
6276
}

backend/schema/paths/nginx/certificates/certID/upload/post.json

+19
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@
5555
"certificate_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC1n9j9C5Bes1nd\nqACDckERauxXVNKCnUlUM1buGBx1xc+j2e2Ar23wUJJuWBY18VfT8yqfqVDktO2w\nrbmvZvLuPmXePOKbIKS+XXh+2NG9L5bDG9rwGFCRXnbQj+GWCdMfzx14+CR1IHge\nYz6Cv/Si2/LJPCh/CoBfM4hUQJON3lxAWrWBpdbZnKYMrxuPBRfW9OuzTbCVXToQ\noxRAHiOR9081Xn1WeoKr7kVBIa5UphlvWXa12w1YmUwJu7YndnJGIavLWeNCVc7Z\nEo+nS8Wr/4QWicatIWZXpVaEOPhRoeplQDxNWg5b/Q26rYoVd7PrCmRs7sVcH79X\nzGONeH1PAgMBAAECggEAANb3Wtwl07pCjRrMvc7WbC0xYIn82yu8/g2qtjkYUJcU\nia5lQbYN7RGCS85Oc/tkq48xQEG5JQWNH8b918jDEMTrFab0aUEyYcru1q9L8PL6\nYHaNgZSrMrDcHcS8h0QOXNRJT5jeGkiHJaTR0irvB526tqF3knbK9yW22KTfycUe\na0Z9voKn5xRk1DCbHi/nk2EpT7xnjeQeLFaTIRXbS68omkr4YGhwWm5OizoyEGZu\nW0Zum5BkQyMr6kor3wdxOTG97ske2rcyvvHi+ErnwL0xBv0qY0Dhe8DpuXpDezqw\no72yY8h31Fu84i7sAj24YuE5Df8DozItFXQpkgbQ6QKBgQDPrufhvIFm2S/MzBdW\nH8JxY7CJlJPyxOvc1NIl9RczQGAQR90kx52cgIcuIGEG6/wJ/xnGfMmW40F0DnQ+\nN+oLgB9SFxeLkRb7s9Z/8N3uIN8JJFYcerEOiRQeN2BXEEWJ7bUThNtsVrAcKoUh\nELsDmnHW/3V+GKwhd0vpk842+wKBgQDf4PGLG9PTE5tlAoyHFodJRd2RhTJQkwsU\nMDNjLJ+KecLv+Nl+QiJhoflG1ccqtSFlBSCG067CDQ5LV0xm3mLJ7pfJoMgjcq31\nqjEmX4Ls91GuVOPtbwst3yFKjsHaSoKB5fBvWRcKFpBUezM7Qcw2JP3+dQT+bQIq\ncMTkRWDSvQKBgQDOdCQFDjxg/lR7NQOZ1PaZe61aBz5P3pxNqa7ClvMaOsuEQ7w9\nvMYcdtRq8TsjA2JImbSI0TIg8gb2FQxPcYwTJKl+FICOeIwtaSg5hTtJZpnxX5LO\nutTaC0DZjNkTk5RdOdWA8tihyUdGqKoxJY2TVmwGe2rUEDjFB++J4inkEwKBgB6V\ng0nmtkxanFrzOzFlMXwgEEHF+Xaqb9QFNa/xs6XeNnREAapO7JV75Cr6H2hFMFe1\nmJjyqCgYUoCWX3iaHtLJRnEkBtNY4kzyQB6m46LtsnnnXO/dwKA2oDyoPfFNRoDq\nYatEd3JIXNU9s2T/+x7WdOBjKhh72dTkbPFmTPDdAoGAU6rlPBevqOFdObYxdPq8\nEQWu44xqky3Mf5sBpOwtu6rqCYuziLiN7K4sjN5GD5mb1cEU+oS92ZiNcUQ7MFXk\n8yTYZ7U0VcXyAcpYreWwE8thmb0BohJBr+Mp3wLTx32x0HKdO6vpUa0d35LUTUmM\nRrKmPK/msHKK/sVHiL+NFqo=\n-----END PRIVATE KEY-----\n"
5656
}
5757
}
58+
},
59+
"schema": {
60+
"type": "object",
61+
"additionalProperties": false,
62+
"required": ["certificate", "certificate_key"],
63+
"properties": {
64+
"certificate": {
65+
"type": "string",
66+
"minLength": 1
67+
},
68+
"certificate_key": {
69+
"type": "string",
70+
"minLength": 1
71+
},
72+
"intermediate_certificate": {
73+
"type": "string",
74+
"minLength": 1
75+
}
76+
}
5877
}
5978
}
6079
}

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

+47
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
describe('Certificates endpoints', () => {
44
let token;
5+
let certID;
56

67
before(() => {
78
cy.getToken().then((tok) => {
@@ -24,6 +25,52 @@ describe('Certificates endpoints', () => {
2425
});
2526
});
2627

28+
it('Custom certificate lifecycle', function() {
29+
cy.task('backendApiPost', {
30+
token: token,
31+
path: '/api/nginx/certificates',
32+
data: {
33+
provider: "other",
34+
nice_name: "Test Certificate",
35+
},
36+
}).then((data) => {
37+
cy.validateSwaggerSchema('post', 201, '/nginx/certificates', data);
38+
expect(data).to.have.property('id');
39+
certID = data.id;
40+
41+
cy.task('backendApiPostFiles', {
42+
token: token,
43+
path: `/api/nginx/certificates/${certID}/upload`,
44+
files: {
45+
certificate: 'test.example.com.pem',
46+
certificate_key: 'test.example.com-key.pem',
47+
},
48+
}).then((data) => {
49+
cy.validateSwaggerSchema('post', 201, '/nginx/certificates/upload', data);
50+
expect(data).to.have.property('certificate');
51+
expect(data).to.have.property('certificate_key');
52+
53+
cy.task('backendApiDelete', {
54+
token: token,
55+
path: `/api/nginx/certificates/${certID}`
56+
}).then((data) => {
57+
cy.validateSwaggerSchema('delete', 200, '/nginx/certificates/{certID}', data);
58+
expect(data).to.be.equal(true);
59+
});
60+
});
61+
});
62+
});
63+
64+
it('Should be able to get all certs', function() {
65+
cy.task('backendApiGet', {
66+
token: token,
67+
path: '/api/nginx/certificates?expand=owner'
68+
}).then((data) => {
69+
cy.validateSwaggerSchema('get', 200, '/nginx/certificates', data);
70+
expect(data.length).to.be.greaterThan(0);
71+
});
72+
});
73+
2774
it('Request Certificate - CVE-2024-46256/CVE-2024-46257', function() {
2875
cy.task('backendApiPost', {
2976
token: token,

test/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"dependencies": {
7-
"@jc21/cypress-swagger-validation": "^0.2.7",
7+
"@jc21/cypress-swagger-validation": "^0.2.8",
88
"axios": "^1.7.7",
99
"cypress": "^13.15.0",
1010
"cypress-multi-reporters": "^1.6.4",

test/yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@
167167
resolved "https://registry.yarnpkg.com/@humanwhocodes/retry/-/retry-0.3.1.tgz#c72a5c76a9fbaf3488e231b13dc52c0da7bab42a"
168168
integrity sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA==
169169

170-
"@jc21/cypress-swagger-validation@^0.2.7":
171-
version "0.2.7"
172-
resolved "https://registry.yarnpkg.com/@jc21/cypress-swagger-validation/-/cypress-swagger-validation-0.2.7.tgz#64642b12d98b884df8c30b72852162941285d2af"
173-
integrity sha512-4EQ0gfigRwVVl3DnVYbR48/EKGnn7oH5YYdMzf6zqypO+bqYvDHu9kgk/WqkGlT/aauGQ7e0YGMo8ZvR7mL0Ng==
170+
"@jc21/cypress-swagger-validation@^0.2.8":
171+
version "0.2.8"
172+
resolved "https://registry.yarnpkg.com/@jc21/cypress-swagger-validation/-/cypress-swagger-validation-0.2.8.tgz#8ab059bd41e3ee100a1998a1484b9e5a2e9a4224"
173+
integrity sha512-9fiZIHj3//bJjC5YUMOc42RnoEUeeokVn6xtMnP52XIZ/ryWQ9PIyFdlOAH8q/LW/uPxozJo2+hdB6ou4iurag==
174174
dependencies:
175175
"@apidevtools/swagger-parser" "^10.1.0"
176176
ajv "^8.17.1"

0 commit comments

Comments
 (0)