Version 3 starter

This commit is contained in:
Jamie Curnow
2021-06-14 19:29:35 +10:00
parent 60fc57431a
commit 6205434140
642 changed files with 25817 additions and 32319 deletions

View File

@@ -0,0 +1,119 @@
/// <reference types="Cypress" />
describe('Certificates endpoints', () => {
let token;
let certID;
before(() => {
cy.getToken().then((tok) => {
token = tok;
});
});
it('Should be able to create new certificate', function() {
cy.task('backendApiPost', {
token: token,
path: '/api/certificates',
data: {
type: 'http',
certificate_authority_id: 1,
name: 'My First Cert',
domain_names: [
'jc21.com',
'*.google.com'
]
}
}).then((data) => {
// Check the swagger schema:
cy.validateSwaggerSchema('post', 201, '/certificates', data);
expect(data.result).to.have.property('id');
expect(data.result.id).to.be.greaterThan(0);
expect(data.result.user_id).to.be.greaterThan(0);
certID = data.result.id;
});
});
it('Should be able to get a certificate', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/certificates/' + certID
}).then((data) => {
// Check the swagger schema:
cy.validateSwaggerSchema('get', 200, '/certificates/{certificateID}', data);
expect(data.result).to.have.property('id', certID);
});
});
it('Should be able to update a certificate', function() {
cy.task('backendApiPut', {
token: token,
path: '/api/certificates/' + certID,
data: {
name: 'My Updated Cert'
}
}).then((data) => {
// Check the swagger schema:
cy.validateSwaggerSchema('put', 200, '/certificates/{certificateID}', data);
expect(data.result).to.have.property('id', certID);
expect(data.result).to.have.property('name', 'My Updated Cert');
});
});
it('Should be able to get all certificates', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/certificates'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/certificates', data);
expect(data).to.have.property('result');
expect(data.result).to.have.property('items');
expect(data.result.items.length).to.be.greaterThan(0);
});
});
it('Should be able to get all certificates with filters A', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/certificates?sort=name&name:starts=my&limit=1'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/certificates', data);
expect(data).to.have.property('result');
expect(data.result).to.have.property('items');
expect(data.result.items.length).to.be.greaterThan(0);
});
});
it('Should be able to get all certificates with filters B', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/certificates?id:in=1,2,3,4,5&limit=1'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/certificates', data);
expect(data).to.have.property('result');
expect(data.result).to.have.property('items');
expect(data.result.items.length).to.eq(1);
});
});
it('Should be able to get all certificates with filters C', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/certificates?name:starts=xxxxxxxxxxxxxxx'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/certificates', data);
expect(data).to.have.property('result');
expect(data.result).to.have.property('total', 0);
});
});
it('Should be able to delete a certificate', function() {
cy.task('backendApiDelete', {
token: token,
path: '/api/certificates/' + certID
}).then((data) => {
cy.validateSwaggerSchema('delete', 200, '/certificates/{certificateID}', data);
expect(data).to.have.property('result', true);
});
});
});

View File

