Azure / Azure/api-management-developer-portal

Widgets consuming the getProduct call in the product service are causing malformed URLs

Open
#2,858 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
545
Forks
360
PR merge metrics
No merged PRs in 30d

Description

## Bug description

The way the productService.getProduct(productId: string) method is forming the URL seems incorrect when looking at the way the azure provided widgets are passing the ID to that method. All code pasted below is directly from azures developer portal repo from release tag 2.34.

```
public async getProduct(productId: string): Promise {
if (!productId) {
throw new Error(`Parameter "productId" not specified.`);
}

const contract = await this.apiClient.get(`/products/${productId}`, [await this.apiClient.getPortalHeader("getProduct"), Utils.getIsUserResourceHeader()]);

if (contract) {
return new Product(contract);
}
return undefined;
}
```
In the method, you can see it adds the "/products/" before the passed in productID in the GET api client call. However, the azure provided widgets, for example the Product Subscribe widget, passes in the ID with the "/product/" part already prepended. See below with a pasted copy of the call from the Product Subscribe widgets LoadProduct method.

```
const loadProduct = async (usersService: UsersService, delegationService: IDelegationService, productService: ProductService, productName: string) => {
const promises = [
await delegationService.isSubscriptionDelegationEnabled(),
await productService.getProduct(`products/${productName}`),
await usersService.getCurrentUserId(),
] as const;
const [isDelegationEnabled, product, userId] = await Promise.all(promises);
```

From what I can tell, all azure provided widgets that call the getProducts method prepend the "/products/" part when making the call to getProducts. So, this is resulting in 404s when the portal attempts to make these requests because the URL is formed like ".../products/products/{productName}"

## Reproduction steps

1) Use portal version 2.34
2) View the product page for a specific product as a authenticated user
3) The subscribe form will not be visible and the browsers dev tools will show 404 responses when trying to send the request to get the product

## Expected behavior

The get products URL should be formed correctly

## Is self-hosted portal?

Yes

## Release tag or commit SHA (if using self-hosted version)

2.34

## API Management service name

N/A

## Environment

N/A

## Additional context

Add any other context about the problem here, including screenshots.

Contributor guide

No contributing guide indexed for this repository

Research direction

Locate ProductService.getProduct and the Product Subscribe widget's loadProduct call, then reproduce the authenticated product-page request described for portal version 2.34. Compare the product ID format at the caller and service boundary. Done means the request contains one products path segment, returns successfully instead of 404, and the subscribe form is visible.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, typescript
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.