-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-133624 / 25.10 / Support for single time user passwords in STIG m…
…ode (#11427) * NAS-133624: Support for single time user passwords in STIG mode * NAS-133624: Support for single time user passwords in STIG mode * NAS-133624: PR update * NAS-133624: PR update * NAS-133624: PR update * NAS-133624: PR update * NAS-133624: PR Update * NAS-133624: PR update * NAS-133624: PR update
- Loading branch information
1 parent
50166c9
commit 33d4cdf
Showing
122 changed files
with
2,600 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export enum AccountAttribute { | ||
Local = 'LOCAL', | ||
SysAdmin = 'SYS_ADMIN', | ||
Otpw = 'OTPW', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/app/modules/forms/ix-forms/components/ix-radio-group/ix-radio-group.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 13 additions & 40 deletions
53
src/app/modules/layout/topbar/change-password-dialog/change-password-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,15 @@ | ||
<h1 matDialogTitle>{{ 'Change Password' | translate }}</h1> | ||
<form class="ix-form-container" [formGroup]="form" (submit)="onSubmit()"> | ||
@if (!(isFullAdminUser$ | async)) { | ||
<ix-input | ||
formControlName="old_password" | ||
type="password" | ||
[label]="'Current Password' | translate" | ||
[required]="true" | ||
></ix-input> | ||
} | ||
|
||
<ix-input | ||
formControlName="new_password" | ||
type="password" | ||
[label]="'New Password' | translate" | ||
[required]="true" | ||
[tooltip]="tooltips.password | translate" | ||
></ix-input> | ||
|
||
<ix-input | ||
formControlName="passwordConfirmation" | ||
type="password" | ||
[label]="'Confirm Password' | translate" | ||
[required]="true" | ||
></ix-input> | ||
|
||
<ix-form-actions> | ||
<button mat-button type="button" matDialogClose ixTest="cancel"> | ||
{{ 'Cancel' | translate }} | ||
</button> | ||
|
||
<button | ||
mat-button | ||
type="submit" | ||
color="primary" | ||
ixTest="save" | ||
[disabled]="form.invalid" | ||
> | ||
{{ 'Save' | translate }} | ||
</button> | ||
</ix-form-actions> | ||
</form> | ||
<button | ||
mat-icon-button | ||
mat-dialog-close | ||
class="close-change-password-dialog" | ||
ixTest="close-change-password-dialog" | ||
[aria-label]="'Close Change Password Dialog' | translate" | ||
> | ||
<ix-icon name="clear"></ix-icon> | ||
</button> | ||
|
||
<ix-change-password-form | ||
(passwordUpdated)="dialogRef.close(true)" | ||
></ix-change-password-form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,8 @@ | |
min-width: 380px; | ||
} | ||
|
||
.close-change-password-dialog { | ||
position: absolute; | ||
right: 16px; | ||
top: 26px; | ||
} |
76 changes: 6 additions & 70 deletions
76
...app/modules/layout/topbar/change-password-dialog/change-password-dialog.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,28 @@ | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { FormGroup, ReactiveFormsModule } from '@angular/forms'; | ||
import { MatButtonHarness } from '@angular/material/button/testing'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
import { MatDialogRef } from '@angular/material/dialog'; | ||
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest'; | ||
import { throwError } from 'rxjs'; | ||
import { MockAuthService } from 'app/core/testing/classes/mock-auth.service'; | ||
import { mockCall, mockApi } from 'app/core/testing/utils/mock-api.utils'; | ||
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils'; | ||
import { Role } from 'app/enums/role.enum'; | ||
import { FormErrorHandlerService } from 'app/modules/forms/ix-forms/services/form-error-handler.service'; | ||
import { IxFormHarness } from 'app/modules/forms/ix-forms/testing/ix-form.harness'; | ||
import { ChangePasswordDialogComponent } from 'app/modules/layout/topbar/change-password-dialog/change-password-dialog.component'; | ||
import { ApiService } from 'app/modules/websocket/api.service'; | ||
import { ChangePasswordFormComponent } from 'app/modules/layout/topbar/change-password-dialog/change-password-form/change-password-form.component'; | ||
|
||
describe('ChangePasswordDialogComponent', () => { | ||
let spectator: Spectator<ChangePasswordDialogComponent>; | ||
let loader: HarnessLoader; | ||
let api: ApiService; | ||
|
||
const createComponent = createComponentFactory({ | ||
component: ChangePasswordDialogComponent, | ||
imports: [ | ||
ReactiveFormsModule, | ||
], | ||
providers: [ | ||
mockApi([ | ||
mockCall('user.set_password'), | ||
]), | ||
mockProvider(FormErrorHandlerService), | ||
mockProvider(MatDialogRef), | ||
mockAuth(), | ||
], | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent(); | ||
loader = TestbedHarnessEnvironment.loader(spectator.fixture); | ||
api = spectator.inject(ApiService); | ||
}); | ||
|
||
it('does not show current password field for full admin', async () => { | ||
const authMock = spectator.inject(MockAuthService); | ||
authMock.setRoles([Role.FullAdmin]); | ||
|
||
const form = await loader.getHarness(IxFormHarness); | ||
expect(await form.getControl('Current Password')).toBeUndefined(); | ||
}); | ||
|
||
it('checks current password, updates to new password and closes the dialog when form is saved', async () => { | ||
const authMock = spectator.inject(MockAuthService); | ||
authMock.setRoles([Role.ReadonlyAdmin]); | ||
|
||
const form = await loader.getHarness(IxFormHarness); | ||
await form.fillForm({ | ||
'Current Password': 'correct', | ||
'New Password': '123456', | ||
'Confirm Password': '123456', | ||
}); | ||
|
||
const saveButton = await loader.getHarness(MatButtonHarness.with({ text: 'Save' })); | ||
await saveButton.click(); | ||
|
||
expect(api.call).toHaveBeenCalledWith('user.set_password', [{ | ||
old_password: 'correct', | ||
new_password: '123456', | ||
username: 'root', | ||
}]); | ||
expect(spectator.inject(MatDialogRef).close).toHaveBeenCalled(); | ||
}); | ||
|
||
it('shows error if any happened during password change request', async () => { | ||
const authMock = spectator.inject(MockAuthService); | ||
authMock.setRoles([Role.ReadonlyAdmin]); | ||
|
||
const error = new Error('error'); | ||
jest.spyOn(api, 'call').mockReturnValue(throwError(() => error)); | ||
|
||
const form = await loader.getHarness(IxFormHarness); | ||
await form.fillForm({ | ||
'Current Password': 'incorrect', | ||
'New Password': '123456', | ||
'Confirm Password': '123456', | ||
}); | ||
|
||
const saveButton = await loader.getHarness(MatButtonHarness.with({ text: 'Save' })); | ||
await saveButton.click(); | ||
|
||
expect(spectator.inject(FormErrorHandlerService).handleValidationErrors) | ||
.toHaveBeenCalledWith(error, expect.any(FormGroup)); | ||
it('renders the change password form', () => { | ||
const formComponent = spectator.query(ChangePasswordFormComponent); | ||
expect(formComponent).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.