fix: 🐛 remove session recording fields from tcp target (#317)
* fix: 🐛 remove session recording fields from tcp target
This commit is contained in:
1 parent
1409ec9fa5
commit
857e455caa
3 files changed
+59
-11
No files matched your search
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import ApplicationSerializer from './application';
|
||||
import { TYPE_TARGET_SSH } from '../models/target';
|
||||
|
||||
export default class TargetSerializer extends ApplicationSerializer {
|
||||
// =methods
|
||||
@@ -22,6 +23,7 @@ export default class TargetSerializer extends ApplicationSerializer {
|
||||
*/
|
||||
serialize(snapshot) {
|
||||
let serialized = super.serialize(...arguments);
|
||||
const { type } = snapshot.record;
|
||||
const hostSourceIDs = snapshot?.adapterOptions?.hostSetIDs;
|
||||
if (hostSourceIDs) {
|
||||
serialized = this.serializeWithHostSources(snapshot, hostSourceIDs);
|
||||
@@ -42,15 +44,11 @@ export default class TargetSerializer extends ApplicationSerializer {
|
||||
injectedApplicationCredentialSourceIDs
|
||||
);
|
||||
|
||||
if (snapshot?.adapterOptions?.method === 'set-storage-bucket') {
|
||||
serialized = this.serializeWithStorageBucket(snapshot);
|
||||
// Delete session recording related fields from non-SSH targets
|
||||
if (type !== TYPE_TARGET_SSH) {
|
||||
delete serialized?.attributes?.storage_bucket_id;
|
||||
delete serialized?.attributes?.enable_session_recording;
|
||||
}
|
||||
if (snapshot?.adapterOptions?.method === 'remove-storage-bucket') {
|
||||
return {
|
||||
version: snapshot.attr('version'),
|
||||
};
|
||||
}
|
||||
|
||||
return serialized;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ export default factory.extend({
|
||||
'remove-host-sources',
|
||||
'add-credential-sources',
|
||||
'remove-credential-sources',
|
||||
'set-storage-bucket',
|
||||
'remove-storage-bucket',
|
||||
],
|
||||
id: () => generateId('t_'),
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { TYPE_TARGET_TCP, TYPE_TARGET_SSH } from 'api/models/target';
|
||||
module('Unit | Serializer | target', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it serializes targets normally, without host sets or credential libraries', function (assert) {
|
||||
test('it serializes TCP targets normally, without host sets or credential libraries or session recording fields in the attributes', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('target');
|
||||
@@ -35,6 +35,8 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
version: 1,
|
||||
type: TYPE_TARGET_TCP,
|
||||
address: '0.0.0.0',
|
||||
enable_session_recording: false,
|
||||
storage_bucket_id: null,
|
||||
});
|
||||
const snapshot = record._createSnapshot();
|
||||
snapshot.adapterOptions = {};
|
||||
@@ -50,6 +52,56 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
worker_filter: null,
|
||||
egress_worker_filter: null,
|
||||
ingress_worker_filter: null,
|
||||
attributes: {
|
||||
default_port: 1234,
|
||||
default_client_port: 4321,
|
||||
},
|
||||
address: '0.0.0.0',
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes SSH targets normally with session recording fields in the attributes but without host sets or credential libraries', 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',
|
||||
host_sources: [
|
||||
{ host_source_id: '1', host_catalog_id: '2' },
|
||||
{ host_source_id: '3', host_catalog_id: '4' },
|
||||
],
|
||||
brokered_credential_source_ids: [{ value: '1' }, { value: '2' }],
|
||||
injected_application_credential_source_ids: [
|
||||
{ value: '4' },
|
||||
{ value: '5' },
|
||||
],
|
||||
scope: {
|
||||
scope_id: 'org_1',
|
||||
type: 'org',
|
||||
},
|
||||
default_port: 1234,
|
||||
default_client_port: 4321,
|
||||
version: 1,
|
||||
type: TYPE_TARGET_SSH,
|
||||
enable_session_recording: false,
|
||||
storage_bucket_id: null,
|
||||
address: '0.0.0.0',
|
||||
});
|
||||
const snapshot = record._createSnapshot();
|
||||
snapshot.adapterOptions = {};
|
||||
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: null,
|
||||
attributes: {
|
||||
default_port: 1234,
|
||||
default_client_port: 4321,
|
||||
|
||||
Reference in new issue
Block a user