metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sard...@apache.org
Subject [metron] branch master updated: METRON-1999 Adding validation against special characters to parser name field (tiborm via sardell) closes apache/metron#1337
Date Thu, 14 Feb 2019 16:03:01 GMT
This is an automated email from the ASF dual-hosted git repository.

sardell pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/metron.git


The following commit(s) were added to refs/heads/master by this push:
     new b89f066  METRON-1999 Adding validation against special characters to parser name
field (tiborm via sardell) closes apache/metron#1337
b89f066 is described below

commit b89f066663b651d11abdf302da034d863559ce4e
Author: tiborm <tibor.meller@gmail.com>
AuthorDate: Thu Feb 14 17:02:40 2019 +0100

    METRON-1999 Adding validation against special characters to parser name field (tiborm
via sardell) closes apache/metron#1337
---
 .../sensor-parser-config.component.html            |  3 +-
 .../sensor-parser-config.component.spec.ts         | 94 ++++++++++------------
 .../sensor-parser-config.component.ts              |  7 +-
 3 files changed, 51 insertions(+), 53 deletions(-)

diff --git a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.html
b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.html
index 22c4289..c9895c7 100644
--- a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.html
+++ b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.html
@@ -48,7 +48,8 @@
                 <div class="form-group">
                     <label attr.for="sensorName">NAME * </label>
                     <input type="text" class="form-control" name="sensorName" formControlName="sensorName"
 [(ngModel)]="sensorName" (ngModelChange)="onSetSensorName()" [readonly]="editMode">
-                    <div *ngIf="!sensorNameUnique"><label ><span class="warning-text">
Sensor already exists </span></label></div>
+                    <div *ngIf="!sensorNameUnique"><label><span class="warning-text">
Sensor already exists </span></label></div>
+                    <div *ngIf="!sensorNameNoSpecChars"><label><span class="warning-text">
Sensor name contains special characters </span></label></div>
                 </div>
 
                 <div class="form-group">
diff --git a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.spec.ts
b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.spec.ts
index 09809a2..4be0703 100644
--- a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.spec.ts
+++ b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.spec.ts
@@ -554,10 +554,12 @@ describe('Component: SensorParserConfig', () => {
     router = TestBed.get(Router);
   }));
 
