kong-dashboard
Version:
Web UI for managing Kong gateway
103 lines (87 loc) • 3.48 kB
JavaScript
var HomePage = require('../util/HomePage');
var Sidebar = require('../util/Sidebar');
var ListCertificatesPage = require('../util/ListCertificatesPage');
var CreateCertificatePage = require('../util/CreateCertificatePage');
var KongDashboard = require('../util/KongDashboard');
var Kong = require('../util/KongClient');
var request = require('../../lib/request');
var PropertyInput = require('../util/PropertyInput');
var semver = require('semver');
var kd = new KongDashboard();
describe('Certificate creation testing:', () => {
if (semver.lt(process.env.KONG_VERSION, '0.10.0')) {
// Only run tests if the Kong version is 0.10.0 or higher as Certificates are supported starting version 0.10 only
return;
}
if (semver.gte(process.env.KONG_VERSION, '0.15.0')) {
// seems there is a cert format validation enforcement in latest kong versions, which makes these tests fail
// skipping tests for now, cause I wasn't able to overcome this validation issues (would appreciate any help)
// TODO fix tests for newer Kong versions
return;
}
var certificateSchema;
beforeEach((done) => {
Kong.deleteAllCertificates().then(done);
});
afterEach(() => {
browser.refresh();
});
beforeAll((done) => {
kd.start({'--kong-url': 'http://127.0.0.1:8001'}, () => {
request.get('http://127.0.0.1:8081/config').then((response) => {
eval(response.body);
certificateSchema = __env.schemas.certificate;
done();
});
});
});
afterAll((done) => {
kd.stop(done);
});
it('should recognize and display an input for every field', () => {
HomePage.visit();
Sidebar.clickOn('Certificates');
ListCertificatesPage.clickAddButton();
expect(browser.getCurrentUrl()).toEqual('http://localhost:8081/#!/certificates/add');
Object.keys(certificateSchema.properties).forEach((fieldName) => {
expect(PropertyInput.getElement(fieldName).isPresent()).toBeTruthy('Form section for ' + fieldName + ' is missing');
})
});
it('should correctly create a Certificate', (done) => {
HomePage.visit();
Sidebar.clickOn('Certificates');
ListCertificatesPage.clickAddButton();
const inputs = {
cert: 'abc',
key: 'def',
snis: 'aaa.com,bbb.com'
};
Object.keys(inputs).forEach((inputName) => {
PropertyInput.set(inputName, inputs[inputName]);
});
CreateCertificatePage.submit().then(() => {
expect(element(by.cssContainingText('div.toast', 'Certificate created')).isPresent()).toBeTruthy();
return browser.waitForAngular(); // waiting for ajax call to create the certificate to be finished.
}).then(() => {
return Kong.getFirstCertificate();
}).then((certificate) => {
delete certificate.created_at;
delete certificate.id;
expect(certificate.cert).toEqual('abc');
expect(certificate.key).toEqual('def');
expect(certificate.snis.sort()).toEqual(['aaa.com', 'bbb.com']);
done();
});
});
it('should error when required field are missing', (done) => {
HomePage.visit();
Sidebar.clickOn('Certificates');
ListCertificatesPage.clickAddButton();
CreateCertificatePage.submit().then(() => {
expect(element(by.cssContainingText('div.toast', 'Certificate created')).isPresent()).toBeFalsy();
PropertyInput.getElementErrorMsg('cert').isPresent();
PropertyInput.getElementErrorMsg('key').isPresent();
done();
});
});
});