Skip to content

Commit

Permalink
[XM Cloud][Next.js] Editing Configuration Endpoint - fix forbidden r…
Browse files Browse the repository at this point in the history
…esponse for Vercel (#1734)

* update response for invalid secret

* adjust unit tests and small fix

* update changelog

* remove redundant lines in test file
  • Loading branch information
yavorsk authored Feb 13, 2024
1 parent 15c24e9 commit c144a05
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Our versioning strategy is as follows:
* `[sitecore-jss]` `[templates/nextjs-xmcloud]` Load the content styles for the RichText component ([#1670](https://github.com/Sitecore/jss/pull/1670))([#1683](https://github.com/Sitecore/jss/pull/1683)) ([#1684](https://github.com/Sitecore/jss/pull/1684)) ([#1693](https://github.com/Sitecore/jss/pull/1693))
* `[templates/react]` `[sitecore-jss-react]` Replace package 'deep-equal' with 'fast-deep-equal'. No functionality change only performance improvement ([#1719](https://github.com/Sitecore/jss/pull/1719)) ([#1665](https://github.com/Sitecore/jss/pull/1665))
* `[templates/nextjs-xmcloud]` `[sitecore-jss]` `[sitecore-jss-nextjs]` `[sitecore-jss-react]` Add support for loading appropriate stylesheets whenever a theme is applied to BYOC and SXA components by introducing new function getComponentLibraryStylesheetLinks, which replaces getFEAASLibraryStylesheetLinks (which has been marked as deprecated) ([#1722](https://github.com/Sitecore/jss/pull/1722))
* `[templates/nextjs-xmcloud]` `[sitecore-jss-nextjs]` Add protected endpoint which provides configuration information (the sitecore packages used by the app and all registered components) to be used to determine feature compatibility on Pages side. ([#1724](https://github.com/Sitecore/jss/pull/1724))
* `[templates/nextjs-xmcloud]` `[sitecore-jss-nextjs]` Add protected endpoint which provides configuration information (the sitecore packages used by the app and all registered components) to be used to determine feature compatibility on Pages side. ([#1724](https://github.com/Sitecore/jss/pull/1724) [#1734](https://github.com/Sitecore/jss/pull/1734))
* `[sitecore-jss-nextjs]` `[templates/nextjs]` [BYOC] Component Builder integration endpoint ([#1729](https://github.com/Sitecore/jss/pull/1729))

### 🐛 Bug Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ const mockResponse = () => {
res.json = spy(() => {
return res;
});
res.end = spy(() => {
return res;
});
return res;
};

Expand All @@ -40,6 +37,7 @@ const expectedResult = {
components: ['TestComponentOne', 'TestComponentTwo'],
packages: { testPackageOne: '0.1.1' },
};
const expectedResultForbidden = { message: 'Missing or invalid editing secret' };

describe('EditingConfigMiddleware', () => {
const secret = 'jss-editing-secret-mock';
Expand All @@ -64,7 +62,8 @@ describe('EditingConfigMiddleware', () => {
await handler(req, res);

expect(res.status).to.have.been.calledWith(401);
expect(res.end).to.have.been.calledOnce;
expect(res.json).to.have.been.calledOnce;
expect(res.json).to.have.been.calledWith(expectedResultForbidden);
});

it('should respond with 401 for invalid secret', async () => {
Expand All @@ -80,7 +79,8 @@ describe('EditingConfigMiddleware', () => {
await handler(req, res);

expect(res.status).to.have.been.calledWith(401);
expect(res.end).to.have.been.calledOnce;
expect(res.json).to.have.been.calledOnce;
expect(res.json).to.have.been.calledWith(expectedResultForbidden);
});

it('should respond with 200 and return config data with components array as argument', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class EditingConfigMiddleware {
getJssEditingSecret()
);

res.status(401).end('Missing or invalid editing secret');
return res.status(401).json({ message: 'Missing or invalid editing secret' });
}

const components = Array.isArray(this.config.components)
Expand Down

0 comments on commit c144a05

Please sign in to comment.