Skip to content

Commit c17d2cb

Browse files
fix: align link checker config behavior
1 parent 6bd21e9 commit c17d2cb

5 files changed

Lines changed: 119 additions & 9 deletions

File tree

apps/link-checker/__tests__/locations/Page.spec.tsx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,69 @@ describe('Page component', () => {
7676

7777
await screen.findByText('https://example.invalid/not-found');
7878
});
79+
80+
it('does not implicitly allow the current domain when the allow list is configured', async () => {
81+
mockSdk.parameters.installation = {
82+
selectedContentTypeIds: ['article'],
83+
baseUrl: 'https://contentful.com',
84+
allowedUrlPatterns: 'ally.com',
85+
};
86+
mockSdk.cma = {
87+
contentType: {
88+
getMany: jest.fn().mockResolvedValue({
89+
items: [
90+
{
91+
sys: { id: 'article' },
92+
name: 'Article',
93+
displayField: 'title',
94+
fields: [
95+
{ id: 'title', name: 'Title', type: 'Symbol' },
96+
{ id: 'body', name: 'Body', type: 'Text' },
97+
],
98+
},
99+
],
100+
}),
101+
},
102+
entry: {
103+
getMany: jest.fn().mockResolvedValue({
104+
items: [
105+
{
106+
sys: {
107+
id: 'entry-1',
108+
contentType: { sys: { id: 'article' } },
109+
},
110+
fields: {
111+
title: { 'en-US': 'Release Notes' },
112+
body: { 'en-US': 'Visit /help' },
113+
},
114+
},
115+
],
116+
}),
117+
},
118+
appAction: {
119+
getMany: jest.fn().mockResolvedValue({
120+
items: [
121+
{
122+
sys: {
123+
id: 'check-link-action',
124+
appDefinition: { sys: { id: mockSdk.ids.app } },
125+
},
126+
function: { sys: { id: 'checkLink' } },
127+
},
128+
],
129+
}),
130+
},
131+
appActionCall: {
132+
createWithResponse: jest.fn(),
133+
},
134+
};
135+
136+
render(<Page />);
137+
fireEvent.click(screen.getByRole('button', { name: 'Run scan' }));
138+
139+
await screen.findByText('/help');
140+
await screen.findByText(/not on allow list/i);
141+
expect(screen.getByText(/resolves to https:\/\/contentful.com\/help/i)).toBeInTheDocument();
142+
expect(mockSdk.cma.appActionCall.createWithResponse).not.toHaveBeenCalled();
143+
});
79144
});

apps/link-checker/__tests__/locations/Sidebar.spec.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,55 @@ describe('Sidebar component', () => {
7676
expect(createWithResponse).not.toHaveBeenCalled();
7777
});
7878

79+
it('does not implicitly allow the current domain when the allow list is configured', async () => {
80+
const createWithResponse = jest.fn();
81+
82+
mockSdk.parameters.installation = {
83+
baseUrl: 'https://contentful.com',
84+
allowedUrlPatterns: 'ally.com',
85+
};
86+
mockSdk.entry.fields = {
87+
body: {
88+
id: 'body',
89+
name: 'Body',
90+
type: 'Text',
91+
locales: ['en-US'],
92+
getValue: () => 'Visit /help for more details.',
93+
},
94+
};
95+
mockSdk.cma = {
96+
appAction: {
97+
getMany: jest.fn().mockResolvedValue({
98+
items: [
99+
{
100+
sys: {
101+
id: 'check-link-action',
102+
appDefinition: { sys: { id: mockSdk.ids.app } },
103+
},
104+
function: { sys: { id: 'checkLink' } },
105+
},
106+
],
107+
}),
108+
},
109+
appActionCall: {
110+
createWithResponse,
111+
},
112+
};
113+
114+
render(<Sidebar />);
115+
116+
await act(async () => {
117+
fireEvent.click(screen.getByRole('button', { name: /check links/i }));
118+
});
119+
120+
await screen.findByText(/not on allow list/i);
121+
expect(screen.getByRole('link', { name: '/help' })).toHaveAttribute(
122+
'href',
123+
'https://contentful.com/help'
124+
);
125+
expect(createWithResponse).not.toHaveBeenCalled();
126+
});
127+
79128
it('shows only non-invalid results when remaining links are expanded', async () => {
80129
const createWithResponse = jest
81130
.fn()

apps/link-checker/components/locations/Page.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,7 @@ export default function Page() {
186186
.map((p) => normalizeDomainPattern(p))
187187
.filter(Boolean);
188188
const baseUrl = (installation.baseUrl || '').trim().replace(/\/$/, '') || null;
189-
const implicitBasePattern = baseUrl ? normalizeDomainPattern(baseUrl) : '';
190-
const allowedPatterns = Array.from(
191-
new Set([implicitBasePattern, ...explicitAllowedPatterns].filter(Boolean))
192-
);
189+
const allowedPatterns = explicitAllowedPatterns;
193190

194191
const loadAuditResults = useCallback(async () => {
195192
setError(null);

apps/link-checker/components/locations/Sidebar.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ export default function Sidebar() {
118118
.map((p) => normalizeDomainPattern(p))
119119
.filter(Boolean);
120120
const baseUrl = (installation.baseUrl || '').trim().replace(/\/$/, '') || null;
121-
const implicitBasePattern = baseUrl ? normalizeDomainPattern(baseUrl) : '';
122-
const allowedPatterns = Array.from(
123-
new Set([implicitBasePattern, ...explicitAllowedPatterns].filter(Boolean))
124-
);
121+
const allowedPatterns = explicitAllowedPatterns;
125122

126123
useAutoResizer();
127124

apps/link-checker/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"add-locations": "contentful-app-scripts add-locations",
1818
"build:functions": "contentful-app-scripts build-functions --ci",
1919
"build:all": "npm run build && npm run build:functions && node -e \"require('fs').mkdirSync('out/functions', {recursive: true}); require('fs').cpSync('build/functions', 'out/functions', {recursive: true})\"",
20+
"deploy": "npm run build:all && contentful-app-scripts upload --ci --bundle-dir ./out --organization-id ${DEFINITIONS_ORG_ID} --definition-id 5Sr53r0O6UqTBrp0I9S3OV --token ${CONTENTFUL_CMA_TOKEN}",
21+
"deploy:test": "npm run build:all && contentful-app-scripts upload --ci --bundle-dir ./out --organization-id ${DEV_TESTING_ORG_ID} --definition-id 5Sr53r0O6UqTBrp0I9S3OV --token ${TEST_CMA_TOKEN}",
2022
"upload": "node scripts/upload-with-env.js",
2123
"upsert-actions": "node scripts/upsert-actions-with-env.js",
2224
"build-and-upload": "npm run build:all && npm run upload && npm run upsert-actions"
@@ -45,4 +47,4 @@
4547
"jest-environment-jsdom": "29.5.0",
4648
"typescript": "5.1.6"
4749
}
48-
}
50+
}

0 commit comments

Comments
 (0)