Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XM Cloud][Next.js] Editing Configuration Endpoint - fix forbidden response for Vercel #1734

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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