metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmerri...@apache.org
Subject [34/51] [abbrv] metron git commit: METRON-1720 Better error messages when there are no results or wireshark is not installed (merrimanr) closes apache/metron#1154
Date Fri, 17 Aug 2018 15:34:49 GMT
METRON-1720 Better error messages when there are no results or wireshark is not installed (merrimanr)
closes apache/metron#1154


Project: http://git-wip-us.apache.org/repos/asf/metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/afb9607d
Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/afb9607d
Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/afb9607d

Branch: refs/heads/master
Commit: afb9607dfbbaf89f06a30823bf668523bb7b6f9a
Parents: 7967f35
Author: merrimanr <merrimanr@gmail.com>
Authored: Wed Aug 8 14:11:26 2018 -0500
Committer: rmerriman <merrimanr@gmail.com>
Committed: Wed Aug 8 14:11:26 2018 -0500

----------------------------------------------------------------------
 .../pcap-panel/pcap-panel.component.spec.ts     | 64 ++++++++++++++++++++
 .../app/pcap/pcap-panel/pcap-panel.component.ts |  9 ++-
 .../src/app/pcap/service/pcap.service.ts        |  3 +-
 3 files changed, 73 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metron/blob/afb9607d/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.spec.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.spec.ts
b/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.spec.ts
index bd732ad..0804b79 100644
--- a/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.spec.ts
+++ b/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.spec.ts
@@ -26,6 +26,7 @@ import { PcapPagination } from '../model/pcap-pagination';
 import { By } from '../../../../node_modules/@angular/platform-browser';
 import { PcapRequest } from '../model/pcap.request';
 import { defer } from 'rxjs/observable/defer';
+import {RestError} from "../../model/rest-error";
 
 @Component({
   selector: 'app-pcap-filters',
@@ -305,6 +306,7 @@ describe('PcapPanelComponent', () => {
     );
 
     const pollResponse = new PcapStatusResponse();
+    pollResponse.jobStatus = 'SUCCEEDED';
     pcapService.pollStatus = jasmine.createSpy('pollStatus').and.returnValue(
       defer(() => Promise.resolve(pollResponse))
     );
@@ -321,6 +323,68 @@ describe('PcapPanelComponent', () => {
     tick();
     fixture.detectChanges();
 
+    expect(component.pdml).toEqual(myPdml);
     expect(fixture.debugElement.query(By.css('app-pcap-list'))).toBeDefined();
   }));
+
+  it('should handle get packet 404', fakeAsync(() => {
+    const searchResponse = new PcapStatusResponse();
+    searchResponse.jobId = '42';
+
+    pcapService.submitRequest = jasmine.createSpy('submitRequest').and.returnValue(
+            defer(() => Promise.resolve(searchResponse))
+    );
+
+    const pollResponse = new PcapStatusResponse();
+    pollResponse.jobStatus = 'SUCCEEDED';
+    pcapService.pollStatus = jasmine.createSpy('pollStatus').and.returnValue(
+            defer(() => Promise.resolve(pollResponse))
+    );
+
+    const restError = new RestError();
+    restError.responseCode = 404;
+    pcapService.getPackets = jasmine.createSpy('getPackets').and.returnValue(
+            defer(() => Promise.reject(restError))
+    );
+
+    component.onSearch(new PcapRequest());
+
+    expect(component.errorMsg).toBeFalsy();
+
+    tick();
+    fixture.detectChanges();
+
+    expect(component.errorMsg).toEqual('No results returned');
+  }));
+
+  it('should handle get packet error', fakeAsync(() => {
+    const searchResponse = new PcapStatusResponse();
+    searchResponse.jobId = '42';
+
+    pcapService.submitRequest = jasmine.createSpy('submitRequest').and.returnValue(
+            defer(() => Promise.resolve(searchResponse))
+    );
+
+    const pollResponse = new PcapStatusResponse();
+    pollResponse.jobStatus = 'SUCCEEDED';
+    pcapService.pollStatus = jasmine.createSpy('pollStatus').and.returnValue(
+            defer(() => Promise.resolve(pollResponse))
+    );
+
+    const restError = new RestError();
+    restError.responseCode = 500;
+    restError.message = 'error message';
+    pcapService.getPackets = jasmine.createSpy('getPackets').and.returnValue(
+            defer(() => Promise.reject(restError))
+    );
+
+    component.onSearch(new PcapRequest());
+
+    expect(component.errorMsg).toBeFalsy();
+
+    tick();
+    fixture.detectChanges();
+
+    expect(component.errorMsg).toEqual('Response message: error message. Something went wrong
retrieving pdml results!');
+  }));
 });

http://git-wip-us.apache.org/repos/asf/metron/blob/afb9607d/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.ts
b/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.ts
index 82121d4..8e4ced0 100644
--- a/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.ts
+++ b/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.ts
@@ -23,6 +23,7 @@ import { PcapRequest } from '../model/pcap.request';
 import { Pdml } from '../model/pdml';
 import { Subscription } from 'rxjs/Rx';
 import { PcapPagination } from '../model/pcap-pagination';
+import {RestError} from "../../model/rest-error";
 
 @Component({
   selector: 'app-pcap-panel',
@@ -72,8 +73,14 @@ export class PcapPanelComponent {
             this.pagination.total = statusResponse.pageTotal;
             this.statusSubscription.unsubscribe();
             this.queryRunning = false;
-            this.pcapService.getPackets(submitResponse.jobId, this.pagination.selectedPage).toPromise().then(pdml
=> {
+            this.pcapService.getPackets(id, this.pagination.selectedPage).toPromise().then(pdml
=> {
               this.pdml = pdml;
+            }, (error: RestError) => {
+              if (error.responseCode === 404) {
+                this.errorMsg = 'No results returned';
+              } else {
+                this.errorMsg = `Response message: ${error.message}. Something went wrong
retrieving pdml results!`;
+              }
             });
           } else if ('FAILED' === statusResponse.jobStatus) {
             this.statusSubscription.unsubscribe();

http://git-wip-us.apache.org/repos/asf/metron/blob/afb9607d/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.ts b/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.ts
index 6418ad0..518cc92 100644
--- a/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.ts
+++ b/metron-interface/metron-alerts/src/app/pcap/service/pcap.service.ts
@@ -56,8 +56,7 @@ export class PcapService {
     public getPackets(id: string, pageId: number): Observable<Pdml> {
         return this.http.get(`/api/v1/pcap/${id}/pdml?page=${pageId}`, new RequestOptions({headers:
new Headers(this.defaultHeaders)}))
             .map(HttpUtil.extractData)
-            .catch(HttpUtil.handleError)
-            .onErrorResumeNext();
+            .catch(HttpUtil.handleError);
     }
 
     public getDownloadUrl(id: string, pageId: number) {


Mime
View raw message