diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index aecc8eab..1b012a0f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,7 +1,7 @@ on: push: branches: - - release/** + - release jobs: container-image: diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index f1b99b2d..ef114f44 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -3,6 +3,8 @@ on: branches: - main pull_request: + branches: + - main types: [opened, synchronize, reopened] jobs: diff --git a/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.spec.ts b/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.spec.ts new file mode 100644 index 00000000..11003000 --- /dev/null +++ b/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.spec.ts @@ -0,0 +1,13 @@ +import { AuthenticationInterceptor } from './authentication.interceptor'; + +describe('AuthenticationInterceptor', () => { + it('should determine correctly whether authentication is required or not', () => { + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/api`)).toBeTrue(); + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/api/test`)).toBeTrue(); + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/api/test/identity`)).toBeTrue(); + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/api/identity`)).toBeFalse(); + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/api/identity/test`)).toBeFalse(); + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/something/api`)).toBeFalse(); + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/something/api/identity`)).toBeFalse(); + }); +}); diff --git a/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.ts b/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.ts index 9dc675e5..6c15ab3a 100644 --- a/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.ts +++ b/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.ts @@ -6,17 +6,14 @@ import { AuthenticationService } from '../services/authentication.service'; @Injectable() export class AuthenticationInterceptor implements HttpInterceptor { - private readonly apiRoutesPrefix = `${window.origin}/api`; - private readonly identityRoutesPrefix = `${window.origin}/api/identity`; - constructor(private readonly authenticationService: AuthenticationService) {} public intercept(request: HttpRequest, next: HttpHandler): Observable> { - // IDEA: The check below could maybe be improved with a regex. Also, the API route for changing the user data also - // requires authentication even though its path '/api/identity/user-data/' is excluded by the logic below. - const requireAuthentication = request.url.startsWith(this.apiRoutesPrefix) && !request.url.startsWith(this.identityRoutesPrefix); + if (!request.url.startsWith(window.origin)) { + return next.handle(request); + } - if (!requireAuthentication) { + if (!AuthenticationInterceptor.doesPathRequireAuthentication(request.url.substring(window.origin.length))) { return next.handle(request); } @@ -30,4 +27,8 @@ export class AuthenticationInterceptor implements HttpInterceptor { }) ); } + + public static doesPathRequireAuthentication(path: string): boolean { + return /^\/api(?!\/identity)/.test(path); + } } diff --git a/src/Turnierplan.App/Constants/TurnierplanMetadata.cs b/src/Turnierplan.App/Constants/TurnierplanMetadata.cs new file mode 100644 index 00000000..44d2f9d2 --- /dev/null +++ b/src/Turnierplan.App/Constants/TurnierplanMetadata.cs @@ -0,0 +1,13 @@ +namespace Turnierplan.App.Constants; + +internal static class TurnierplanMetadata +{ + public static readonly string Version = DetermineVersion(); + + private static string DetermineVersion() + { + var assemblyVersion = typeof(TurnierplanMetadata).Assembly.GetName().Version?.ToString(); + + return assemblyVersion?[..assemblyVersion.LastIndexOf('.')] ?? "?.?.?"; + } +} diff --git a/src/Turnierplan.App/Pages/Shared/_Layout.cshtml b/src/Turnierplan.App/Pages/Shared/_Layout.cshtml index 3ced4349..d13e07b9 100644 --- a/src/Turnierplan.App/Pages/Shared/_Layout.cshtml +++ b/src/Turnierplan.App/Pages/Shared/_Layout.cshtml @@ -1,4 +1,5 @@ - +@using Turnierplan.App.Constants + @@ -42,11 +43,11 @@
-