+  afterEach(() => {
+    fixture.destroy();
+  })
+
   it('should create an instance of SensorParserConfigComponent', async(() => {
     expect(component).toBeDefined();
-
-    fixture.destroy();
   }));
 
   it('should handle ngOnInit', async(() => {
@@ -572,8 +574,6 @@ describe('Component: SensorParserConfig', () => {
     expect(component.init).toHaveBeenCalledWith('squid');
     expect(component.createForms).toHaveBeenCalled();
     expect(component.getAvailableParsers).toHaveBeenCalled();
-
-    fixture.destroy();
   }));
 
   it('should createForms', async(() => {
@@ -593,8 +593,6 @@ describe('Component: SensorParserConfig', () => {
     component.showAdvancedParserConfiguration = false;
     component.createForms();
     expect(component.showAdvancedParserConfiguration).toEqual(false);
-
-    fixture.destroy();
   }));
 
   it('should getAvailableParsers', async(() => {
@@ -604,8 +602,6 @@ describe('Component: SensorParserConfig', () => {
       Grok: 'org.apache.metron.parsers.GrokParser'
     });
     expect(component.availableParserNames).toEqual(['Bro', 'Grok']);
-
-    fixture.destroy();
   }));
 
   it('should init', async(() => {
@@ -706,8 +702,6 @@ describe('Component: SensorParserConfig', () => {
 
     component.init('bro');
     expect(component.showAdvancedParserConfiguration).toEqual(false);
-
-    fixture.destroy();
   }));
 
   it('should getMessagePrefix', async(() => {
@@ -715,8 +709,6 @@ describe('Component: SensorParserConfig', () => {
     expect(component.getMessagePrefix()).toEqual('Created');
     component.editMode = true;
     expect(component.getMessagePrefix()).toEqual('Modified');
-
-    fixture.destroy();
   }));
 
   it('should handle onSetKafkaTopic', async(() => {
@@ -731,8 +723,6 @@ describe('Component: SensorParserConfig', () => {
     component.onSetKafkaTopic();
     expect(component.kafkaTopicValid).toEqual(true);
     expect(component.getKafkaStatus).toHaveBeenCalled();
-
-    fixture.destroy();
   }));
 
   it('should handle onSetSensorName', async(() => {
@@ -752,10 +742,47 @@ describe('Component: SensorParserConfig', () => {
     component.onSetSensorName();
     expect(component.sensorNameUnique).toEqual(true);
     expect(component.sensorNameValid).toEqual(true);
-
-    fixture.destroy();
   }));
 
+  it('sensor name should be validated agains special characters', () => {
+    component.sensorName = 'squidWithSpecChar@';
+    component.onSetSensorName();
+    expect(component.sensorNameNoSpecChars).toEqual(false);
+    expect(component.sensorNameValid).toEqual(false);
+
+    component.sensorName = 'squidWithSpecChar#';
+    component.onSetSensorName();
+    expect(component.sensorNameNoSpecChars).toEqual(false);
+    expect(component.sensorNameValid).toEqual(false);
+
+    component.sensorName = 'squidWithSpecChar/';
+    component.onSetSensorName();
+    expect(component.sensorNameNoSpecChars).toEqual(false);
+    expect(component.sensorNameValid).toEqual(false);
+
+    component.sensorName = 'squidWithSpecChar?';
+    component.onSetSensorName();
+    expect(component.sensorNameNoSpecChars).toEqual(false);
+    expect(component.sensorNameValid).toEqual(false);
+
+    component.sensorName = 'squidWithSpecChar?$&%';
+    component.onSetSensorName();
+    expect(component.sensorNameNoSpecChars).toEqual(false);
+    expect(component.sensorNameValid).toEqual(false);
+  });
+
+  it('sensor name validation should accept dash and lowdash chars', () => {
+    component.sensorName = 'squidWithSpecChar-';
+    component.onSetSensorName();
+    expect(component.sensorNameNoSpecChars).toEqual(true);
+    expect(component.sensorNameValid).toEqual(true);
+
+    component.sensorName = 'squidWithSpecChar_';
+    component.onSetSensorName();
+    expect(component.sensorNameNoSpecChars).toEqual(true);
+    expect(component.sensorNameValid).toEqual(true);
+  })
+
   it('should handle onParserTypeChange', async(() => {
     spyOn(component, 'hidePane');
     spyOn(component, 'isConfigValid');
@@ -774,8 +801,6 @@ describe('Component: SensorParserConfig', () => {
       'org.apache.metron.parsers.bro.BasicBroParser';
     component.onParserTypeChange();
     expect(component.hidePane).toHaveBeenCalledWith(Pane.GROK);
-
-    fixture.destroy();
   }));
 
   it('should handle onGrokStatementChange', async(() => {
@@ -788,8 +813,6 @@ describe('Component: SensorParserConfig', () => {
     component.grokStatement = 'grok statement';
     component.onGrokStatementChange();
     expect(component.grokStatementValid).toEqual(true);
-
-    fixture.destroy();
   }));
 
   it('should handle isConfigValid', async(() => {
@@ -811,8 +834,6 @@ describe('Component: SensorParserConfig', () => {
     component.grokStatementValid = true;
     component.isConfigValid();
     expect(component.configValid).toEqual(true);
-
-    fixture.destroy();
   }));
 
   it('should getKafkaStatus', async(() => {
@@ -834,8 +855,6 @@ describe('Component: SensorParserConfig', () => {
     kafkaService.setSampleData('squid', 'message');
     component.getKafkaStatus();
     expect(component.currentKafkaStatus).toEqual(KafkaStatus.EMITTING);
-
-    fixture.destroy();
   }));
 
   it('should getTransforms', async(() => {
@@ -849,8 +868,6 @@ describe('Component: SensorParserConfig', () => {
     );
 
     expect(component.getTransforms()).toEqual('3 Transformations Applied');
-
-    fixture.destroy();
   }));
 
   it('should handle onSaveGrokStatement', async(() => {
@@ -873,8 +890,6 @@ describe('Component: SensorParserConfig', () => {
     expect(component.sensorParserConfig.parserConfig['grokPath']).toEqual(
       '/custom/grok/path'
     );
-
-    fixture.destroy();
   }));
 
   it('should onSavePatternLabel', async(() => {
@@ -883,8 +898,6 @@ describe('Component: SensorParserConfig', () => {
     expect(component.sensorParserConfig.parserConfig['patternLabel']).toEqual(
       'PATTERN_LABEL'
     );
-
-    fixture.destroy();
   }));
 
   it('should goBack', async(() => {
@@ -893,8 +906,6 @@ describe('Component: SensorParserConfig', () => {
     router.navigateByUrl = jasmine.createSpy('navigateByUrl');
     component.goBack();
     expect(router.navigateByUrl).toHaveBeenCalledWith('/sensors');
-
-    fixture.destroy();
   }));
 
   it('should save sensor configuration', async(() => {
@@ -980,8 +991,6 @@ describe('Component: SensorParserConfig', () => {
     expect(metronAlerts.showErrorMessage['calls'].mostRecent().args[0]).toEqual(
       'Created Sensor parser config but unable to save indexing configuration: IndexingConfigurations
post error'
     );
-
-    fixture.destroy();
   }));
 
   it('should getTransformationCount', async(() => {
@@ -1015,7 +1024,6 @@ describe('Component: SensorParserConfig', () => {
       transforms[0]
     ];
     expect(component.getTransformationCount()).toEqual(0);
-    fixture.destroy();
   }));
 
   it('should getEnrichmentCount', async(() => {
@@ -1028,8 +1036,6 @@ describe('Component: SensorParserConfig', () => {
     ] = ['ip_src_addr', 'ip_dst_addr'];
 
     expect(component.getEnrichmentCount()).toEqual(4);
-
-    fixture.destroy();
   }));
 
   it('should getThreatIntelCount', async(() => {
@@ -1038,8 +1044,6 @@ describe('Component: SensorParserConfig', () => {
     ] = ['ip_src_addr', 'ip_dst_addr'];
 
     expect(component.getThreatIntelCount()).toEqual(2);
-
-    fixture.destroy();
   }));
 
   it('should getRuleCount', async(() => {
@@ -1061,8 +1065,6 @@ describe('Component: SensorParserConfig', () => {
     );
 
     expect(component.getRuleCount()).toEqual(2);
-
-    fixture.destroy();
   }));
 
   it('should showPane', async(() => {
@@ -1080,8 +1082,6 @@ describe('Component: SensorParserConfig', () => {
     expect(component.showGrokValidator).toEqual(false);
     expect(component.showFieldSchema).toEqual(false);
     expect(component.showRawJson).toEqual(true);
-
-    fixture.destroy();
   }));
 
   it('should hidePane', async(() => {
@@ -1099,8 +1099,6 @@ describe('Component: SensorParserConfig', () => {
     expect(component.showGrokValidator).toEqual(false);
     expect(component.showFieldSchema).toEqual(false);
     expect(component.showRawJson).toEqual(false);
-
-    fixture.destroy();
   }));
 
   it('should handle onShowGrokPane', async(() => {
@@ -1115,8 +1113,6 @@ describe('Component: SensorParserConfig', () => {
 
     component.onShowGrokPane();
     expect(component.patternLabel).toEqual('PATTERN_LABEL');
-
-    fixture.destroy();
   }));
 
   it('should handle onRawJsonChanged', async(() => {
@@ -1127,15 +1123,11 @@ describe('Component: SensorParserConfig', () => {
     expect(
       component.sensorFieldSchema.createFieldSchemaRows
     ).toHaveBeenCalled();
-
-    fixture.destroy();
   }));
 
   it('should handle onAdvancedConfigFormClose', async(() => {
     component.onAdvancedConfigFormClose();
 
     expect(component.showAdvancedParserConfiguration).toEqual(false);
-
-    fixture.destroy();
   }));
 });
diff --git a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts
b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts
index 1ba297c..efd08d0 100644
--- a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts
+++ b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts
@@ -72,6 +72,7 @@ export class SensorParserConfigComponent implements OnInit {
   configValid = false;
   sensorNameValid = false;
   sensorNameUnique = true;
+  sensorNameNoSpecChars = false;
   kafkaTopicValid = false;
   parserClassValid = false;
   grokStatementValid = false;
@@ -296,10 +297,14 @@ export class SensorParserConfigComponent implements OnInit {
 
   onSetSensorName(): void {
     this.sensorNameUnique = this.currentSensors.indexOf(this.sensorName) === -1;
+    this.sensorNameNoSpecChars = !/[^a-zA-Z0-9_-]/.test(this.sensorName);
+
     this.sensorNameValid =
       this.sensorName !== undefined &&
       this.sensorName.length > 0 &&
-      this.sensorNameUnique;
+      this.sensorNameUnique &&
+      this.sensorNameNoSpecChars;
+
     this.isConfigValid();
   }
 


Mime
View raw message