Skip to content

Commit

Permalink
fix: don't try to access to /settings in user's pages
Browse files Browse the repository at this point in the history
APIM-6929
  • Loading branch information
michel-barret committed Sep 24, 2024
1 parent cae1d15 commit c8d7c5a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, ElementRef, forwardRef, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, ElementRef, forwardRef, Inject, Input, OnDestroy, OnInit } from "@angular/core";
import {
AbstractControl,
AsyncValidator,
Expand All @@ -32,11 +32,11 @@ import { filter, map, observeOn, startWith, take, takeUntil, tap } from 'rxjs/op
import { FocusMonitor } from '@angular/cdk/a11y';
import { asyncScheduler, Observable, of, Subject, zip } from 'rxjs';

import { PortalSettingsService } from '../../../../../services-ngx/portal-settings.service';
import { ApiService } from '../../../../../services-ngx/api.service';
import { PathV4 } from '../../../../../entities/management-api-v2';

const PATH_PATTERN_REGEX = new RegExp(/^\/[/.a-zA-Z0-9-_]*$/);
import { Constants } from '../../../../../entities/Constants';

const DEFAULT_LISTENER: PathV4 = {
path: '/',
Expand Down Expand Up @@ -94,22 +94,18 @@ export class GioFormListenersContextPathComponent implements OnInit, OnDestroy,
private readonly fm: FocusMonitor,
private readonly elRef: ElementRef,
protected readonly apiService: ApiService,
private readonly portalSettingsService: PortalSettingsService,
@Inject(Constants) public readonly constants: Constants,
) {
this.mainForm = new FormGroup({
listeners: this.listenerFormArray,
});
}

ngOnInit(): void {
this.portalSettingsService
.get()
.pipe(takeUntil(this.unsubscribe$))
.subscribe((settings) => {
this.contextPathPrefix = settings.portal.entrypoint.endsWith('/')
? settings.portal.entrypoint.slice(0, -1)
: settings.portal.entrypoint;
});
this.contextPathPrefix = this.constants.env.settings.portal.entrypoint;
if (this.contextPathPrefix.endsWith('/')) {
this.contextPathPrefix = this.constants.env.settings.portal.entrypoint.slice(0, -1);
}

this.listenerFormArray?.valueChanges
.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { GioFormListenersContextPathHarness } from './gio-form-listeners-context

import { CONSTANTS_TESTING, GioHttpTestingModule } from '../../../../../shared/testing';
import { AjsRootScope } from '../../../../../ajs-upgraded-providers';
import { PortalSettings } from '../../../../../entities/portal/portalSettings';
import { PathV4 } from '../../../../../entities/management-api-v2';

@Component({
Expand Down Expand Up @@ -57,6 +56,7 @@ describe('GioFormListenersContextPathModule', () => {
];

beforeEach(() => {
fakeConstants.env.settings.portal = { entrypoint: 'localhost' };
TestBed.configureTestingModule({
declarations: [TestComponent],
imports: [NoopAnimationsModule, GioFormListenersContextPathModule, MatIconTestingModule, ReactiveFormsModule, GioHttpTestingModule],
Expand All @@ -73,19 +73,9 @@ describe('GioFormListenersContextPathModule', () => {
testComponent = fixture.componentInstance;
httpTestingController = TestBed.inject(HttpTestingController);
fixture.detectChanges();
expectGetPortalSettings();
expectApiVerify();
});

afterEach(() => {
httpTestingController.verify({ ignoreCancelled: true });
});

const expectGetPortalSettings = () => {
const settings: PortalSettings = { portal: { entrypoint: 'localhost' } };
httpTestingController.expectOne({ url: `${CONSTANTS_TESTING.env.baseURL}/settings`, method: 'GET' }).flush(settings);
};

const expectApiVerify = (inError = false) => {
httpTestingController
.match({ url: `${CONSTANTS_TESTING.env.baseURL}/apis/verify`, method: 'POST' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@ describe('ApiProxyV4EntrypointsComponent', () => {
let httpTestingController: HttpTestingController;
let rootLoader: HarnessLoader;

const createComponent = async (environment: Environment, api: ApiV4, getPortalSettings = true, permissions?: string[]) => {
const createComponent = async (environment: Environment, api: ApiV4, permissions?: string[]) => {
await init(permissions);
fixture.detectChanges();

expectGetCurrentEnvironment(environment);
expectGetEntrypoints();
expectGetApi(api);

if (getPortalSettings) {
expectGetPortalSettings();
}
};

const init = async (permissions: string[] = ['api-definition-u', 'api-definition-r']) => {
Expand Down Expand Up @@ -123,7 +119,7 @@ describe('ApiProxyV4EntrypointsComponent', () => {
const API = fakeApiV4({ listeners: [{ type: 'SUBSCRIPTION', entrypoints: [{ type: 'webhook' }] }] });

beforeEach(async () => {
await createComponent(ENV, API, false);
await createComponent(ENV, API);
});

it('should not show context paths', async () => {
Expand Down Expand Up @@ -209,7 +205,6 @@ describe('ApiProxyV4EntrypointsComponent', () => {
const harness = await loader.getHarness(GioFormListenersVirtualHostHarness);
expect(harness).toBeDefined();
expect(await harness.getLastListenerRow().then((row) => row.pathInput.getValue())).toEqual('/context-path');
expectGetPortalSettings();
});
});

Expand Down Expand Up @@ -275,7 +270,6 @@ describe('ApiProxyV4EntrypointsComponent', () => {
const harness = await loader.getHarness(GioFormListenersContextPathHarness);
expect(harness).toBeDefined();
expect(await harness.getLastListenerRow().then((row) => row.pathInput.getValue())).toEqual('/context-path');
expectGetPortalSettings();
});
});

Expand Down Expand Up @@ -554,7 +548,7 @@ describe('ApiProxyV4EntrypointsComponent', () => {
});

beforeEach(async () => {
await createComponent(ENV, API, false);
await createComponent(ENV, API);
});

it('should ask for the context path', async () => {
Expand Down Expand Up @@ -607,7 +601,7 @@ describe('ApiProxyV4EntrypointsComponent', () => {
});

beforeEach(async () => {
await createComponent(ENV, API, undefined, ['api-definition-r']);
await createComponent(ENV, API, ['api-definition-r']);
});
it('should not show buttons that require permissions', async () => {
// switch to virtual host mode/context path mode
Expand Down Expand Up @@ -649,11 +643,6 @@ describe('ApiProxyV4EntrypointsComponent', () => {
httpTestingController.expectOne({ url: `${CONSTANTS_TESTING.env.v2BaseURL}/apis/${API_ID}`, method: 'GET' }).flush(api);
}

function expectGetPortalSettings(): void {
const settings: PortalSettings = { portal: { entrypoint: 'localhost' } };
httpTestingController.expectOne({ url: `${CONSTANTS_TESTING.env.baseURL}/settings`, method: 'GET' }).flush(settings);
}

function expectApiVerify(): void {
httpTestingController.match({ url: `${CONSTANTS_TESTING.env.baseURL}/apis/verify`, method: 'POST' });
}
Expand Down

0 comments on commit c8d7c5a

Please sign in to comment.