Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ exports[`usePatternFlyDocsTool, callback should attempt to parse parameters, mul

exports[`usePatternFlyDocsTool, callback should attempt to parse parameters, single file, mock path 1`] = `"# Content for components/button.md"`;

exports[`usePatternFlyDocsTool, callback should attempt to parse parameters, with invalid urlList 1`] = `"# Content for invalid-path"`;

exports[`usePatternFlyDocsTool, callback should attempt to parse parameters, with name and actual path 1`] = `"# Content for documentation:chatbot/README.md"`;

exports[`usePatternFlyDocsTool, callback should have a specific markdown format: Button 1`] = `
Expand Down
27 changes: 26 additions & 1 deletion src/__tests__/server.assertions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,31 @@ describe('assertInputStringNumberEnumLike', () => {

describe('assertInputUrlWhiteListed', () => {
it.each([
{
description: 'empty string',
input: '',
compare: ['https://patternfly.org']
},
{
description: 'undefined',
input: undefined,
compare: ['https://patternfly.org']
},
{
description: 'null',
input: null,
compare: ['https://patternfly.org']
},
{
description: 'number',
input: 1,
compare: ['https://patternfly.org']
},
{
description: 'string',
input: 'lorem ipsum',
compare: ['https://patternfly.org']
},
{
description: 'URL and display name',
input: 'https://github.com/patternfly',
Expand Down Expand Up @@ -322,7 +347,7 @@ describe('assertInputUrlWhiteListed', () => {
const errorMessage = 'Lorem ipsum error message for validation.';

expect(() => assertInputUrlWhiteListed(
'https://github.com/patternfly',
false,
['http://patternfly.org'],
{ message: errorMessage, codeOrError: (message, cause) => new Error(`Custom: ${message}`, { cause }) }
)).toThrow(`Custom: ${errorMessage}`);
Expand Down
16 changes: 6 additions & 10 deletions src/__tests__/tool.patternFlyDocs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,19 @@ describe('usePatternFlyDocsTool, callback', () => {
path: 'components/button.md',
content: 'single documentation content'
},
urlList: ['components/button.md']
urlList: ['https://www.patternfly.org/components/button.md']
},
{
description: 'multiple files, mock paths',
processedValue: {
path: 'components/button.md',
content: 'combined documentation content'
},
urlList: ['components/button.md', 'components/card.md', 'components/table.md']
},
{
description: 'with invalid urlList',
processedValue: {
path: 'invalid-path',
content: 'Failed to load'
},
urlList: ['invalid-url']
urlList: [
'https://www.patternfly.org/components/button.md',
'https://www.patternfly.org/components/card.md',
'https://www.patternfly.org/components/table.md'
]
},
{
description: 'with name and actual path',
Expand Down
9 changes: 7 additions & 2 deletions src/server.assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,18 @@ function assertInputUrlWhiteListed(

updatedInput.forEach(url => {
const isRemote = typeof url === 'string' && allowedProtocols.some(protocol => url.startsWith(protocol));
const isPfUri = isPatternFlyUri(url);

if (isRemote) {
// Dive into condition to avoid flipping else
if (!isWhitelistedUrl(url, whitelist, { allowedProtocols })) {
invalidUrls.push(url);
}
} else if (isUrl(url, { isStrict: false }) && !isPfUri) {
} else if (isUrl(url, { isStrict: false })) {
// Dive into condition to avoid flipping else
if (!isPatternFlyUri(url)) {
invalidUrls.push(url);
}
} else {
invalidUrls.push(url);
}
});
Expand Down
Loading