From 0bbd11d48f1a2ea39102c67eb2b5cf410a3d5bdf Mon Sep 17 00:00:00 2001 From: Krishi Kishore Date: Mon, 20 Jun 2022 15:12:28 -0400 Subject: [PATCH 1/2] fix(profiles): remove excess mebx random password warning --- .../profile/create-static-cira.spec.ts | 75 +++++++++++++++++++ .../e2e/integration/profile/create.spec.ts | 42 +++++++++++ .../profile-detail.component.spec.ts | 74 +++++++++++++++++- .../profile-detail.component.ts | 15 +++- 4 files changed, 201 insertions(+), 5 deletions(-) diff --git a/cypress/e2e/integration/profile/create-static-cira.spec.ts b/cypress/e2e/integration/profile/create-static-cira.spec.ts index 2a7aa86e6..4c4550350 100644 --- a/cypress/e2e/integration/profile/create-static-cira.spec.ts +++ b/cypress/e2e/integration/profile/create-static-cira.spec.ts @@ -197,4 +197,79 @@ describe('Test Profile Page', () => { cy.get('mat-cell').contains(profileFixtures.check.network.static.toString()) cy.get('mat-cell').contains(profileFixtures.check.mode.ccm) }) + + it('creates the default profile with static+cira and only random mebx password and ccm', () => { + // Stub the get and post requests + cy.myIntercept('GET', 'ciraconfigs?$count=true', { + statusCode: httpCodes.SUCCESS, + body: apiResponses.ciraConfigs.getAll.forProfile.response + }).as('get-configs') + + cy.myIntercept('GET', 'wirelessconfigs?$count=true', { + statusCode: httpCodes.SUCCESS, + body: apiResponses.wirelessConfigs.getAll.forProfile.response + }).as('get-wirelessConfigs') + + cy.myIntercept('POST', 'profiles', { + statusCode: httpCodes.CREATED, + body: apiResponses.profiles.create.success.response + }).as('post-profile') + + cy.myIntercept('GET', 'profiles?$top=25&$skip=0&$count=true', { + statusCode: httpCodes.SUCCESS, + body: apiResponses.profiles.getAll.empty.response + }).as('get-profiles') + + cy.goToPage('Profiles') + cy.wait('@get-profiles') + + // change api response + cy.myIntercept('GET', 'profiles?$top=25&$skip=0&$count=true', { + statusCode: httpCodes.SUCCESS, + body: apiResponses.profiles.getAll.success.response + }).as('get-profiles2') + + // Fill out the profile + cy.get('button').contains('Add New').click() + cy.wait('@get-configs') + cy.wait('@get-wirelessConfigs') + cy.enterProfileInfo( + profileFixtures.happyPathStaticCIRARandomPassword.profileName, + profileFixtures.happyPathStaticCIRARandomPassword.activation, + false, + true, + profileFixtures.happyPathStaticCIRARandomPassword.dhcpEnabled, + profileFixtures.happyPathStaticCIRARandomPassword.connectionMode, + profileFixtures.happyPathStaticCIRARandomPassword.ciraConfig, + profileFixtures.happyPathStaticCIRARandomPassword.userConsent, + profileFixtures.happyPathStaticCIRARandomPassword.iderEnabled, + profileFixtures.happyPathStaticCIRARandomPassword.kvmEnabled, + profileFixtures.happyPathStaticCIRARandomPassword.solEnabled + ) + cy.get('button[type=submit]').click() + cy.get('button').contains('Continue').click() + + // Wait for requests to finish and check them their responses + cy.wait('@post-profile').then((req) => { + cy.wrap(req) + .its('response.statusCode') + .should('eq', httpCodes.CREATED) + + // Check that the config was successful + cy.get('mat-cell').contains(profileFixtures.happyPathStaticCIRARandomPassword.profileName) + cy.get('mat-cell').contains(profileFixtures.check.network.static.toString()) + cy.get('mat-cell').contains(profileFixtures.check.mode.ccm) + }) + + // TODO: check the response to make sure that it is correct + // this is currently difficult because of the format of the response + cy.wait('@get-profiles2') + .its('response.statusCode') + .should('eq', httpCodes.SUCCESS) + + // Check that the config was successful + cy.get('mat-cell').contains(profileFixtures.happyPathStaticCIRARandomPassword.profileName) + cy.get('mat-cell').contains(profileFixtures.check.network.static.toString()) + cy.get('mat-cell').contains(profileFixtures.check.mode.ccm) + }) }) diff --git a/cypress/e2e/integration/profile/create.spec.ts b/cypress/e2e/integration/profile/create.spec.ts index f710bde92..20e6ed68b 100644 --- a/cypress/e2e/integration/profile/create.spec.ts +++ b/cypress/e2e/integration/profile/create.spec.ts @@ -90,4 +90,46 @@ describe('Test Profile Page', () => { cy.get('mat-cell').contains(profileFixtures.happyPath.ciraConfig) cy.get('mat-cell').contains(profileFixtures.check.mode.ccm) }) + + it('creates the default profile with only random mebx password and ccm', () => { + cy.enterProfileInfo( + profileFixtures.happyPath.profileName, + profileFixtures.happyPath.activation, + false, + true, + profileFixtures.happyPath.dhcpEnabled, + profileFixtures.happyPath.connectionMode, + profileFixtures.happyPath.ciraConfig, + profileFixtures.happyPath.userConsent, + profileFixtures.happyPath.iderEnabled, + profileFixtures.happyPath.kvmEnabled, + profileFixtures.happyPath.solEnabled + ) + cy.get('button[type=submit]').click() + + // Wait for requests to finish and check them their responses + cy.wait('@post-profile').then((req) => { + cy.wrap(req) + .its('response.statusCode') + .should('eq', httpCodes.CREATED) + + // Check that the config was successful + cy.get('mat-cell').contains(profileFixtures.happyPath.profileName) + cy.get('mat-cell').contains(profileFixtures.check.network.dhcp.toString()) + cy.get('mat-cell').contains(profileFixtures.happyPath.ciraConfig) + cy.get('mat-cell').contains(profileFixtures.check.mode.ccm) + }) + + // TODO: check the response to make sure that it is correct + // this is currently difficult because of the format of the response + cy.wait('@get-profiles2') + .its('response.statusCode') + .should('eq', httpCodes.SUCCESS) + + // Check that the config was successful + cy.get('mat-cell').contains(profileFixtures.happyPath.profileName) + cy.get('mat-cell').contains(profileFixtures.check.network.dhcp.toString()) + cy.get('mat-cell').contains(profileFixtures.happyPath.ciraConfig) + cy.get('mat-cell').contains(profileFixtures.check.mode.ccm) + }) }) diff --git a/src/app/profiles/profile-detail/profile-detail.component.spec.ts b/src/app/profiles/profile-detail/profile-detail.component.spec.ts index 3b4c8357b..380a773f0 100644 --- a/src/app/profiles/profile-detail/profile-detail.component.spec.ts +++ b/src/app/profiles/profile-detail/profile-detail.component.spec.ts @@ -312,6 +312,76 @@ describe('ProfileDetailComponent', () => { expect(routerSpy).not.toHaveBeenCalled() }) + it('should submit when valid with only random mebx password + ccm activation', () => { + const routerSpy = spyOn(component.router, 'navigate') + + component.isEdit = false + component.profileForm.patchValue({ + profileName: 'profile', + activation: 'ccmactivate', + amtPassword: 'Password123', + generateRandomPassword: false, + generateRandomMEBxPassword: true, + mebxPassword: '', + dhcpEnabled: true, + ciraConfigName: null + }) + component.confirm() + + expect(profileCreateSpy).toHaveBeenCalled() + expect(routerSpy).toHaveBeenCalled() + }) + + it('should submit if cira config and static network are simultaneously selected + only random mebx password + ccm activation', () => { + const routerSpy = spyOn(component.router, 'navigate') + const dialogRefSpyObj = jasmine.createSpyObj({ afterClosed: of(true), close: null }) + const dialogSpy = spyOn(TestBed.get(MatDialog), 'open').and.returnValue(dialogRefSpyObj) + + component.isEdit = false + component.profileForm.patchValue({ + profileName: 'profile', + activation: 'ccmactivate', + amtPassword: 'Password123', + generateRandomPassword: false, + generateRandomMEBxPassword: true, + mebxPassword: '', + dhcpEnabled: false, + ciraConfigName: 'config1', + tlsConfigName: null + }) + component.confirm() + + expect(dialogSpy).toHaveBeenCalled() + expect(dialogRefSpyObj.afterClosed).toHaveBeenCalled() + expect(profileCreateSpy).toHaveBeenCalled() + expect(routerSpy).toHaveBeenCalled() + }) + + it('should cancel submit if cira config and static network are simultaneously selected + only random mebx password + ccm activation', () => { + const routerSpy = spyOn(component.router, 'navigate') + const dialogRefSpyObj = jasmine.createSpyObj({ afterClosed: of(false), close: null }) + const dialogSpy = spyOn(TestBed.get(MatDialog), 'open').and.returnValue(dialogRefSpyObj) + + component.isEdit = false + component.profileForm.patchValue({ + profileName: 'profile', + activation: 'ccmactivate', + amtPassword: 'Password123', + generateRandomPassword: false, + generateRandomMEBxPassword: true, + mebxPassword: '', + dhcpEnabled: false, + ciraConfigName: 'config1', + tlsConfigName: null + }) + component.confirm() + + expect(dialogSpy).toHaveBeenCalled() + expect(dialogRefSpyObj.afterClosed).toHaveBeenCalled() + expect(profileCreateSpy).not.toHaveBeenCalled() + expect(routerSpy).not.toHaveBeenCalled() + }) + it('should update the selected wifi configs on selecting a wifi profile', () => { component.selectedWifiConfigs = [{ priority: 1, profileName: 'home' }] const option: any = { @@ -336,11 +406,11 @@ describe('ProfileDetailComponent', () => { it('should adjust related fields on selecting activation mode', () => { component.activationChange(Constants.CCMActivate) - expect(component.profileForm.controls.mebxPassword.disabled).toBe(true) + expect(component.profileForm.controls.generateRandomMEBxPassword.disabled).toBe(true) expect(component.profileForm.controls.userConsent.disabled).toBe(true) expect(component.profileForm.controls.userConsent.value).toEqual(Constants.UserConsent_All) component.activationChange(Constants.ACMActivate) - expect(component.profileForm.controls.mebxPassword.disabled).toBe(false) + expect(component.profileForm.controls.generateRandomMEBxPassword.disabled).toBe(false) expect(component.profileForm.controls.userConsent.disabled).toBe(false) }) diff --git a/src/app/profiles/profile-detail/profile-detail.component.ts b/src/app/profiles/profile-detail/profile-detail.component.ts index 2176adc23..9714e509c 100644 --- a/src/app/profiles/profile-detail/profile-detail.component.ts +++ b/src/app/profiles/profile-detail/profile-detail.component.ts @@ -139,11 +139,14 @@ export class ProfileDetailComponent implements OnInit { this.profileForm.controls.mebxPassword.disable() this.profileForm.controls.mebxPassword.setValue(null) this.profileForm.controls.mebxPassword.clearValidators() + this.profileForm.controls.generateRandomMEBxPassword.setValue(true) + this.profileForm.controls.generateRandomMEBxPassword.disable() } else { this.profileForm.controls.mebxPassword.enable() this.profileForm.controls.mebxPassword.setValidators(Validators.required) this.profileForm.controls.userConsent.enable() this.profileForm.controls.userConsent.setValidators(Validators.required) + this.profileForm.controls.generateRandomMEBxPassword.enable() } } @@ -376,13 +379,19 @@ export class ProfileDetailComponent implements OnInit { if (this.profileForm.valid) { this.isLoading = true const result: any = Object.assign({}, this.profileForm.getRawValue()) - // When creating new + // Indicator for when activation mode is CCM and only the MEBX password is randomized + // Since the default for CCM is to randomize the MEBX password, no warning is necessary in this case + let CCMMEBXRandomOnly = false + if (result.activation === Constants.CCMActivate && result.generateRandomMEBxPassword && !result.generateRandomPassword) { + CCMMEBXRandomOnly = true + } + // Check combinations of CIRA configuration + static network & randomized password to trigger different warnings if ((result.connectionMode === Constants.ConnectionMode_CIRA && result.dhcpEnabled === false) && - (!this.isEdit && (result.generateRandomPassword || result.generateRandomMEBxPassword))) { + (!this.isEdit && (result.generateRandomPassword || result.generateRandomMEBxPassword) && !CCMMEBXRandomOnly)) { this.randPasswordCIRAStaticWarning() } else if (result.connectionMode === Constants.ConnectionMode_CIRA && result.dhcpEnabled === false) { this.CIRAStaticWarning() - } else if (!this.isEdit && (result.generateRandomPassword || result.generateRandomMEBxPassword)) { + } else if (!this.isEdit && (result.generateRandomPassword || result.generateRandomMEBxPassword) && !CCMMEBXRandomOnly) { this.randPasswordWarning() } else { this.onSubmit() From 12877850cae4246af76ea33370c78c693228c5da Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 22 Jun 2022 10:18:36 -0700 Subject: [PATCH 2/2] refactor(profile-detail): update logic to be more readable --- .../profile/create-static-cira.spec.ts | 6 +- .../profile-detail.component.html | 4 +- .../profile-detail.component.spec.ts | 14 ++- .../profile-detail.component.ts | 111 ++++++------------ .../random-pass-alert.component.html | 2 +- .../static-cira-warning.component.html | 2 +- 6 files changed, 52 insertions(+), 87 deletions(-) diff --git a/cypress/e2e/integration/profile/create-static-cira.spec.ts b/cypress/e2e/integration/profile/create-static-cira.spec.ts index 4c4550350..478eb0e0a 100644 --- a/cypress/e2e/integration/profile/create-static-cira.spec.ts +++ b/cypress/e2e/integration/profile/create-static-cira.spec.ts @@ -170,9 +170,9 @@ describe('Test Profile Page', () => { profileFixtures.happyPathStaticCIRARandomPassword.solEnabled ) cy.get('button[type=submit]').click() - cy.get('button').contains('Continue').click() - cy.wait(300) - cy.get('button').contains('Continue').click() + + cy.get('button[data-cy="static-cira-alert-ok"]').click() + cy.get('button[data-cy="random-pass-ok"]').click() // Wait for requests to finish and check them their responses cy.wait('@post-profile').then((req) => { diff --git a/src/app/profiles/profile-detail/profile-detail.component.html b/src/app/profiles/profile-detail/profile-detail.component.html index 51c0d4270..63814881c 100644 --- a/src/app/profiles/profile-detail/profile-detail.component.html +++ b/src/app/profiles/profile-detail/profile-detail.component.html @@ -62,7 +62,7 @@ This field is required and must be between 8 and 32 characters - The AMT Password is used for remote access of a device. + The AMT Password is used for remote access of a device. It is also required for reconfiguring/deactivating the device. - + \ No newline at end of file diff --git a/src/app/shared/static-cira-warning/static-cira-warning.component.html b/src/app/shared/static-cira-warning/static-cira-warning.component.html index 7e9f91f65..7dcea98bc 100644 --- a/src/app/shared/static-cira-warning/static-cira-warning.component.html +++ b/src/app/shared/static-cira-warning/static-cira-warning.component.html @@ -5,5 +5,5 @@

CIRA and Static Network Configuration

- + \ No newline at end of file