Skip to content

Conversation

@uroslates
Copy link
Contributor

@uroslates uroslates requested a review from a team as a code owner September 30, 2025 09:53
@github-actions github-actions bot marked this pull request as draft September 30, 2025 09:53
@uroslates
Copy link
Contributor Author

Changing password expiration rules for testing purpose (can be tricky - since targets all system users).

Workaround for handing this can be following:

  1. Create mocked interceptor similar to below and provide it in your app module (as specified in class docs below):
import {
  HttpErrorResponse,
  HttpEvent,
  HttpHandler,
  HttpInterceptor,
  HttpRequest,
} from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, throwError } from 'rxjs';

/**
 * This interceptor is used to mock HTTP responses for specific API endpoints.
 *
 * It intercepts HTTP requests and returns mock data for the defined endpoints,
 * while allowing other requests to pass through unmodified.
 *
 * To use this interceptor, provide it in your Angular module's providers array.
 * Example ([in app.module.ts](https://github.com/SAP/spartacus/blob/20b375201f22ecdff1ad850bccbae763969102a5/projects/storefrontapp/src/app/app.module.ts#L68)):
 * {
 *  provide: HTTP_INTERCEPTORS,
 *  useExisting: MockInterceptor,
 *  multi: true,
 * }
 */
@Injectable({ providedIn: 'root' })
export class MockInterceptor implements HttpInterceptor {
  intercept(
    req: HttpRequest<any>,
    next: HttpHandler
  ): Observable<HttpEvent<any>> {
    // Define the API endpoint you want to mock
    const OAUTH_ENDPOINT = '/authorizationserver/oauth/token';
    const mockUrl = OAUTH_ENDPOINT;

    if (req.url.endsWith(mockUrl)) {
      // Return mock data as an HTTP response
      const mockResponse = new HttpErrorResponse({
        status: 400,
        error: {
          error: 'invalid_grant',
          // error_description: "Bad credentials",
          error_description: 'Password expired for the user: John Doe',
        },
        url: req.url,
      });
      // Use throwError to simulate an error response
      return throwError(() => mockResponse);
    }

    // Pass through other requests unmodified
    return next.handle(req);
  }
}
  1. Trying to login will now trigger expected error.
  2. Verify tests are passing.

@uroslates uroslates marked this pull request as ready for review September 30, 2025 12:25
@github-actions
Copy link
Contributor

Merge Checks Failed

Please push a commit to re-trigger the build.
To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`

@github-actions github-actions bot marked this pull request as draft September 30, 2025 13:46
@uroslates uroslates marked this pull request as ready for review September 30, 2025 14:00
@cypress
Copy link

cypress bot commented Sep 30, 2025

spartacus    Run #50188

Run Properties:  status check passed Passed #50188  •  git commit 7fc44359bb ℹ️: Merge 9917c78c0a0062caacbfaf4a531966f9293a8e47 into 09dc2f3f19dd34e2c443e8c37331...
Project spartacus
Branch Review feature/CXSPA-10815
Run status status check passed Passed #50188
Run duration 03m 39s
Commit git commit 7fc44359bb ℹ️: Merge 9917c78c0a0062caacbfaf4a531966f9293a8e47 into 09dc2f3f19dd34e2c443e8c37331...
Committer Uros Lates
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 4
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 101
View all changes introduced in this branch ↗︎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants