Skip to content

Commit adef285

Browse files
authoredOct 14, 2022
Merge pull request #667 from auth0/DXCDT-240-blank-logo-url-validation
DXCDT-240: Prevent empty `logo_url` update payload inclusion
2 parents af1ed12 + c8f17e0 commit adef285

File tree

3 files changed

+78
-6
lines changed

3 files changed

+78
-6
lines changed
 

‎src/tools/auth0/handlers/branding.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ export default class BrandingHandler extends DefaultHandler {
6969
}
7070

7171
async processChanges(assets: Assets) {
72-
// quit early if there's no branding to process.
7372
if (!assets.branding) return;
7473

75-
// remove templates, we only want top level branding settings for this API call
7674
const { templates, ...brandingSettings } = assets.branding;
7775

78-
// Do nothing if not set
76+
if (brandingSettings.logo_url === '') {
77+
//Sometimes blank logo_url returned by API but is invalid on import. See: DXCDT-240
78+
delete brandingSettings.logo_url;
79+
}
80+
7981
if (brandingSettings && Object.keys(brandingSettings).length) {
8082
await this.client.branding.updateSettings({}, brandingSettings);
8183
this.updated += 1;

‎src/types.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,11 @@ export type Asset = { [key: string]: any };
208208
export type Assets = Partial<{
209209
actions: Action[] | null;
210210
attackProtection: Asset | null;
211-
branding: {
212-
templates?: { template: string; body: string }[] | null;
213-
} | null;
211+
branding:
212+
| (Asset & {
213+
templates?: { template: string; body: string }[] | null;
214+
})
215+
| null;
214216
clients: Asset[] | null;
215217
clientGrants: Asset[] | null;
216218
connections: Asset[] | null;

‎test/tools/auth0/handlers/branding.tests.js

+68
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,74 @@ describe('#branding handler', () => {
156156
]);
157157
});
158158

159+
it('should ignore empty string `logo_url` during update', async () => {
160+
let wasUpdateCalled = false;
161+
162+
const auth0 = {
163+
branding: {
164+
updateSettings: (_params, data) => {
165+
expect(data).to.deep.equal({
166+
colors: {
167+
primary: '#F8F8F2',
168+
page_background: '#112',
169+
},
170+
font: {
171+
url: 'https://mycompany.org/font/myfont.ttf',
172+
},
173+
});
174+
expect(data.logo_url).to.be.undefined; // eslint-disable-line no-unused-expressions
175+
wasUpdateCalled = true;
176+
},
177+
},
178+
};
179+
180+
const handler = new branding.default({ client: auth0 });
181+
const stageFn = Object.getPrototypeOf(handler).processChanges;
182+
183+
await stageFn.apply(handler, [
184+
{
185+
branding: {
186+
logo_url: '', // Note the empty string
187+
colors: {
188+
primary: '#F8F8F2',
189+
page_background: '#112',
190+
},
191+
font: {
192+
url: 'https://mycompany.org/font/myfont.ttf',
193+
},
194+
},
195+
},
196+
]);
197+
198+
expect(wasUpdateCalled).to.equal(true);
199+
});
200+
201+
it('should not send updateSettings request if empty object passed', async () => {
202+
let wasUpdateCalled = false;
203+
204+
const auth0 = {
205+
branding: {
206+
updateSettings: () => {
207+
wasUpdateCalled = true;
208+
throw new Error(
209+
'updateSettings should not have been called because omitted `logo_url` means that no API request needs to be made.'
210+
);
211+
},
212+
},
213+
};
214+
215+
const handler = new branding.default({ client: auth0 });
216+
const stageFn = Object.getPrototypeOf(handler).processChanges;
217+
218+
await stageFn.apply(handler, [
219+
{
220+
branding: {},
221+
},
222+
]);
223+
224+
expect(wasUpdateCalled).to.equal(false);
225+
});
226+
159227
it('should not throw, and be no-op if branding not set in context', async () => {
160228
const auth0 = {
161229
branding: {

0 commit comments

Comments
 (0)
Please sign in to comment.