@exdst-sitecore-content-sdk/astro 0.0.24 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -12
- package/src/context.ts +1 -1
- package/src/client/sitecore-astro-client.test.ts +0 -267
- package/src/components/AstroImage.astro.test.ts +0 -541
- package/src/components/Date.astro.test.ts +0 -197
- package/src/components/EditingScripts.astro.test.ts +0 -267
- package/src/components/ErrorBoundary.astro.test.ts +0 -252
- package/src/components/ErrorComponent.astro.test.ts +0 -31
- package/src/components/FieldMetadata.astro.test.ts +0 -40
- package/src/components/File.astro.test.ts +0 -68
- package/src/components/HiddenRendering.astro.test.ts +0 -36
- package/src/components/Image.astro.test.ts +0 -438
- package/src/components/Link.astro.test.ts +0 -261
- package/src/components/MissingComponent.astro.test.ts +0 -21
- package/src/components/Placeholder/Placeholder.astro.test.ts +0 -1088
- package/src/components/Placeholder/PlaceholderMetadata.astro.test.ts +0 -228
- package/src/components/Placeholder/PlaceholderUtils.astro.test.ts +0 -149
- package/src/components/Placeholder/placeholder-utils.test.ts +0 -309
- package/src/components/RichText.astro.test.ts +0 -205
- package/src/components/Text.astro.test.ts +0 -273
- package/src/config/define-config.test.ts +0 -526
- package/src/config-cli/define-cli-config.test.ts +0 -67
- package/src/editing/editing-config-middleware.test.ts +0 -164
- package/src/editing/editing-render-middleware.test.ts +0 -1143
- package/src/editing/render-middleware.test.ts +0 -57
- package/src/editing/utils.test.ts +0 -1212
- package/src/enhancers/WithEmptyFieldEditingComponent.astro.test.ts +0 -380
- package/src/enhancers/WithFieldMetadata.astro.test.ts +0 -113
- package/src/middleware/middleware.test.ts +0 -520
- package/src/middleware/multisite-middleware.test.ts +0 -736
- package/src/middleware/robots-middleware.test.ts +0 -129
- package/src/middleware/sitemap-middleware.test.ts +0 -184
- package/src/tests/astro-helpers.ts +0 -61
- package/src/tests/helpers.ts +0 -46
- package/src/tests/personalizeData.ts +0 -63
- package/src/tests/test-components/CustomErrorComponent.astro +0 -3
- package/src/tests/test-components/CustomHiddenRendering.astro +0 -10
- package/src/tests/test-components/CustomMissingComponent.astro +0 -9
- package/src/tests/test-components/DownloadCallout.astro +0 -12
- package/src/tests/test-components/EmptyFieldEditingComponent.astro +0 -5
- package/src/tests/test-components/ErrorBoundaryWithError.astro +0 -10
- package/src/tests/test-components/Home.astro +0 -12
- package/src/tests/test-components/SxaRichText.astro +0 -23
- package/src/tests/test-components/SxaRichTextDefault.astro +0 -7
- package/src/tests/test-components/SxaRichTextWithTitle.astro +0 -8
- package/src/tests/test-components/TestComponent.astro +0 -9
- package/src/tests/test-components/TestComponentWithError.astro +0 -4
- package/src/tests/test-components/TestComponentWithField.astro +0 -17
- package/src/tests/test-components/TestHeader.astro +0 -8
- package/src/tests/test-components/TestLogo.astro +0 -5
- package/src/tests/test-components/TestParentWrapperComponent.astro +0 -5
- package/src/tests/test-components/TestWrapperComponent.astro +0 -5
- package/src/tests/test-components/generate-map/Button.astro +0 -4
- package/src/tests/test-components/generate-map/Link.astro +0 -4
- package/src/tests/test-components/map-components/Bar.astro +0 -0
- package/src/tests/test-components/map-components/Baz.astro +0 -0
- package/src/tests/test-components/map-components/Foo.astro +0 -0
- package/src/tests/test-components/map-components/Hero.variant.astro +0 -0
- package/src/tests/test-components/map-components/NotComponent.bsx +0 -0
- package/src/tests/test-components/map-components/Qux.astro +0 -0
- package/src/tests/test-components/map-components/folded/Folded.astro +0 -0
- package/src/tests/test-components/map-components/folded/random-file-2.docx +0 -0
- package/src/tests/test-components/map-components/random-file.txt +0 -0
- package/src/tests/test-data/metadata-data.ts +0 -86
- package/src/tests/test-data/normal-mode-data.ts +0 -466
- package/src/tests/vitest.setup.ts +0 -4
- package/src/tools/generate-map.test.ts +0 -201
- package/src/tools/templating/components.test.ts +0 -318
- package/src/tools/templating/default-component.test.ts +0 -31
- package/src/utils/utils.test.ts +0 -111
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-expressions */
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import { EditingConfigMiddleware } from './editing-config-middleware';
|
|
4
|
-
import { QUERY_PARAM_EDITING_SECRET } from '@sitecore-content-sdk/content/editing';
|
|
5
|
-
import { AstroContentSdkComponent } from '../sharedTypes/component-props';
|
|
6
|
-
import { mockRequest as MockRequest, Query } from '../tests/helpers';
|
|
7
|
-
|
|
8
|
-
const allowedOrigin = 'https://allowed.com';
|
|
9
|
-
|
|
10
|
-
const mockRequest = (
|
|
11
|
-
method: string,
|
|
12
|
-
query?: Query,
|
|
13
|
-
headers?: { [key: string]: string }
|
|
14
|
-
) => {
|
|
15
|
-
return MockRequest({
|
|
16
|
-
query,
|
|
17
|
-
method,
|
|
18
|
-
headers: {
|
|
19
|
-
origin: allowedOrigin,
|
|
20
|
-
...headers,
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const componentsMap = new Map<string, AstroContentSdkComponent>();
|
|
26
|
-
componentsMap.set('TestComponentOne', () => {});
|
|
27
|
-
componentsMap.set('TestComponentTwo', () => {});
|
|
28
|
-
const metadata = { packages: { testPackageOne: '0.1.1' } };
|
|
29
|
-
|
|
30
|
-
const expectedResultWithMetadata = {
|
|
31
|
-
components: ['TestComponentOne', 'TestComponentTwo'],
|
|
32
|
-
packages: { testPackageOne: '0.1.1' },
|
|
33
|
-
editMode: 'metadata',
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const expectedResultForbidden = {
|
|
37
|
-
message: 'Missing or invalid editing secret',
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
describe('EditingConfigMiddleware', () => {
|
|
41
|
-
const secret = 'jss-editing-secret-mock';
|
|
42
|
-
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
process.env.SITECORE_EDITING_SECRET = secret;
|
|
45
|
-
process.env.JSS_ALLOWED_ORIGINS = allowedOrigin;
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
after(() => {
|
|
49
|
-
delete process.env.SITECORE_EDITING_SECRET;
|
|
50
|
-
delete process.env.JSS_ALLOWED_ORIGINS;
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should respond with 401 for missing secret', async () => {
|
|
54
|
-
const key = 'wrongkey';
|
|
55
|
-
const query = { key } as Query;
|
|
56
|
-
const req = mockRequest('GET', query);
|
|
57
|
-
|
|
58
|
-
const middleware = new EditingConfigMiddleware({
|
|
59
|
-
components: componentsMap,
|
|
60
|
-
metadata,
|
|
61
|
-
});
|
|
62
|
-
const handler = middleware.getHandler();
|
|
63
|
-
|
|
64
|
-
const res = await handler(req);
|
|
65
|
-
|
|
66
|
-
const body = await res.json();
|
|
67
|
-
expect(res.status).to.equal(401);
|
|
68
|
-
expect(body).to.deep.equal(expectedResultForbidden);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should stop request and return 401 when CORS match is not met', async () => {
|
|
72
|
-
const req = mockRequest('GET', {}, { origin: 'https://notallowed.com' });
|
|
73
|
-
const middleware = new EditingConfigMiddleware({
|
|
74
|
-
components: componentsMap,
|
|
75
|
-
metadata,
|
|
76
|
-
});
|
|
77
|
-
const handler = middleware.getHandler();
|
|
78
|
-
|
|
79
|
-
const res = await handler(req);
|
|
80
|
-
|
|
81
|
-
const body = await res.json();
|
|
82
|
-
expect(res.status).to.equal(401);
|
|
83
|
-
expect(body).to.deep.equal({ message: 'Invalid origin' });
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should respond with 401 for invalid secret', async () => {
|
|
87
|
-
const key = 'wrongkey';
|
|
88
|
-
const query = { key } as Query;
|
|
89
|
-
query[QUERY_PARAM_EDITING_SECRET] = 'wrongsekret';
|
|
90
|
-
const req = mockRequest('GET', query);
|
|
91
|
-
|
|
92
|
-
const middleware = new EditingConfigMiddleware({
|
|
93
|
-
components: componentsMap,
|
|
94
|
-
metadata,
|
|
95
|
-
});
|
|
96
|
-
const handler = middleware.getHandler();
|
|
97
|
-
|
|
98
|
-
const res = await handler(req);
|
|
99
|
-
|
|
100
|
-
const body = await res.json();
|
|
101
|
-
expect(res.status).to.equal(401);
|
|
102
|
-
expect(body).to.deep.equal(expectedResultForbidden);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should respond with 204 for preflight OPTIONS request', async () => {
|
|
106
|
-
const query = {} as Query;
|
|
107
|
-
query[QUERY_PARAM_EDITING_SECRET] = secret;
|
|
108
|
-
const req = mockRequest('OPTIONS', query);
|
|
109
|
-
|
|
110
|
-
const middleware = new EditingConfigMiddleware({
|
|
111
|
-
components: componentsMap,
|
|
112
|
-
metadata,
|
|
113
|
-
});
|
|
114
|
-
const handler = middleware.getHandler();
|
|
115
|
-
|
|
116
|
-
const res = await handler(req);
|
|
117
|
-
|
|
118
|
-
expect(res.headers.has('Access-Control-Allow-Origin')).to.be.true;
|
|
119
|
-
expect(res.headers.get('Access-Control-Allow-Origin')).to.include(allowedOrigin);
|
|
120
|
-
|
|
121
|
-
expect(res.headers.has('Access-Control-Allow-Methods')).to.be.true;
|
|
122
|
-
expect(res.headers.get('Access-Control-Allow-Methods')).to.include(
|
|
123
|
-
'GET, POST, OPTIONS, DELETE, PUT, PATCH'
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
expect(res.headers.has('Access-Control-Allow-Headers')).to.be.true;
|
|
127
|
-
expect(res.headers.get('Access-Control-Allow-Headers')).to.include(
|
|
128
|
-
'Content-Type, Authorization'
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
expect(res.status).to.equal(204);
|
|
132
|
-
expect(res.body).to.equal(null);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
const testEditingConfig = async (
|
|
136
|
-
components: Map<string, AstroContentSdkComponent>,
|
|
137
|
-
expectedResult: {
|
|
138
|
-
components: string[];
|
|
139
|
-
packages: { testPackageOne: string };
|
|
140
|
-
editMode: string;
|
|
141
|
-
}
|
|
142
|
-
) => {
|
|
143
|
-
const key = 'wrongkey';
|
|
144
|
-
const query = { key } as Query;
|
|
145
|
-
query[QUERY_PARAM_EDITING_SECRET] = secret;
|
|
146
|
-
const req = mockRequest('GET', query);
|
|
147
|
-
const middleware = new EditingConfigMiddleware({ components, metadata });
|
|
148
|
-
const handler = middleware.getHandler();
|
|
149
|
-
|
|
150
|
-
const res = await handler(req);
|
|
151
|
-
|
|
152
|
-
const body = await res.json();
|
|
153
|
-
expect(res.status).to.equal(200);
|
|
154
|
-
expect(body).to.deep.equal(expectedResult);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
it('should respond with 200 and return config data with components array as argument', async () => {
|
|
158
|
-
await testEditingConfig(componentsMap, expectedResultWithMetadata);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should respond with 200 and return config data with components map as argument', async () => {
|
|
162
|
-
await testEditingConfig(componentsMap, expectedResultWithMetadata);
|
|
163
|
-
});
|
|
164
|
-
});
|