From 7a6ed13edf60f626059cf477d620c54e93f2819e Mon Sep 17 00:00:00 2001 From: Michael Baumberger Date: Tue, 24 Dec 2024 14:15:37 +0100 Subject: [PATCH 1/2] Moved Designer.png to docs so service-worker doesn't fetch it as resource. Also renamed it to favicon.png. --- .../assets/icons/Designer.png => docs/favicon.png | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename website/src/assets/icons/Designer.png => docs/favicon.png (100%) diff --git a/website/src/assets/icons/Designer.png b/docs/favicon.png similarity index 100% rename from website/src/assets/icons/Designer.png rename to docs/favicon.png From 8668f61fcdd217afa1362801349dcdefd73016a8 Mon Sep 17 00:00:00 2001 From: Michael Baumberger Date: Tue, 24 Dec 2024 15:28:09 +0100 Subject: [PATCH 2/2] Pls finally cookie set fixed. resolves https://github.com/MichiBaum/Microservices/issues/114 --- website/src/app/app.config.ts | 4 +-- .../interceptors/auth-cookie.interceptor.ts | 15 ++++++++++ ...r.spec.ts => auth-jwt.interceptor.spec.ts} | 8 +++--- ...interceptor.ts => auth-jwt.interceptor.ts} | 2 +- website/src/app/login/login.spec.ts | 28 ++++++++++++------- 5 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 website/src/app/core/interceptors/auth-cookie.interceptor.ts rename website/src/app/core/interceptors/{auth.interceptor.spec.ts => auth-jwt.interceptor.spec.ts} (86%) rename website/src/app/core/interceptors/{auth.interceptor.ts => auth-jwt.interceptor.ts} (95%) diff --git a/website/src/app/app.config.ts b/website/src/app/app.config.ts index 6a12bde0..ea2ea37b 100644 --- a/website/src/app/app.config.ts +++ b/website/src/app/app.config.ts @@ -4,7 +4,7 @@ import {routes} from './app.routes'; import {HTTP_INTERCEPTORS, HttpClient, provideHttpClient, withInterceptorsFromDi} from "@angular/common/http"; import {InterpolatableTranslationObject, TranslateLoader, TranslateModule, TranslateService} from "@ngx-translate/core"; import {TranslateHttpLoader} from "@ngx-translate/http-loader"; -import {AuthInterceptor} from "./core/interceptors/auth.interceptor"; +import {AuthJwtInterceptor} from "./core/interceptors/auth-jwt.interceptor"; import {provideServiceWorker} from '@angular/service-worker'; import {IMAGE_LOADER, ImageLoaderConfig} from "@angular/common"; import {environment} from "../environments/environment"; @@ -73,7 +73,7 @@ export const appConfig: ApplicationConfig = { }), { provide : HTTP_INTERCEPTORS, - useClass: AuthInterceptor, + useClass: AuthJwtInterceptor, multi : true, }, TranslateModule.forRoot({ diff --git a/website/src/app/core/interceptors/auth-cookie.interceptor.ts b/website/src/app/core/interceptors/auth-cookie.interceptor.ts new file mode 100644 index 00000000..7abe7ef5 --- /dev/null +++ b/website/src/app/core/interceptors/auth-cookie.interceptor.ts @@ -0,0 +1,15 @@ +import {Injectable} from "@angular/core"; +import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http"; +import {Observable} from "rxjs"; + +@Injectable() +export class AuthCookieInterceptor implements HttpInterceptor{ + + intercept(req: HttpRequest, next: HttpHandler): Observable> { + const modifiedRequest = req.clone({ + withCredentials: true, + }); + return next.handle(modifiedRequest); + } + +} diff --git a/website/src/app/core/interceptors/auth.interceptor.spec.ts b/website/src/app/core/interceptors/auth-jwt.interceptor.spec.ts similarity index 86% rename from website/src/app/core/interceptors/auth.interceptor.spec.ts rename to website/src/app/core/interceptors/auth-jwt.interceptor.spec.ts index 87e5da99..9a5b5576 100644 --- a/website/src/app/core/interceptors/auth.interceptor.spec.ts +++ b/website/src/app/core/interceptors/auth-jwt.interceptor.spec.ts @@ -1,7 +1,7 @@ import {TestBed} from '@angular/core/testing'; -import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; +import {HttpTestingController, provideHttpClientTesting} from '@angular/common/http/testing'; import {HTTP_INTERCEPTORS, HttpClient} from '@angular/common/http'; -import {AuthInterceptor} from './auth.interceptor'; +import {AuthJwtInterceptor} from './auth-jwt.interceptor'; import {AuthService} from "../services/auth.service"; describe('AuthInterceptor', () => { @@ -13,9 +13,9 @@ describe('AuthInterceptor', () => { const authServiceSpy = jasmine.createSpyObj('AuthService', ['jwtIsPresent', 'getJwtTokenFromLocalStorage']); TestBed.configureTestingModule({ - imports: [HttpClientTestingModule], providers: [ - {provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true}, + provideHttpClientTesting(), + {provide: HTTP_INTERCEPTORS, useClass: AuthJwtInterceptor, multi: true}, {provide: AuthService, useValue: authServiceSpy} ] }); diff --git a/website/src/app/core/interceptors/auth.interceptor.ts b/website/src/app/core/interceptors/auth-jwt.interceptor.ts similarity index 95% rename from website/src/app/core/interceptors/auth.interceptor.ts rename to website/src/app/core/interceptors/auth-jwt.interceptor.ts index 7ed7971f..9f1e46c2 100644 --- a/website/src/app/core/interceptors/auth.interceptor.ts +++ b/website/src/app/core/interceptors/auth-jwt.interceptor.ts @@ -9,7 +9,7 @@ import {AuthService} from "../services/auth.service"; * if a JWT token is present. */ @Injectable() -export class AuthInterceptor implements HttpInterceptor { +export class AuthJwtInterceptor implements HttpInterceptor { private authService = inject(AuthService); /** diff --git a/website/src/app/login/login.spec.ts b/website/src/app/login/login.spec.ts index 339903db..24aad435 100644 --- a/website/src/app/login/login.spec.ts +++ b/website/src/app/login/login.spec.ts @@ -1,6 +1,6 @@ import {ComponentFixture, TestBed} from '@angular/core/testing'; import {FormsModule, ReactiveFormsModule} from '@angular/forms'; -import {HttpClientTestingModule} from '@angular/common/http/testing'; +import {provideHttpClientTesting} from '@angular/common/http/testing'; import {TranslateModule} from '@ngx-translate/core'; import {LoginComponent} from './login.component'; import {of} from 'rxjs'; @@ -22,10 +22,10 @@ describe('LoginComponent', () => { imports: [ ReactiveFormsModule, FormsModule, - HttpClientTestingModule, TranslateModule.forRoot() ], providers: [ + provideHttpClientTesting(), AuthService, HeaderService, RouterNavigationService @@ -50,26 +50,34 @@ describe('LoginComponent', () => { it('should not call authService.login if username or password is empty', () => { const loginSpy = spyOn(authService, 'login'); - component.username = ''; - component.password = ''; + component.loginForm.patchValue({ + username: '', + password: '' + }) component.login(); expect(loginSpy).not.toHaveBeenCalled(); - component.username = 'user'; - component.password = ''; + component.loginForm.patchValue({ + username: 'user', + password: '' + }) component.login(); expect(loginSpy).not.toHaveBeenCalled(); - component.username = ''; - component.password = 'pass'; + component.loginForm.patchValue({ + username: '', + password: 'pass' + }) component.login(); expect(loginSpy).not.toHaveBeenCalled(); }); it('should call authService.login if username and password are not empty', () => { const loginSpy = spyOn(authService, 'login'); - component.username = 'user'; - component.password = 'pass'; + component.loginForm.patchValue({ + username: 'user', + password: 'pass' + }) component.login(); expect(loginSpy).toHaveBeenCalledWith('user', 'pass'); });