2016-11-21 23:22:14 +03:00
|
|
|
import expect from 'expect';
|
2016-12-23 21:40:16 +03:00
|
|
|
import { omit } from 'lodash';
|
2016-11-21 23:22:14 +03:00
|
|
|
|
2016-12-23 21:40:16 +03:00
|
|
|
import { configStub } from 'test/stubs';
|
2016-11-21 23:22:14 +03:00
|
|
|
import helpers from 'kolide/helpers';
|
|
|
|
|
2016-12-21 20:07:13 +03:00
|
|
|
const label1 = { id: 1, target_type: 'labels' };
|
|
|
|
const label2 = { id: 2, target_type: 'labels' };
|
|
|
|
const host1 = { id: 6, target_type: 'hosts' };
|
|
|
|
const host2 = { id: 5, target_type: 'hosts' };
|
|
|
|
|
2016-11-21 23:22:14 +03:00
|
|
|
describe('Kolide API - helpers', () => {
|
2016-12-12 19:48:50 +03:00
|
|
|
describe('#labelSlug', () => {
|
|
|
|
it('creates a slug for the label', () => {
|
|
|
|
expect(helpers.labelSlug({ display_text: 'All Hosts' })).toEqual('all-hosts');
|
|
|
|
expect(helpers.labelSlug({ display_text: 'windows' })).toEqual('windows');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-12-23 21:40:16 +03:00
|
|
|
describe('#formatConfigDataForServer', () => {
|
|
|
|
const { formatConfigDataForServer } = helpers;
|
|
|
|
const config = {
|
|
|
|
org_name: 'Kolide',
|
|
|
|
org_logo_url: '0.0.0.0:8080/logo.png',
|
|
|
|
kolide_server_url: '',
|
|
|
|
configured: false,
|
|
|
|
sender_address: '',
|
|
|
|
server: '',
|
|
|
|
port: 587,
|
|
|
|
authentication_type: 'authtype_username_password',
|
|
|
|
user_name: '',
|
|
|
|
password: '',
|
|
|
|
enable_ssl_tls: true,
|
|
|
|
authentication_method: 'authmethod_plain',
|
|
|
|
verify_ssl_certs: true,
|
|
|
|
enable_start_tls: true,
|
|
|
|
email_enabled: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
it('splits config into categories for the server', () => {
|
|
|
|
expect(formatConfigDataForServer(config)).toEqual(omit(configStub, ['smtp_settings.configured']));
|
2017-01-18 01:45:07 +03:00
|
|
|
expect(formatConfigDataForServer({ org_name: 'The Gnar Co' })).toEqual({
|
|
|
|
org_info: { org_name: 'The Gnar Co' },
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
formatConfigDataForServer({ org_name: 'The Gnar Co', kolide_server_url: 'https://example.com' })
|
|
|
|
).toEqual({
|
|
|
|
org_info: { org_name: 'The Gnar Co' },
|
|
|
|
server_settings: { kolide_server_url: 'https://example.com' },
|
|
|
|
});
|
2016-12-23 21:40:16 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-12-21 20:07:13 +03:00
|
|
|
describe('#formatSelectedTargetsForApi', () => {
|
|
|
|
const { formatSelectedTargetsForApi } = helpers;
|
|
|
|
|
|
|
|
it('splits targets into labels and hosts', () => {
|
|
|
|
const targets = [host1, host2, label1, label2];
|
|
|
|
|
|
|
|
expect(formatSelectedTargetsForApi(targets)).toEqual({
|
|
|
|
hosts: [6, 5],
|
|
|
|
labels: [1, 2],
|
|
|
|
});
|
|
|
|
});
|
2017-01-11 20:10:14 +03:00
|
|
|
|
|
|
|
it('appends `_id` when appendID is specified', () => {
|
|
|
|
const targets = [host1, host2, label1, label2];
|
|
|
|
|
|
|
|
expect(formatSelectedTargetsForApi(targets, true)).toEqual({
|
|
|
|
host_ids: [6, 5],
|
|
|
|
label_ids: [1, 2],
|
|
|
|
});
|
|
|
|
});
|
2016-12-21 20:07:13 +03:00
|
|
|
});
|
|
|
|
|
2016-11-21 23:22:14 +03:00
|
|
|
describe('#setupData', () => {
|
|
|
|
const formData = {
|
|
|
|
email: 'hi@gnar.dog',
|
|
|
|
name: 'Gnar Dog',
|
|
|
|
kolide_server_url: 'https://gnar.kolide.co',
|
|
|
|
org_logo_url: 'https://thegnar.co/assets/logo.png',
|
|
|
|
org_name: 'The Gnar Co.',
|
|
|
|
password: 'p@ssw0rd',
|
|
|
|
password_confirmation: 'p@ssw0rd',
|
|
|
|
username: 'gnardog',
|
|
|
|
};
|
|
|
|
|
|
|
|
it('formats the form data to send to the server', () => {
|
|
|
|
expect(helpers.setupData(formData)).toEqual({
|
|
|
|
kolide_server_url: 'https://gnar.kolide.co',
|
|
|
|
org_info: {
|
|
|
|
org_logo_url: 'https://thegnar.co/assets/logo.png',
|
|
|
|
org_name: 'The Gnar Co.',
|
|
|
|
},
|
|
|
|
admin: {
|
|
|
|
admin: true,
|
|
|
|
email: 'hi@gnar.dog',
|
|
|
|
name: 'Gnar Dog',
|
|
|
|
password: 'p@ssw0rd',
|
|
|
|
password_confirmation: 'p@ssw0rd',
|
|
|
|
username: 'gnardog',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|