From c4e8387e010278c1c8506f684fbab4abd42c0d61 Mon Sep 17 00:00:00 2001 From: milanmajchrak <90026355+milanmajchrak@users.noreply.github.com> Date: Wed, 6 Dec 2023 07:31:33 +0100 Subject: [PATCH] ufal/fe-shibboleth-validate-emails * Encoded query params (#407) --- .../auth-failed-page.component.spec.ts | 97 +++++++++++++++++++ .../auth-failed-page.component.ts | 6 +- 2 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 src/app/login-page/auth-failed-page/auth-failed-page.component.spec.ts diff --git a/src/app/login-page/auth-failed-page/auth-failed-page.component.spec.ts b/src/app/login-page/auth-failed-page/auth-failed-page.component.spec.ts new file mode 100644 index 00000000000..a60ff1163e5 --- /dev/null +++ b/src/app/login-page/auth-failed-page/auth-failed-page.component.spec.ts @@ -0,0 +1,97 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { of as observableOf} from 'rxjs'; +import { ActivatedRoute } from '@angular/router'; +import { ConfigurationDataService } from '../../core/data/configuration-data.service'; +import {createSuccessfulRemoteDataObject$} from '../../shared/remote-data.utils'; +import { ConfigurationProperty } from '../../core/shared/configuration-property.model'; +import { HELP_DESK_PROPERTY } from '../../item-page/tombstone/tombstone.component'; +import { TranslateModule } from '@ngx-translate/core'; +import { AuthFailedPageComponent } from './auth-failed-page.component'; +import { RequestService } from '../../core/data/request.service'; +import { HALEndpointService } from '../../core/shared/hal-endpoint.service'; +import { getMockRemoteDataBuildService } from '../../shared/mocks/remote-data-build.service.mock'; +import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service'; +import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub'; +import { NotificationsService } from '../../shared/notifications/notifications.service'; + +describe('DuplicateUserErrorComponent', () => { + let component: AuthFailedPageComponent; + let fixture: ComponentFixture; + let mockConfigurationDataService: ConfigurationDataService; + let requestService: RequestService; + let activatedRoute: any; + let halService: HALEndpointService; + let rdbService: RemoteDataBuildService; + let notificationService: NotificationsServiceStub; + + const rootUrl = 'root url'; + const queryParams = 'netid[idp]'; + const encodedQueryParams = 'netid%5Bidp%5D&email='; + + activatedRoute = { + params: observableOf({}), + snapshot: { + queryParams: { + netid: queryParams + } + } + }; + + mockConfigurationDataService = jasmine.createSpyObj('configurationDataService', { + findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), { + name: HELP_DESK_PROPERTY, + values: [ + 'email' + ] + })) + }); + + requestService = jasmine.createSpyObj('requestService', { + send: observableOf('response'), + generateRequestId: observableOf('123456'), + }); + + halService = jasmine.createSpyObj('authService', { + getRootHref: rootUrl, + }); + + rdbService = getMockRemoteDataBuildService(); + notificationService = new NotificationsServiceStub(); + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ + TranslateModule.forRoot() + ], + declarations: [ AuthFailedPageComponent ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRoute }, + { provide: ConfigurationDataService, useValue: mockConfigurationDataService }, + { provide: RequestService, useValue: requestService }, + { provide: HALEndpointService, useValue: halService }, + { provide: RemoteDataBuildService, useValue: rdbService }, + { provide: NotificationsService, useValue: notificationService }, + ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(AuthFailedPageComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it('should send request with encoded netId and email param', () => { + component.ngOnInit(); + component.sendEmail(); + expect(requestService.send).toHaveBeenCalledWith(jasmine.objectContaining({ + href: rootUrl + '/autoregistration?netid=' + encodedQueryParams, + })); + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/login-page/auth-failed-page/auth-failed-page.component.ts b/src/app/login-page/auth-failed-page/auth-failed-page.component.ts index 24ff567ca4f..b49e3b9b368 100644 --- a/src/app/login-page/auth-failed-page/auth-failed-page.component.ts +++ b/src/app/login-page/auth-failed-page/auth-failed-page.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; +import { ActivatedRoute } from '@angular/router'; import { Observable } from 'rxjs'; import { RemoteData } from '../../core/data/remote-data'; import { ConfigurationProperty } from '../../core/shared/configuration-property.model'; @@ -42,7 +42,6 @@ export class AuthFailedPageComponent implements OnInit { constructor( protected configurationDataService: ConfigurationDataService, - protected router: Router, public route: ActivatedRoute, private requestService: RequestService, protected halService: HALEndpointService, @@ -61,7 +60,8 @@ export class AuthFailedPageComponent implements OnInit { public sendEmail() { const requestId = this.requestService.generateRequestId(); - const url = this.halService.getRootHref() + '/autoregistration?netid=' + this.netid + '&email=' + this.email; + const url = this.halService.getRootHref() + '/autoregistration?netid=' + encodeURIComponent(this.netid) + + '&email=' + encodeURIComponent(this.email); const postRequest = new PostRequest(requestId, url); // Send POST request this.requestService.send(postRequest);