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

[Branding] prevent logging when config not set #941

Merged
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
5 changes: 5 additions & 0 deletions src/core/server/rendering/rendering_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ describe('RenderingService', () => {
const result = await service.isUrlValid('http://notfound.svg', 'config');
expect(result).toEqual(false);
});

it('checks default URL returns false', async () => {
const result = await service.isUrlValid('/', 'config');
expect(result).toEqual(false);
});
});

describe('isTitleValid()', () => {
Expand Down
19 changes: 13 additions & 6 deletions src/core/server/rendering/rendering_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,21 @@ export class RenderingService {
* @returns {boolean} indicate if the URL is valid/invalid
*/
public isUrlValid = async (url: string, configName?: string): Promise<boolean> => {
if (url === '/') {
kavilla marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
if (url.match(/\.(png|svg|gif|PNG|SVG|GIF)$/) === null) {
this.logger.get('branding').info(configName + ' config is not found or invalid.');
this.logger.get('branding').error(`${configName} config is invalid. Using default branding.`);
return false;
}
return await Axios.get(url, { adapter: AxiosHttpAdapter, maxRedirects: 0 })
.then(() => {
return true;
})
.catch(() => {
this.logger.get('branding').info(configName + ' config is not found or invalid');
this.logger
.get('branding')
.error(`${configName} URL was not found or invalid. Using default branding.`);
return false;
});
};
Expand All @@ -338,12 +343,14 @@ export class RenderingService {
* @returns {boolean} indicate if user input title is valid/invalid
*/
public isTitleValid = (title: string, configName?: string): boolean => {
if (!title || title.length > 36) {
if (!title) {
return false;
kavilla marked this conversation as resolved.
Show resolved Hide resolved
}
if (title.length > 36) {
this.logger
.get('branding')
.info(
configName +
' config is not found or invalid. Title length should be between 1 to 36 characters.'
.error(
`${configName} config is not found or invalid. Title length should be between 1 to 36 characters. Using default title.`
);
return false;
}
Expand Down