From 857e455caa3cf3910b74d5f64df67cbad0dc5dae Mon Sep 17 00:00:00 2001 From: Dharini Jeeva Date: Fri, 2 Jun 2023 16:03:17 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20remove=20session=20record?= =?UTF-8?q?ing=20fields=20from=20tcp=20target=20(#317)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 remove session recording fields from tcp target --- addons/api/addon/serializers/target.js | 14 +++-- addons/api/mirage/factories/target.js | 2 - .../api/tests/unit/serializers/target-test.js | 54 ++++++++++++++++++- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/addons/api/addon/serializers/target.js b/addons/api/addon/serializers/target.js index 25a952cfc..00a50005a 100644 --- a/addons/api/addon/serializers/target.js +++ b/addons/api/addon/serializers/target.js @@ -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; } diff --git a/addons/api/mirage/factories/target.js b/addons/api/mirage/factories/target.js index f09fdeb8c..3d8ecb950 100644 --- a/addons/api/mirage/factories/target.js +++ b/addons/api/mirage/factories/target.js @@ -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_'), diff --git a/addons/api/tests/unit/serializers/target-test.js b/addons/api/tests/unit/serializers/target-test.js index 6b1fe308d..27894ee88 100644 --- a/addons/api/tests/unit/serializers/target-test.js +++ b/addons/api/tests/unit/serializers/target-test.js @@ -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,