mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
[ACS-1198] - Use the redirectLogout route in case of sso (#1944)
* Use the redirectLogout route in case of sso * Add unit test for logout in basic and sso
This commit is contained in:
@@ -24,23 +24,22 @@
|
||||
*/
|
||||
|
||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { TranslateModule, TranslateLoader, TranslateFakeLoader } from '@ngx-translate/core';
|
||||
import { AppTestingModule } from '../../../testing/app-testing.module';
|
||||
import { LogoutComponent } from './logout.component';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { SetSelectedNodesAction } from '@alfresco/aca-shared/store';
|
||||
import { AppConfigService, AuthenticationService } from '@alfresco/adf-core';
|
||||
|
||||
describe('LogoutComponent', () => {
|
||||
let fixture: ComponentFixture<LogoutComponent>;
|
||||
let component: LogoutComponent;
|
||||
let store;
|
||||
let authService: AuthenticationService;
|
||||
let appConfig: AppConfigService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot({
|
||||
loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
|
||||
})
|
||||
],
|
||||
imports: [AppTestingModule],
|
||||
declarations: [LogoutComponent],
|
||||
providers: [
|
||||
{
|
||||
@@ -54,6 +53,8 @@ describe('LogoutComponent', () => {
|
||||
|
||||
store = TestBed.inject(Store);
|
||||
fixture = TestBed.createComponent(LogoutComponent);
|
||||
appConfig = TestBed.inject(AppConfigService);
|
||||
authService = TestBed.inject(AuthenticationService);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
@@ -63,4 +64,19 @@ describe('LogoutComponent', () => {
|
||||
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([]));
|
||||
});
|
||||
|
||||
it('should return the login route in case of basic auth', () => {
|
||||
spyOn(authService, 'isOauth').and.returnValue(false);
|
||||
|
||||
const redirectLogout = component.getLogoutRedirectUri();
|
||||
expect(redirectLogout).toEqual('/login');
|
||||
});
|
||||
|
||||
it('should return the value of redirectUriLogout as route in case of SSO auth', () => {
|
||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||
appConfig.config['oauth2.redirectUriLogout'] = 'fake-logout';
|
||||
|
||||
const redirectLogout = component.getLogoutRedirectUri();
|
||||
expect(redirectLogout).toEqual('fake-logout');
|
||||
});
|
||||
});
|
||||
|
@@ -26,18 +26,27 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AppStore, SetSelectedNodesAction } from '@alfresco/aca-shared/store';
|
||||
import { AppConfigService, AuthenticationService } from '@alfresco/adf-core';
|
||||
|
||||
@Component({
|
||||
selector: 'aca-logout',
|
||||
template: `
|
||||
<button mat-menu-item (click)="onLogoutEvent()" adf-logout>
|
||||
<button mat-menu-item (click)="onLogoutEvent()" adf-logout [redirectUri]="getLogoutRedirectUri()">
|
||||
<mat-icon>exit_to_app</mat-icon>
|
||||
<span>{{ 'APP.SIGN_OUT' | translate }}</span>
|
||||
</button>
|
||||
`
|
||||
})
|
||||
export class LogoutComponent {
|
||||
constructor(private store: Store<AppStore>) {}
|
||||
constructor(private store: Store<AppStore>, private appConfig: AppConfigService, private auth: AuthenticationService) {}
|
||||
|
||||
getLogoutRedirectUri() {
|
||||
if (this.auth.isOauth()) {
|
||||
const logoutRedirect = this.appConfig.get<string>('oauth2.redirectUriLogout');
|
||||
return logoutRedirect;
|
||||
}
|
||||
return '/login';
|
||||
}
|
||||
|
||||
onLogoutEvent() {
|
||||
this.store.dispatch(new SetSelectedNodesAction([]));
|
||||
|
Reference in New Issue
Block a user