@@ -1,20 +1,12 @@
/// <reference types="Cypress" />
describe('Basic API checks', () => {
it('Should return a valid health payload', function () {
it('Should return a valid health payload', function() {
cy.task('backendApiGet', {
path: '/api/',
}).then((data) => {
// Check the swagger schema:
expect(data.result.healthy, 'healthy should equal true').to.equal(true);
cy.validateSwaggerSchema('get', 200, '/', data);
});
});
it('Should return a valid schema payload', function () {
cy.task('backendApiGet', {
path: '/api/schema',
}).then((data) => {
expect(data.openapi).to.be.equal('3.0.0');
});
});
});

View File

@@ -0,0 +1,118 @@
/// <reference types="Cypress" />
const generateRandomString = function (length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
};
describe('Settings endpoints', () => {
let token;
let settingName = 'cypressSetting_' + generateRandomString(12);
before(() => {
cy.getToken().then((tok) => {
token = tok;
});
});
it('Should be able to create new settting', function() {
cy.task('backendApiPost', {
token: token,
path: '/api/settings',
data: {
name: settingName,
value: {
type: 'custom',
html: '<p>not found</p>'
}
}
}).then((data) => {
// Check the swagger schema:
cy.validateSwaggerSchema('post', 201, '/settings', data);
expect(data.result).to.have.property('id');
expect(data.result.id).to.be.greaterThan(0);
});
});
it('Should be able to get a settting', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/settings/' + settingName
}).then((data) => {
// Check the swagger schema:
cy.validateSwaggerSchema('get', 200, '/settings/{name}', data);
expect(data.result).to.have.property('id');
expect(data.result).to.have.property('name', settingName);
expect(data.result.id).to.be.greaterThan(0);
});
});
it('Should be able to update a settting', function() {
cy.task('backendApiPut', {
token: token,
path: '/api/settings/' + settingName,
data: {
value: true
}
}).then((data) => {
// Check the swagger schema:
cy.validateSwaggerSchema('put', 200, '/settings/{name}', data);
expect(data.result).to.have.property('id');
expect(data.result).to.have.property('name', settingName);
expect(data.result.id).to.be.greaterThan(0);
});
});
it('Should be able to get all settings', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/settings'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/settings', data);
expect(data).to.have.property('result');
expect(data.result).to.have.property('items');
expect(data.result.items.length).to.be.greaterThan(0);
});
});
it('Should be able to get all settings with filters A', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/settings?sort=name&name:starts=e&limit=1'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/settings', data);
expect(data).to.have.property('result');
expect(data.result).to.have.property('items');
expect(data.result.items.length).to.be.greaterThan(0);
});
});
it('Should be able to get all settings with filters B', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/settings?id:in=1,2,3,4,5&limit=1'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/settings', data);
expect(data).to.have.property('result');
expect(data.result).to.have.property('items');
expect(data.result.items.length).to.be.greaterThan(0);
});
});
it('Should be able to get all settings with filters C', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/settings?name:starts=xxxxxxxxxxxxxxx'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/settings', data);
expect(data).to.have.property('result');
expect(data.result).to.have.property('total', 0);
});
});
});

View File

@@ -0,0 +1,29 @@
/// <reference types="Cypress" />
describe('Setup Phase', () => {
before(() => {
cy.task('backendApiDelete', {
path: '/api/users'
}).then((data) => {
expect(data).to.have.property('result', true);
});
});
it('Should not be able to get a token', function() {
cy.task('backendApiPost', {
path: '/api/tokens',
data: {
type: 'password',
identity: 'jc@jc21.com',
secret: 'changeme'
},
returnOnError: true
}).then((data) => {
cy.validateSwaggerSchema('post', 403, '/tokens', data);
expect(data.error).to.have.property('code', 403);
expect(data.error).to.have.property('message', 'Not available during setup phase');
});
});
});

View File

@@ -0,0 +1,9 @@
/// <reference types="Cypress" />
describe('Swagger Schema Checks', () => {
it('Should be valid with swagger-validator', function() {
cy.task('validateSwaggerFile', {
file: Cypress.env('swaggerBase')
}).should('equal', null);
});
});

View File

