From 810bd77f0dcf7c97fb44b8f8fa4611840e578fa5 Mon Sep 17 00:00:00 2001 From: Charissa Miller <48832936+clemiller@users.noreply.github.com> Date: Fri, 2 Feb 2024 22:08:30 -0500 Subject: [PATCH] few more updates --- .../src/app/services/config.service.spec.ts | 104 +---- nav-app/src/app/services/data.service.spec.ts | 1 - nav-app/src/app/tabs/tabs.component.spec.ts | 376 ++---------------- nav-app/src/tests/utils/mock-data.ts | 38 ++ 4 files changed, 95 insertions(+), 424 deletions(-) diff --git a/nav-app/src/app/services/config.service.spec.ts b/nav-app/src/app/services/config.service.spec.ts index 5eea8abd9..448b39c91 100644 --- a/nav-app/src/app/services/config.service.spec.ts +++ b/nav-app/src/app/services/config.service.spec.ts @@ -3,33 +3,9 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ConfigService } from './config.service'; import { DataService } from './data.service'; import { Subscription, of } from 'rxjs'; +import * as MockData from '../../tests/utils/mock-data'; describe('ConfigService', () => { - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/enterprise-attack/enterprise-attack.json"] - } - ] - }, - { - "name": "ATT&CK v12", - "version": "12", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v12.1/enterprise-attack/enterprise-attack.json"] - } - ] - } - ] - let config = { "banner":"", "comment_color":"yellow", @@ -47,7 +23,7 @@ describe('ConfigService', () => { "link_color": "blue", "metadata_color":"purple", "versions": [{"name": 'ATT&CK v13', "version": '13', "domains": ["Enterprise"]}] - } + } beforeEach(() => { TestBed.configureTestingModule({ @@ -61,7 +37,7 @@ describe('ConfigService', () => { })); it('should set up data in constructor', inject([ConfigService], (service: ConfigService) => { - service.dataService.setUpURLs(versions); + service.dataService.setUpURLs(MockData.configDataExtended); spyOn(DataService.prototype, 'getConfig').and.returnValue(of(config)); let fragments = new Map(); fragments.set("comments", "false"); //'https://mitre-attack.github.io/attack-navigator/#comments=false' @@ -74,12 +50,7 @@ describe('ConfigService', () => { })); it('should set feature object', inject([ConfigService], (service: ConfigService) => { - let feature_object = {"name": "technique_controls", "enabled": true, "description": "Disable to disable all subfeatures", "subfeatures": [ - {"name": "disable_techniques", "enabled": true, "description": "Disable to remove the ability to disable techniques."}, - {"name": "manual_color", "enabled": true, "description": "Disable to remove the ability to assign manual colors to techniques."}, - {"name": "background_color", "enabled": true, "description": "Disable to remove the background color effect on manually assigned colors."} - ]} - expect(service.setFeature_object(feature_object)).toEqual([ 'disable_techniques', 'manual_color', 'background_color' ]); + expect(service.setFeature_object(MockData.configTechniqueControls)).toEqual([ 'disable_techniques', 'manual_color', 'background_color' ]); })); it('should set single feature to given value', inject([ConfigService], (service: ConfigService) => { @@ -87,96 +58,53 @@ describe('ConfigService', () => { })); it('should get feature', inject([ConfigService], (service: ConfigService) => { - service.setFeature("sticky_toolbar", true) + service.setFeature("sticky_toolbar", true); expect(service.getFeature("sticky_toolbar")).toBeTruthy(); })); it('should get feature group', inject([ConfigService], (service: ConfigService) => { expect(service.getFeatureGroup("technique_controls")).toBeTruthy(); - let feature_object = {"name": "technique_controls", "enabled": true, "description": "Disable to disable all subfeatures", "subfeatures": [ - {"name": "disable_techniques", "enabled": true, "description": "Disable to remove the ability to disable techniques."}, - {"name": "manual_color", "enabled": true, "description": "Disable to remove the ability to assign manual colors to techniques."}, - {"name": "background_color", "enabled": true, "description": "Disable to remove the background color effect on manually assigned colors."} - ]} - service.setFeature_object(feature_object) + service.setFeature_object(MockData.configTechniqueControls); expect(service.getFeatureGroup("technique_controls")).toBeTruthy(); })); it('should get feature group count', inject([ConfigService], (service: ConfigService) => { expect(service.getFeatureGroupCount("technique_controls")).toEqual(-1); - let feature_object = {"name": "technique_controls", "enabled": true, "description": "Disable to disable all subfeatures", "subfeatures": [ - {"name": "disable_techniques", "enabled": true, "description": "Disable to remove the ability to disable techniques."}, - {"name": "manual_color", "enabled": true, "description": "Disable to remove the ability to assign manual colors to techniques."}, - {"name": "background_color", "enabled": true, "description": "Disable to remove the background color effect on manually assigned colors."} - ]} - service.setFeature_object(feature_object) + service.setFeature_object(MockData.configTechniqueControls); expect(service.getFeatureGroupCount("technique_controls")).toEqual(3); })); it('should get all features', inject([ConfigService], (service: ConfigService) => { - let feature_group_one = {"name": "technique_controls", "enabled": true, "description": "Disable to disable all subfeatures", "subfeatures": [ - {"name": "disable_techniques", "enabled": true, "description": "Disable to remove the ability to disable techniques."}, - {"name": "manual_color", "enabled": false, "description": "Disable to remove the ability to assign manual colors to techniques."}, - {"name": "background_color", "enabled": true, "description": "Disable to remove the background color effect on manually assigned colors."} - ]} - service.setFeature_object(feature_group_one) - let feature_group_two = {"name": "toolbar_controls", "enabled": true, "description": "Disable to disable all subfeatures", "subfeatures": [ - {"name": "sticky_toolbar", "enabled": true, "description": "Disable to remove the ability to enable/disable the sticky toolbar."} - ]} - service.setFeature_object(feature_group_two) + service.setFeature_object(MockData.configTechniqueControls); + service.setFeature_object(MockData.configToolbarControls); expect(service.getFeatures()).toEqual([ 'disable_techniques', 'manual_color', 'background_color', 'sticky_toolbar' ] ); })); it('should get all feature groups', inject([ConfigService], (service: ConfigService) => { - let feature_group_one = {"name": "technique_controls", "enabled": true, "description": "Disable to disable all subfeatures", "subfeatures": [ - {"name": "disable_techniques", "enabled": true, "description": "Disable to remove the ability to disable techniques."}, - {"name": "manual_color", "enabled": false, "description": "Disable to remove the ability to assign manual colors to techniques."}, - {"name": "background_color", "enabled": true, "description": "Disable to remove the background color effect on manually assigned colors."} - ]} - service.setFeature_object(feature_group_one) - let feature_group_two = {"name": "toolbar_controls", "enabled": true, "description": "Disable to disable all subfeatures", "subfeatures": [ - {"name": "sticky_toolbar", "enabled": true, "description": "Disable to remove the ability to enable/disable the sticky toolbar."} - ]} - service.setFeature_object(feature_group_two) + service.setFeature_object(MockData.configTechniqueControls); + service.setFeature_object(MockData.configToolbarControls); expect(service.getFeatureGroups()).toEqual(["technique_controls", "toolbar_controls"] ); })); it('should check if feature exists', inject([ConfigService], (service: ConfigService) => { - let feature_group_one = {"name": "technique_controls", "enabled": true, "description": "Disable to disable all subfeatures", "subfeatures": [ - {"name": "disable_techniques", "enabled": true, "description": "Disable to remove the ability to disable techniques."}, - {"name": "manual_color", "enabled": false, "description": "Disable to remove the ability to assign manual colors to techniques."}, - {"name": "background_color", "enabled": true, "description": "Disable to remove the background color effect on manually assigned colors."} - ]} - service.setFeature_object(feature_group_one) + service.setFeature_object(MockData.configTechniqueControls) expect(service.isFeature('disable_techniques')).toBeTruthy(); })); it('should check if feature group exists', inject([ConfigService], (service: ConfigService) => { - let feature_group_one = {"name": "technique_controls", "enabled": true, "description": "Disable to disable all subfeatures", "subfeatures": [ - {"name": "disable_techniques", "enabled": true, "description": "Disable to remove the ability to disable techniques."}, - {"name": "manual_color", "enabled": false, "description": "Disable to remove the ability to assign manual colors to techniques."}, - {"name": "background_color", "enabled": true, "description": "Disable to remove the background color effect on manually assigned colors."} - ]} - service.setFeature_object(feature_group_one) + service.setFeature_object(MockData.configTechniqueControls) expect(service.isFeatureGroup("technique_controls")).toBeTruthy(); })); it('should get feature list', inject([ConfigService], (service: ConfigService) => { expect(service.getFeatureList()).toEqual([]); - service.featureStructure = [ - {"name": "sticky_toolbar", "enabled": true} - ] + service.featureStructure = [{"name": "sticky_toolbar", "enabled": true}] expect(service.getFeatureList()).toEqual([{"name": "sticky_toolbar", "enabled": true}]); })); it('should set features of the given group to provided value', inject([ConfigService], (service: ConfigService) => { - let feature_object = {"name": "technique_controls", "enabled": true, "description": "Disable to disable all subfeatures", "subfeatures": [ - {"name": "disable_techniques", "enabled": false, "description": "Disable to remove the ability to disable techniques."}, - {"name": "manual_color", "enabled": true, "description": "Disable to remove the ability to assign manual colors to techniques."}, - {"name": "background_color", "enabled": true, "description": "Disable to remove the background color effect on manually assigned colors."} - ]} - service.setFeature_object(feature_object) - expect(service.setFeature("technique_controls",true)).toEqual(["technique_controls"]); + service.setFeature_object(MockData.configTechniqueControls); + expect(service.setFeature("technique_controls", true)).toEqual(["technique_controls"]); })); it('should set features of the given group to the value object', inject([ConfigService], (service: ConfigService) => { diff --git a/nav-app/src/app/services/data.service.spec.ts b/nav-app/src/app/services/data.service.spec.ts index dcb782215..360ce2d10 100755 --- a/nav-app/src/app/services/data.service.spec.ts +++ b/nav-app/src/app/services/data.service.spec.ts @@ -281,7 +281,6 @@ describe('DataService', () => { service.domains[0].relationships['targeted_assets'].set('asset-0',['attack-pattern-0']); let domain = service.domains[0]; service.parseBundle(domain, MockData.stixBundleSDO); - console.log('domain', domain) // check data loaded expect(domain.dataLoaded).toBeTrue(); expect(domain.platforms).toEqual(MockData.T0000.x_mitre_platforms); diff --git a/nav-app/src/app/tabs/tabs.component.spec.ts b/nav-app/src/app/tabs/tabs.component.spec.ts index 27d371d8d..d25c00f47 100755 --- a/nav-app/src/app/tabs/tabs.component.spec.ts +++ b/nav-app/src/app/tabs/tabs.component.spec.ts @@ -31,20 +31,6 @@ describe('TabsComponent', () => { ] }]; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/enterprise-attack/enterprise-attack.json"] - } - ] - } - ]; - beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [HttpClientTestingModule, MatDialogModule, BrowserAnimationsModule, MarkdownModule.forRoot({ loader: HttpClient })], @@ -100,8 +86,7 @@ describe('TabsComponent', () => { it('should set up data in constructor', () => { spyOn(DataService.prototype, 'setUpURLs').and.stub(); - let return$ = {versions: versions}; - spyOn(DataService.prototype, 'getConfig').and.returnValue(of(return$)); + spyOn(DataService.prototype, 'getConfig').and.returnValue(of(MockData.configData)); TabsComponent.prototype.subscription = new Subscription; spyOn(TabsComponent.prototype, "getNamedFragmentValue").and.returnValues(["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v14.1/enterprise-attack/enterprise-attack.json"], ['13'], ['defending-iaas'], ['https://raw.githubusercontent.com/mitre-attack/attack-navigator/master/layers/data/samples/Bear_APT.json']); fixture = TestBed.createComponent(TabsComponent); @@ -160,7 +145,7 @@ describe('TabsComponent', () => { }); it('should create new layer', () => { - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); expect(component.latestDomains.length).toEqual(1); component.newLayer("enterprise-attack-13"); expect(component.layerTabs.length).toEqual(1); @@ -246,25 +231,13 @@ describe('TabsComponent', () => { let component = fixture.debugElement.componentInstance; component.opSettings.scoreExpression = "a+b"; component.opSettings.domain = "enterprise-atack-13"; - let vm1 = component.viewModelsService.newViewModel("layer","ics-attack-13"); - let vm2 = component.viewModelsService.newViewModel("layer1","ics-attack-13"); + let vm1 = component.viewModelsService.newViewModel("layer","enterprise-attack-13"); + let vm2 = component.viewModelsService.newViewModel("layer1","enterprise-attack-13"); component.openTab('layer', vm1, true, true, true, true); component.openTab('layer1', vm2, true, true, true, true); expect(component.getScoreExpressionError()).toEqual('Layer b does not match the chosen domain'); - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "ICS", - "identifier": "ics-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/ics-attack/ics-attack.json"] - } - ] - }] - component.dataService.setUpURLs(versions); // set up data - component.opSettings.domain = "ics-attack-13"; + component.dataService.setUpURLs(MockData.configData); // set up data + component.opSettings.domain = "enterprise-attack-13"; expect(component.getFilteredVMs()).toEqual(component.viewModelsService.viewModels); spyOn(component.dataService, 'loadDomainData').and.returnValue(Promise.resolve()); component.dataService.getDomain(component.opSettings.domain).dataLoaded = false; @@ -278,7 +251,7 @@ describe('TabsComponent', () => { let vm1 = component.viewModelsService.newViewModel("layer","enterprise-attack-13"); component.openTab('layer', vm1, true, true, true, true); expect(component.getScoreExpressionError()).toEqual(null); - component.dataService.setUpURLs(versions); // set up data + component.dataService.setUpURLs(MockData.configData); // set up data component.dataService.parseBundle(component.dataService.getDomain("enterprise-attack-13"), bundles); //load the data component.opSettings.domain = "enterprise-attack-13"; spyOn(component.dataService, 'loadDomainData').and.returnValue(Promise.resolve()); @@ -367,19 +340,7 @@ describe('TabsComponent', () => { it('should read and open json file', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Mobile", - "identifier": "mobile-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/mobile-attack/attack-attack.json"] - } - ] - }] - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); let mockedDocElement = document.createElement('input'); mockedDocElement.id = 'uploader'; mockedDocElement.value = 'test1'; @@ -410,7 +371,7 @@ describe('TabsComponent', () => { it('should get unique layer names', () => { let component = fixture.debugElement.componentInstance; - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); expect(component.latestDomains.length).toEqual(1); component.newLayer("enterprise-attack-13"); component.newLayer("enterprise-attack-13"); @@ -433,31 +394,7 @@ describe('TabsComponent', () => { it('should upgrade layer', (waitForAsync (() => { let component = fixture.debugElement.componentInstance; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/enterprise-attack/enterprise-attack.json"] - } - ] - }, - { - "name": "ATT&CK v12", - "version": "12", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v12.1/enterprise-attack/enterprise-attack.json"] - } - ] - } - ] - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configDataExtended); let layer = JSON.parse(JSON.stringify(MockLayers.layerFile1)) let vm1 = component.viewModelsService.newViewModel("layer2","enterprise-attack-12"); let versionUpgradeSpy = spyOn(component, 'versionUpgradeDialog').and.returnValue(Promise.resolve({oldID: 'enterprise-attack-12', newID: 'enterprise-attack-13'})); @@ -472,31 +409,7 @@ describe('TabsComponent', () => { it('should not upgrade layer', (waitForAsync (() => { let component = fixture.debugElement.componentInstance; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/enterprise-attack/enterprise-attack.json"] - } - ] - }, - { - "name": "ATT&CK v12", - "version": "12", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v12.1/enterprise-attack/enterprise-attack.json"] - } - ] - } - ] - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configDataExtended); let layer = JSON.parse(JSON.stringify(MockLayers.layerFile1)) let vm1 = component.viewModelsService.newViewModel("layer2","enterprise-attack-12"); let versionUpgradeSpy = spyOn(component, 'versionUpgradeDialog').and.returnValue(Promise.resolve(null)); @@ -511,31 +424,7 @@ describe('TabsComponent', () => { it('should not upgrade layer with default layer enabled', (waitForAsync (() => { let component = fixture.debugElement.componentInstance; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/enterprise-attack/enterprise-attack.json"] - } - ] - }, - { - "name": "ATT&CK v12", - "version": "12", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v12.1/enterprise-attack/enterprise-attack.json"] - } - ] - } - ] - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configDataExtended); let layer = JSON.parse(JSON.stringify(MockLayers.layerFile1)); let vm1 = component.viewModelsService.newViewModel("layer2","enterprise-attack-12"); spyOn(component.dataService, 'loadDomainData').and.returnValue(Promise.resolve()); @@ -547,31 +436,7 @@ describe('TabsComponent', () => { it('should not upgrade layer with default layer enabled and domain data loaded', (waitForAsync (() => { let component = fixture.debugElement.componentInstance; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/enterprise-attack/enterprise-attack.json"] - } - ] - }, - { - "name": "ATT&CK v12", - "version": "12", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v12.1/enterprise-attack/enterprise-attack.json"] - } - ] - } - ] - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configDataExtended); component.dataService.parseBundle(component.dataService.getDomain("enterprise-attack-13"), bundles); let bb = JSON.parse(JSON.stringify(MockLayers.layerFile1)) let vm1 = component.viewModelsService.newViewModel("layer2","enterprise-attack-13"); @@ -584,31 +449,7 @@ describe('TabsComponent', () => { it('should not upgrade layer with domain data loaded', (waitForAsync (() => { let component = fixture.debugElement.componentInstance; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/enterprise-attack/enterprise-attack.json"] - } - ] - }, - { - "name": "ATT&CK v12", - "version": "12", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v12.1/enterprise-attack/enterprise-attack.json"] - } - ] - } - ] - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configDataExtended); component.dataService.parseBundle(component.dataService.getDomain("enterprise-attack-13"), bundles); let layer = JSON.parse(JSON.stringify(MockLayers.layerFile1)) let vm1 = component.viewModelsService.newViewModel("layer2","enterprise-attack-13"); @@ -632,31 +473,7 @@ describe('TabsComponent', () => { it('should open version upgrade dialog with upgrade', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/enterprise-attack/enterprise-attack.json"] - } - ] - }, - { - "name": "ATT&CK v12", - "version": "12", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v12.1/enterprise-attack/enterprise-attack.json"] - } - ] - } - ] - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configDataExtended); let vm1 = component.viewModelsService.newViewModel("layer2","enterprise-attack-12"); vm1.version = '12'; const versionUpgradeSpy = spyOn(component.dialog, 'open').and.returnValue({afterClosed: () => of({upgrade:true})}); @@ -667,31 +484,7 @@ describe('TabsComponent', () => { it('should open version upgrade dialog with no upgrade', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/enterprise-attack/enterprise-attack.json"] - } - ] - }, - { - "name": "ATT&CK v12", - "version": "12", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v12.1/enterprise-attack/enterprise-attack.json"] - } - ] - } - ] - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configDataExtended); let vm1 = component.viewModelsService.newViewModel("layer2","enterprise-attack-12"); vm1.version = '12'; const versionUpgradeSpy = spyOn(component.dialog, 'open').and.returnValue({afterClosed: () => of({upgrade:false})}); @@ -702,7 +495,7 @@ describe('TabsComponent', () => { it('should serialize viewmodel and only save techniqueVMs which have been modified', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); let vm1 = component.viewModelsService.newViewModel("layer2","enterprise-attack-13"); vm1.version = '13'; let st1 = new Technique(MockData.T0000_000, [], null); @@ -740,7 +533,7 @@ describe('TabsComponent', () => { it('should serialize viewmodel and only save techniqueVMs which have been modified and are visible', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); let vm1 = component.viewModelsService.newViewModel("layer2","enterprise-attack-13"); let t1 = new Technique(MockData.T0000, [], null); let t2 = new Technique(MockData.T0001, [], null); @@ -760,7 +553,7 @@ describe('TabsComponent', () => { it('should throw errors for deserializing viewmodel', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); let viewmodel_error_file1 = { "description":3, "sorting": "3", @@ -842,7 +635,7 @@ describe('TabsComponent', () => { 'version': '100F', 'identifier': 'enterprise-attack' } - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); let layer = JSON.parse(JSON.stringify(validate_input_error_file1)); let alertSpy = spyOn(window, "alert"); let consoleSpy = spyOn(console, 'error'); @@ -857,7 +650,7 @@ describe('TabsComponent', () => { 'version': '13', 'identifier': 'enterprise-attack' } - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); let layer = JSON.parse(JSON.stringify(validate_input_error_file1)); let alertSpy = spyOn(window, "alert"); let consoleSpy = spyOn(console, 'error'); @@ -878,19 +671,7 @@ describe('TabsComponent', () => { it('should through error for invalid domain', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Mobile", - "identifier": "mobile-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/mobile-attack/attack-attack.json"] - } - ] - }] - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); spyOn(console, 'error'); let blob = new Blob([JSON.stringify(MockLayers.layerFile1)], { type: 'text/json' }); let file = new File([blob], "layer-2.json"); @@ -900,19 +681,7 @@ describe('TabsComponent', () => { it('should read and open json file with 2 layers', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Mobile", - "identifier": "mobile-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/mobile-attack/attack-attack.json"] - } - ] - }] - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); let combined_layer = [MockLayers.layerFile3, MockLayers.layerFile3] let blob = new Blob([JSON.stringify(combined_layer)], { type: 'text/json' }); let file = new File([blob], "layer-2.json"); @@ -929,31 +698,7 @@ describe('TabsComponent', () => { component.openTab('layer', vm1, true, true, true, true); component.openTab('layer2', vm2, true, true, true, true); - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/enterprise-attack/enterprise-attack.json"] - } - ] - }, - { - "name": "ATT&CK v12", - "version": "12", - "domains": [ - { - "name": "Enterprise", - "identifier": "enterprise-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v12.1/enterprise-attack/enterprise-attack.json"] - } - ] - } - ] - component.dataService.setUpURLs(versions); // set up data + component.dataService.setUpURLs(MockData.configDataExtended); // set up data component.dataService.parseBundle(component.dataService.getDomain("enterprise-attack-13"), bundles); //load the data component.opSettings.domain = "enterprise-attack-13"; let alertSpy = spyOn(window, "alert"); @@ -965,7 +710,7 @@ describe('TabsComponent', () => { it('should load from url', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); component.http = httpClient; spyOn(component.http,'get').and.returnValue(of(MockLayers.layerFile1)); let versionMismatchSpy = spyOn(component, 'versionMismatchWarning').and.returnValue(Promise.resolve([])); @@ -978,18 +723,15 @@ describe('TabsComponent', () => { it('should throw errors when loading from url', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Mobile", - "identifier": "mobile-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/mobile-attack/attack-attack.json"] - } - ] - }] + let versions = [{ + "name": "ATT&CK v13", + "version": "13", + "domains": [{ + "name": "Mobile", + "identifier": "mobile-attack", + "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/mobile-attack/attack-attack.json"] + }] + }] component.dataService.setUpURLs(versions); component.http = httpClient; spyOn(component.http,'get').and.returnValue(of(MockLayers.layerFile1)); @@ -1010,19 +752,7 @@ describe('TabsComponent', () => { 'version': '12', 'identifier': 'enterprise-attack' } - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Mobile", - "identifier": "mobile-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/mobile-attack/attack-attack.json"] - } - ] - }] - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); component.dataService.domains[0].dataLoaded = true; component.http = httpClient; spyOn(component.http,'get').and.returnValue(of(MockLayers.layerFile1)); @@ -1033,45 +763,25 @@ describe('TabsComponent', () => { it('should load base data from URL', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - let versions = [ - { - "name": "ATT&CK v13", - "version": "13", - "domains": [ - { - "name": "Mobile", - "identifier": "mobile-attack", - "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/mobile-attack/attack-attack.json"] - } - ] - }] - let default_layers = { - "enabled": false, - "urls": ["assets/example.json", "https://raw.githubusercontent.com/mitre-attack/attack-navigator/master/layers/data/samples/Bear_APT.json"] - } - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); component.http = httpClient; spyOn(component.http,'get').and.returnValue(of(MockLayers.layerFile1)); spyOn(component.dataService, 'loadDomainData').and.returnValue(Promise.resolve()); spyOn(component, "getNamedFragmentValue").and.returnValues(["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v14.1/enterprise-attack/enterprise-attack.json"], ['13'], ['defending-iaas'], 'https://raw.githubusercontent.com/mitre-attack/attack-navigator/master/layers/data/samples/Bear_APT.json'); - component.loadTabs(default_layers); + component.loadTabs(MockData.defaultLayersDisabled); expect(component.layerTabs.length).toEqual(1) }))); it('should load layer from URL', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - let default_layers = { - "enabled": false, - "urls": ["assets/example.json", "https://raw.githubusercontent.com/mitre-attack/attack-navigator/master/layers/data/samples/Bear_APT.json"] - } - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); component.http = httpClient; spyOn(component.http,'get').and.returnValue(of(MockLayers.layerFile1)); spyOn(component.dataService, 'loadDomainData').and.returnValue(Promise.resolve()); let versionMismatchSpy = spyOn(component, 'versionMismatchWarning').and.returnValue(Promise.resolve([])); let upgradeLayerSpy = spyOn(component, 'upgradeLayer').and.returnValue(Promise.resolve([])); spyOn(component, "getNamedFragmentValue").and.returnValues([], ['13'], ['defending-iaas'], ['https://raw.githubusercontent.com/mitre-attack/attack-navigator/master/layers/data/samples/Bear_APT.json']); - component.loadTabs(default_layers).then(() => { + component.loadTabs(MockData.defaultLayersDisabled).then(() => { expect(versionMismatchSpy).toHaveBeenCalled(); expect(upgradeLayerSpy).toHaveBeenCalled(); }); @@ -1079,18 +789,14 @@ describe('TabsComponent', () => { it('should load default layers from config file', (waitForAsync ( () => { let component = fixture.debugElement.componentInstance; - let default_layers = { - "enabled": true, - "urls": ["https://raw.githubusercontent.com/mitre-attack/attack-navigator/master/layers/data/samples/Bear_APT.json"] - } - component.dataService.setUpURLs(versions); + component.dataService.setUpURLs(MockData.configData); component.http = httpClient; spyOn(component.http,'get').and.returnValue(of(MockLayers.layerFile1)); spyOn(component.dataService, 'loadDomainData').and.returnValue(Promise.resolve()); let versionMismatchSpy = spyOn(component, 'versionMismatchWarning').and.returnValue(Promise.resolve([])); let upgradeLayerSpy = spyOn(component, 'upgradeLayer').and.returnValue(Promise.resolve([])); spyOn(component, "getNamedFragmentValue").and.returnValues([], ['13'], ['defending-iaas'], []); - component.loadTabs(default_layers).then(() => { + component.loadTabs(MockData.defaultLayersEnabled).then(() => { expect(versionMismatchSpy).toHaveBeenCalled(); expect(upgradeLayerSpy).toHaveBeenCalled(); }); diff --git a/nav-app/src/tests/utils/mock-data.ts b/nav-app/src/tests/utils/mock-data.ts index 61a59b618..7a4061667 100644 --- a/nav-app/src/tests/utils/mock-data.ts +++ b/nav-app/src/tests/utils/mock-data.ts @@ -10,6 +10,32 @@ export const configData = [{ "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/enterprise-attack/enterprise-attack.json"] }] }]; +export const configDataExtended = [{ + "name": "ATT&CK v13", + "version": "13", + "domains": [{ + "name": "Enterprise", + "identifier": "enterprise-attack", + "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v13.1/enterprise-attack/enterprise-attack.json"] + }] +},{ + "name": "ATT&CK v12", + "version": "12", + "domains": [{ + "name": "Enterprise", + "identifier": "enterprise-attack", + "data": ["https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v12.1/enterprise-attack/enterprise-attack.json"] + }] +}]; +export const defaultLayersEnabled = { + "enabled": true, + "urls": ["https://raw.githubusercontent.com/mitre-attack/attack-navigator/master/layers/data/samples/Bear_APT.json"] +} +export const defaultLayersDisabled = { + "enabled": false, + "urls": ["https://raw.githubusercontent.com/mitre-attack/attack-navigator/master/layers/data/samples/Bear_APT.json"] +} + export const taxiiData = [{ "name": "ATT&CK v13", "version": "13", @@ -28,6 +54,18 @@ export const workbenchData = [{ "apiKey": "sample-navigator-apikey" }, }]; +export const configTechniqueControls = { + "name": "technique_controls", "enabled": true, "description": "Disable to disable all subfeatures", "subfeatures": [ + {"name": "disable_techniques", "enabled": true, "description": "Disable to remove the ability to disable techniques."}, + {"name": "manual_color", "enabled": true, "description": "Disable to remove the ability to assign manual colors to techniques."}, + {"name": "background_color", "enabled": true, "description": "Disable to remove the background color effect on manually assigned colors."} + ] +} +export const configToolbarControls = { + "name": "toolbar_controls", "enabled": true, "description": "Disable to disable all subfeatures", "subfeatures": [ + {"name": "sticky_toolbar", "enabled": true, "description": "Disable to remove the ability to enable/disable the sticky toolbar."} + ] +} // mock base STIX SDOs export const stixSDO = {