Add egress and ingress worker filters to target model (#1554)
* feat: 🎸 add egress and ingress worker filter to target model ✅ Closes: ICU-7300 * chore: 🤖 update mirage to include ingress/egress worker filter * refactor: 💡 update target mirage config for worker filters * refactor: 💡 update how target id is set in mirage factory * refactor: 💡 update target id and default_port mirage setup * test: 💍 fix missing address attribute in new tests
This commit is contained in:
1 parent
f41631c745
commit
63f619b1ff
4 files changed
+156
-15
No files matched your search
@@ -39,6 +39,18 @@ export default class GeneratedTargetModel extends BaseModel {
|
||||
})
|
||||
worker_filter;
|
||||
|
||||
@attr('string', {
|
||||
description:
|
||||
'Optional boolean expressions to filter the egress workers that are allowed to satisfy this request.',
|
||||
})
|
||||
egress_worker_filter;
|
||||
|
||||
@attr('string', {
|
||||
description:
|
||||
'Optional boolean expressions to filter the ingress workers that are allowed to satisfy this request.',
|
||||
})
|
||||
ingress_worker_filter;
|
||||
|
||||
@attr('date', {
|
||||
description: 'The time this resource was created\nOutput only.',
|
||||
readOnly: true,
|
||||
|
||||
@@ -22,7 +22,6 @@ export default factory.extend({
|
||||
'add-credential-sources',
|
||||
'remove-credential-sources',
|
||||
],
|
||||
|
||||
id: () => generateId('t_'),
|
||||
|
||||
/**
|
||||
@@ -31,17 +30,9 @@ export default factory.extend({
|
||||
session_connection_limit: () =>
|
||||
faker.helpers.arrayElement([-1, faker.datatype.number()]),
|
||||
worker_filter: (i) => (i % 2 === 0 ? faker.random.words() : null),
|
||||
egress_worker_filter: (i) => (i % 2 !== 0 ? faker.random.words() : null),
|
||||
ingress_worker_filter: (i) => (i % 2 !== 0 ? faker.random.words() : null),
|
||||
type: (i) => types[i % types.length],
|
||||
/**
|
||||
* Generates attributes fields by type.
|
||||
*/
|
||||
afterCreate(target) {
|
||||
target.update({
|
||||
attributes: {
|
||||
default_port: faker.datatype.number(),
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Randomly selects existing host sets and credential libraries to assign to target.
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
import { Factory } from 'miragejs';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { TYPE_TARGET_TCP } from 'api/models/target';
|
||||
|
||||
/**
|
||||
* GeneratedTargetModelFactory
|
||||
*/
|
||||
export default Factory.extend({
|
||||
type: TYPE_TARGET_TCP,
|
||||
name: () => faker.random.words(),
|
||||
session_max_seconds: () => faker.datatype.number(),
|
||||
session_connection_limit: () => faker.datatype.number(),
|
||||
worker_filter: () => faker.random.words(),
|
||||
description: () => faker.random.words(),
|
||||
created_time: () => faker.date.recent(),
|
||||
updated_time: () => faker.date.recent(),
|
||||
disabled: () => faker.datatype.boolean(),
|
||||
default_port: () => faker.datatype.number(),
|
||||
version: () => faker.datatype.number(),
|
||||
});
|
||||
@@ -42,6 +42,8 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
session_max_seconds: 28800,
|
||||
session_connection_limit: null,
|
||||
worker_filter: null,
|
||||
egress_worker_filter: null,
|
||||
ingress_worker_filter: null,
|
||||
attributes: {
|
||||
default_port: 1234,
|
||||
},
|
||||
@@ -119,6 +121,7 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
version: 1,
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes the worker_filter attribute if present', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
@@ -145,6 +148,78 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
session_max_seconds: 28800,
|
||||
session_connection_limit: null,
|
||||
worker_filter: 'worker',
|
||||
egress_worker_filter: null,
|
||||
ingress_worker_filter: null,
|
||||
attributes: {
|
||||
default_port: 1234,
|
||||
},
|
||||
address: null,
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes the egress_worker_filter attribute if present', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('target');
|
||||
const record = store.createRecord('target', {
|
||||
name: 'User',
|
||||
description: 'Description',
|
||||
version: 1,
|
||||
type: TYPE_TARGET_SSH,
|
||||
egress_worker_filter: 'egress worker',
|
||||
default_port: 1234,
|
||||
scope: {
|
||||
scope_id: 'org_1',
|
||||
},
|
||||
});
|
||||
const snapshot = record._createSnapshot();
|
||||
const serializedRecord = serializer.serialize(snapshot);
|
||||
assert.deepEqual(serializedRecord, {
|
||||
name: 'User',
|
||||
description: 'Description',
|
||||
version: 1,
|
||||
type: TYPE_TARGET_SSH,
|
||||
scope_id: 'org_1',
|
||||
session_max_seconds: 28800,
|
||||
session_connection_limit: null,
|
||||
worker_filter: null,
|
||||
egress_worker_filter: 'egress worker',
|
||||
ingress_worker_filter: null,
|
||||
attributes: {
|
||||
default_port: 1234,
|
||||
},
|
||||
address: null,
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes the ingress_worker_filter attribute if present', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('target');
|
||||
const record = store.createRecord('target', {
|
||||
name: 'User',
|
||||
description: 'Description',
|
||||
version: 1,
|
||||
type: TYPE_TARGET_SSH,
|
||||
ingress_worker_filter: 'ingress worker',
|
||||
default_port: 1234,
|
||||
scope: {
|
||||
scope_id: 'org_1',
|
||||
},
|
||||
});
|
||||
const snapshot = record._createSnapshot();
|
||||
const serializedRecord = serializer.serialize(snapshot);
|
||||
assert.deepEqual(serializedRecord, {
|
||||
name: 'User',
|
||||
description: 'Description',
|
||||
version: 1,
|
||||
type: TYPE_TARGET_SSH,
|
||||
scope_id: 'org_1',
|
||||
session_max_seconds: 28800,
|
||||
session_connection_limit: null,
|
||||
worker_filter: null,
|
||||
egress_worker_filter: null,
|
||||
ingress_worker_filter: 'ingress worker',
|
||||
attributes: {
|
||||
default_port: 1234,
|
||||
},
|
||||
@@ -292,4 +367,70 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('it normalizes the egress_worker_filter attribute if present', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('target');
|
||||
const target = store.createRecord('target').constructor;
|
||||
const payload = {
|
||||
id: '1',
|
||||
name: 'Target 1',
|
||||
egress_worker_filter: 'egress worker',
|
||||
};
|
||||
const normalized = serializer.normalizeSingleResponse(
|
||||
store,
|
||||
target,
|
||||
payload
|
||||
);
|
||||
assert.deepEqual(normalized, {
|
||||
included: [],
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'target',
|
||||
attributes: {
|
||||
authorized_actions: [],
|
||||
name: 'Target 1',
|
||||
host_sources: [],
|
||||
brokered_credential_source_ids: [],
|
||||
injected_application_credential_source_ids: [],
|
||||
egress_worker_filter: 'egress worker',
|
||||
},
|
||||
relationships: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('it normalizes the ingress_worker_filter attribute if present', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('target');
|
||||
const target = store.createRecord('target').constructor;
|
||||
const payload = {
|
||||
id: '1',
|
||||
name: 'Target 1',
|
||||
ingress_worker_filter: 'ingress worker',
|
||||
};
|
||||
const normalized = serializer.normalizeSingleResponse(
|
||||
store,
|
||||
target,
|
||||
payload
|
||||
);
|
||||
assert.deepEqual(normalized, {
|
||||
included: [],
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'target',
|
||||
attributes: {
|
||||
authorized_actions: [],
|
||||
name: 'Target 1',
|
||||
host_sources: [],
|
||||
brokered_credential_source_ids: [],
|
||||
injected_application_credential_source_ids: [],
|
||||
ingress_worker_filter: 'ingress worker',
|
||||
},
|
||||
relationships: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user