Skip to content

Commit

Permalink
[#1532] Allow space in passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
msiodelski committed Oct 16, 2024
1 parent 26b77ab commit 174f840
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@ describe('PasswordChangePageComponent', () => {
expect(breadcrumbsComponent.items[0].label).toEqual('User Profile')
expect(breadcrumbsComponent.items[1].label).toEqual('Password Change')
})

it('should permit spaces in the password', () => {
component.ngOnInit()
component.passwordChangeForm.get('oldPassword').setValue('admin')
component.passwordChangeForm.get('newPassword').setValue('password with spaces works well')
component.passwordChangeForm.get('confirmPassword').setValue('password with spaces works well')

fixture.detectChanges()
expect(component.passwordChangeForm.valid).toBeTrue()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class PasswordChangePageComponent implements OnInit {
* It allows uppercase and lowercase letters A-Z,
* numbers 0-9 and all special characters.
*/
passwordPattern: RegExp = /^[a-zA-Z0-9~`!@#$%^&*()_+\-=\[\]\\{}|;':",.\/<>?]+$/
passwordPattern: RegExp = /^[a-zA-Z0-9~`!@#$%^&*()_+\-=\[\]\\{}|;':",.\/<>?\s]+$/

constructor(
private formBuilder: UntypedFormBuilder,
Expand Down
40 changes: 37 additions & 3 deletions webui/src/app/users-page/users-page.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { By } from '@angular/platform-browser'
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing'
import { UsersPageComponent } from './users-page.component'
import { ActivatedRoute, convertToParamMap, ParamMap, RouterModule } from '@angular/router'
import { UntypedFormBuilder } from '@angular/forms'
Expand All @@ -15,13 +15,15 @@ import { BreadcrumbModule } from 'primeng/breadcrumb'
import { HelpTipComponent } from '../help-tip/help-tip.component'
import { OverlayPanelModule } from 'primeng/overlaypanel'
import { NoopAnimationsModule } from '@angular/platform-browser/animations'
import { RouterTestingModule } from '@angular/router/testing'
import { ReactiveFormsModule } from '@angular/forms'
import { AuthService } from '../auth.service'
import { ConfirmDialogModule } from 'primeng/confirmdialog'
import { PlaceholderPipe } from '../pipes/placeholder.pipe'
import { MockParamMap } from '../utils'
import { TagModule } from 'primeng/tag'
import { PanelModule } from 'primeng/panel'
import { DropdownModule } from 'primeng/dropdown'
import { PasswordModule } from 'primeng/password'

describe('UsersPageComponent', () => {
let component: UsersPageComponent
Expand All @@ -45,7 +47,13 @@ describe('UsersPageComponent', () => {
ConfirmDialogModule,
SharedModule,
TagModule,
RouterTestingModule.withRoutes([{ path: 'users/1', component: UsersPageComponent }]),
RouterModule.forRoot([
{ path: 'users/1', component: UsersPageComponent },
{ path: 'users/new', component: UsersPageComponent },
]),
PanelModule,
DropdownModule,
PasswordModule,
],
declarations: [UsersPageComponent, BreadcrumbsComponent, HelpTipComponent, PlaceholderPipe],
providers: [
Expand Down Expand Up @@ -159,4 +167,30 @@ describe('UsersPageComponent', () => {
// Check that the deleteUser function has been called
expect(usersApi.deleteUser).toHaveBeenCalled()
})

it('should allow spaces in the password', fakeAsync(() => {
component.ngOnInit()
tick()
fixture.detectChanges()

// Open the new user tab.
paramMapValue.next(convertToParamMap({ id: 'new' }))
fixture.detectChanges()

// Initially the form should be invalid because it is empty.
expect(component.userForm).toBeTruthy()
expect(component.userForm.valid).toBeFalse()

// Set valid data including a password containing spaces.
component.userForm.get('userLogin').setValue('frank')
component.userForm.get('userFirst').setValue('Frank')
component.userForm.get('userLast').setValue('Smith')
component.userForm.get('userGroup').setValue(1)
component.userForm.get('userPassword').setValue('password with spaces is cool')
component.userForm.get('userPassword2').setValue('password with spaces is cool')
fixture.detectChanges()

// The form should be validated ok.
expect(component.userForm.valid).toBeTrue()
}))
})
29 changes: 9 additions & 20 deletions webui/src/app/users-page/users-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ConfirmationService, MenuItem, MessageService, SelectItem } from 'prime
import { AuthService } from '../auth.service'
import { ServerDataService } from '../server-data.service'
import { UsersService } from '../backend/api/api'
import { Subscription } from 'rxjs'
import { lastValueFrom, Subscription } from 'rxjs'
import { getErrorMessage } from '../utils'
import { User } from '../backend'

Expand Down Expand Up @@ -106,7 +106,7 @@ export class UsersPageComponent implements OnInit, OnDestroy {
* It allows uppercase and lowercase letters A-Z,
* numbers 0-9 and all special characters.
*/
passwordPattern: RegExp = /^[a-zA-Z0-9~`!@#$%^&*()_+\-=\[\]\\{}|;':",.\/<>?]+$/
passwordPattern: RegExp = /^[a-zA-Z0-9~`!@#$%^&*()_+\-=\[\]\\{}|;':",.\/<>?\s]+$/

// ToDo: Strict typing
private groups: any[] = []
Expand Down Expand Up @@ -360,9 +360,7 @@ export class UsersPageComponent implements OnInit, OnDestroy {
* of rows to be returned and the filter text.
*/
loadUsers(event) {
this.usersApi
.getUsers(event.first, event.rows, event.filters.text?.[0]?.value)
.toPromise()
lastValueFrom(this.usersApi.getUsers(event.first, event.rows, event.filters.text?.[0]?.value))
.then((data) => {
this.users = data.items ?? []
this.totalUsers = data.total ?? 0
Expand Down Expand Up @@ -471,12 +469,9 @@ export class UsersPageComponent implements OnInit, OnDestroy {
// We have no information about the user, so let's try to fetch it
// from the server.
// ToDo: Non-catches promise
this.usersApi
.getUser(userId)
.toPromise()
.then((data) => {
this.addUserTab(UserTabType.User, data)
})
lastValueFrom(this.usersApi.getUser(userId)).then((data) => {
this.addUserTab(UserTabType.User, data)
})
}
})
)
Expand All @@ -500,9 +495,7 @@ export class UsersPageComponent implements OnInit, OnDestroy {
}
const password = this.userForm.controls.userPassword.value
const account = { user, password }
this.usersApi
.createUser(account)
.toPromise()
lastValueFrom(this.usersApi.createUser(account))
.then((/* data */) => {
this.msgSrv.add({
severity: 'success',
Expand Down Expand Up @@ -539,9 +532,7 @@ export class UsersPageComponent implements OnInit, OnDestroy {
}
const password = this.userForm.controls.userPassword.value
const account = { user, password }
this.usersApi
.updateUser(account)
.toPromise()
lastValueFrom(this.usersApi.updateUser(account))
.then((/* data */) => {
this.msgSrv.add({
severity: 'success',
Expand Down Expand Up @@ -582,9 +573,7 @@ export class UsersPageComponent implements OnInit, OnDestroy {
* deleted.
*/
deleteUser() {
this.usersApi
.deleteUser(this.userTab.user.id)
.toPromise()
lastValueFrom(this.usersApi.deleteUser(this.userTab.user.id))
.then((/* data */) => {
this.msgSrv.add({
severity: 'success',
Expand Down

0 comments on commit 174f840

Please sign in to comment.