Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage #4125

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 112 additions & 2 deletions test/cypress/e2e/api/ProxyHosts.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ describe('Proxy Hosts endpoints', () => {
token: token,
path: '/api/nginx/proxy-hosts',
data: {
domain_names: ['test.example.com'],
// Use current timestamp (in ms) to generate unique hosts and
// not have failing tests on second run without clearing db
domain_names: [`test-${Date.now()}.example.com`],
forward_scheme: 'http',
forward_host: '1.1.1.1',
forward_port: 80,
Expand All @@ -32,7 +34,7 @@ describe('Proxy Hosts endpoints', () => {
http2_support: false,
hsts_enabled: false,
hsts_subdomains: false,
ssl_forced: false
ssl_forced: false,
}
}).then((data) => {
cy.validateSwaggerSchema('post', 201, '/nginx/proxy-hosts', data);
Expand All @@ -45,4 +47,112 @@ describe('Proxy Hosts endpoints', () => {
});
});

it('Should be able to get a http host', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/nginx/proxy-hosts',
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/nginx/proxy-hosts', data);
expect(data.length).to.be.greaterThan(0);
let hostId = data[0].id;
expect(hostId).to.be.greaterThan(0);
cy.task('backendApiGet', {
token: token,
path: `/api/nginx/proxy-hosts/${hostId}`,
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/nginx/proxy-hosts/{hostID}', data);
});
});
});

it('Should be able to update a http host', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/nginx/proxy-hosts',
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/nginx/proxy-hosts', data);
expect(data.length).to.be.greaterThan(0);
let hostId = data[0].id;
expect(hostId).to.be.greaterThan(0);
cy.task('backendApiPut', {
token: token,
path: `/api/nginx/proxy-hosts/${hostId}`,
data: {
domain_names: [`test-${Date.now()}.example.com`],
forward_scheme: 'http',
forward_host: '1.1.1.1',
forward_port: 80,
access_list_id: '0',
certificate_id: 0,
meta: {
letsencrypt_agree: false,
dns_challenge: false
},
advanced_config: '',
locations: [],
block_exploits: false,
caching_enabled: false,
allow_websocket_upgrade: false,
http2_support: false,
hsts_enabled: false,
hsts_subdomains: false,
ssl_forced: false,
}
}).then((data) => {
cy.validateSwaggerSchema('put', 200, '/nginx/proxy-hosts/{hostID}', data);
expect(data).to.have.property('id');
expect(data.id).to.be.greaterThan(0);
expect(data).to.have.property('enabled');
expect(data).to.have.property("enabled", true);
expect(data).to.have.property('meta');
expect(data.meta.nginx_online).to.be.true;
});
});
});

it('Should be able to disable and enable a http host', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/nginx/proxy-hosts',
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/nginx/proxy-hosts', data);
expect(data.length).to.be.greaterThan(0);
let hostId = data[0].id;
expect(hostId).to.be.greaterThan(0);
cy.task('backendApiPost', {
token: token,
path: `/api/nginx/proxy-hosts/${hostId}/disable`,
}).then((data) => {
cy.validateSwaggerSchema('post', 200, '/nginx/proxy-hosts/{hostID}/disable', data);
expect(data).to.be.true;

cy.task('backendApiPost', {
token: token,
path: `/api/nginx/proxy-hosts/${hostId}/enable`,
}).then((data) => {
cy.validateSwaggerSchema('post', 200, '/nginx/proxy-hosts/{hostID}/enable', data);
expect(data).to.be.true;
});
});
});
});

it('Should be able to delete a http host', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/nginx/proxy-hosts',
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/nginx/proxy-hosts', data);
expect(data.length).to.be.greaterThan(0);
let hostId = data[0].id;
expect(hostId).to.be.greaterThan(0);
cy.task('backendApiDelete', {
token: token,
path: `/api/nginx/proxy-hosts/${hostId}`
}).then((data) => {
cy.validateSwaggerSchema('delete', 200, '/nginx/proxy-hosts/{hostID}', data);
expect(data).to.be.true;
});
});
});
});
14 changes: 14 additions & 0 deletions test/cypress/e2e/frontend/Login.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference types="cypress" />

describe('Frontend Login', () => {
it('Login works', function() {
cy.intercept('/api/users/me*').as('getCurrentUser')

cy.visit("/")
cy.get('input[name="identity"]').type("[email protected]")
cy.get('input[name="secret"]').type("changeme")
cy.get('button[type=submit]').click()

cy.wait("@getCurrentUser")
});
});