@@ -1,7 +1,19 @@
/// <reference types="Cypress" />
const generateRandomString = function (length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
};
describe('Users endpoints', () => {
let token;
let uniqueEmail = 'jc_' + generateRandomString(10) + '@example.com';
let myUserID = 0;
before(() => {
cy.getToken().then((tok) => {
@@ -15,8 +27,10 @@ describe('Users endpoints', () => {
path: '/api/users/me'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/users/{userID}', data);
expect(data).to.have.property('id');
expect(data.id).to.be.greaterThan(0);
expect(data).to.have.property('result');
expect(data.result).to.have.property('id');
expect(data.result.id).to.be.greaterThan(0);
myUserID = data.result.id;
});
});
@@ -26,7 +40,91 @@ describe('Users endpoints', () => {
path: '/api/users'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/users', data);
expect(data.length).to.be.greaterThan(0);
expect(data).to.have.property('result');
expect(data.result).to.have.property('items');
expect(data.result.items.length).to.be.greaterThan(0);
});
});
it('Should be able to get all users with filters A', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/users?sort=id.desc&name:starts=J&name:ends=w'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/users', data);
expect(data).to.have.property('result');
expect(data.result).to.have.property('items');
expect(data.result.items.length).to.be.greaterThan(0);
});
});
it('Should be able to get all users with filters B', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/users?sort=id&id:in=1,2,3,4,5'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/users', data);
expect(data).to.have.property('result');
expect(data.result).to.have.property('items');
expect(data.result.items.length).to.be.greaterThan(0);
});
});
it('Should be able to get all users with filters C', function() {
cy.task('backendApiGet', {
token: token,
path: '/api/users?sort=id&name:ends=xxxxxxxxxxxxx'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/users', data);
expect(data).to.have.property('result');
expect(data.result).to.have.property('total', 0);
});
});
it('Should be able to create someone else', function() {
cy.task('backendApiPost', {
token: token,
path: '/api/users',
data: {
name: 'Example user 1',
nickname: 'User1',
email: uniqueEmail,
roles: ['admin'],
is_disabled: false,
auth: {
type: 'password',
secret: 'changeme'
}
}
}).then((data) => {
cy.validateSwaggerSchema('post', 201, '/users', data);
expect(data).to.have.property('result');
expect(data.result).to.have.property('id');
expect(data.result.id).to.be.greaterThan(0);
});
});
it('Should not be able to create duplicate email', function() {
cy.task('backendApiPost', {
token: token,
path: '/api/users',
returnOnError: true,
data: {
name: 'Example user 2',
nickname: 'User2',
email: uniqueEmail,
roles: ['admin'],
is_disabled: false,
auth: {
type: 'password',
secret: 'changeme'
}
}
}).then((data) => {
cy.validateSwaggerSchema('post', 400, '/users', data);
expect(data).to.have.property('result', null);
expect(data).to.have.property('error');
expect(data.error).to.have.property('code', 400);
});
});
@@ -39,9 +137,55 @@ describe('Users endpoints', () => {
}
}).then((data) => {
cy.validateSwaggerSchema('put', 200, '/users/{userID}', data);
expect(data).to.have.property('id');
expect(data.id).to.be.greaterThan(0);
expect(data.name).to.be.equal('changed name');
expect(data).to.have.property('result');
expect(data.result).to.have.property('id');
expect(data.result.id).to.be.greaterThan(0);
expect(data.result.name).to.be.equal('changed name');
});
});
it('Should not be able to update email to another user', function() {
cy.task('backendApiPut', {
token: token,
path: '/api/users/me',
returnOnError: true,
data: {
email: uniqueEmail
}
}).then((data) => {
cy.validateSwaggerSchema('put', 400, '/users/{userID}', data);
expect(data).to.have.property('result', null);
expect(data).to.have.property('error');
expect(data.error).to.have.property('code', 400);
});
});
it('Should not be able to disable yourself', function() {
cy.task('backendApiPut', {
token: token,
path: '/api/users/me',
returnOnError: true,
data: {
is_disabled: true
}
}).then((data) => {
cy.validateSwaggerSchema('put', 400, '/users/{userID}', data);
expect(data).to.have.property('result', null);
expect(data).to.have.property('error');
expect(data.error).to.have.property('code', 400);
});
});
it('Should not be able to delete yourself', function() {
cy.task('backendApiDelete', {
token: token,
path: '/api/users/' + myUserID,
returnOnError: true
}).then((data) => {
cy.validateSwaggerSchema('delete', 400, '/users/{userID}', data);
expect(data).to.have.property('result', null);
expect(data).to.have.property('error');
expect(data.error).to.have.property('code', 400);
});
});