Skip to content

Commit 4e7398e

Browse files
authored
Fix confirmations/notifications validation and OAuth signature generation
Fix confirmations and notifications validation to accept objects
2 parents 958811a + 5bb0e78 commit 4e7398e

7 files changed

Lines changed: 69 additions & 39 deletions

File tree

scripts/setup-test-data.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,20 @@ const testForms = [
138138
button: {
139139
text: 'Send Message'
140140
},
141-
confirmations: [{
142-
type: 'message',
143-
message: '<p>Thank you for contacting us! We\'ll respond within 24 hours.</p>'
144-
}],
145-
notifications: [{
146-
name: 'Admin Notification',
147-
to: '{admin_email}',
148-
subject: 'New Contact Form Submission',
149-
message: 'You have a new contact form submission from {Name:1}.'
150-
}]
141+
confirmations: {
142+
conf_1: {
143+
type: 'message',
144+
message: '<p>Thank you for contacting us! We\'ll respond within 24 hours.</p>'
145+
}
146+
},
147+
notifications: {
148+
notif_1: {
149+
name: 'Admin Notification',
150+
to: '{admin_email}',
151+
subject: 'New Contact Form Submission',
152+
message: 'You have a new contact form submission from {Name:1}.'
153+
}
154+
}
151155
},
152156
{
153157
title: 'Newsletter Signup (Test)',
@@ -193,10 +197,12 @@ const testForms = [
193197
button: {
194198
text: 'Subscribe'
195199
},
196-
confirmations: [{
197-
type: 'message',
198-
message: '<p>Success! Please check your email to confirm your subscription.</p>'
199-
}]
200+
confirmations: {
201+
conf_1: {
202+
type: 'message',
203+
message: '<p>Success! Please check your email to confirm your subscription.</p>'
204+
}
205+
}
200206
},
201207
{
202208
title: 'Multi-Page Survey (Test)',
@@ -263,10 +269,12 @@ const testForms = [
263269
button: {
264270
text: 'Submit Survey'
265271
},
266-
confirmations: [{
267-
type: 'message',
268-
message: '<p>Thank you for your feedback!</p>'
269-
}]
272+
confirmations: {
273+
conf_1: {
274+
type: 'message',
275+
message: '<p>Thank you for your feedback!</p>'
276+
}
277+
}
270278
}
271279
];
272280

src/config/auth.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,19 @@ export async function validateRestApiAccess(httpClient, authManager) {
317317
{ path: '/feeds', name: 'Feeds' }
318318
];
319319

320+
// Get baseURL from httpClient for OAuth signature generation
321+
const baseURL = httpClient?.defaults?.baseURL;
322+
323+
if (!baseURL) {
324+
throw new Error('httpClient baseURL is not configured');
325+
}
326+
320327
const results = [];
321328
for (const endpoint of endpoints) {
322329
try {
323-
const headers = authManager.getAuthHeaders();
330+
// Generate proper OAuth headers with full URL for signature
331+
const fullUrl = `${baseURL}${endpoint.path}`;
332+
const headers = authManager.getAuthHeaders('GET', fullUrl, { per_page: 1 });
324333
await httpClient.get(endpoint.path, {
325334
headers,
326335
params: { per_page: 1 }

src/config/validation.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,18 @@ export class FormsValidator extends BaseValidator {
309309
}
310310

311311
if (formData.confirmations !== undefined) {
312-
validated.confirmations = this.validateArray(formData.confirmations, 'confirmations');
313-
validated.confirmations = validated.confirmations.map((conf, index) => {
312+
validated.confirmations = this.validateObject(formData.confirmations, 'confirmations');
313+
Object.entries(validated.confirmations).forEach(([key, conf]) => {
314314
if (conf.type === 'redirect' && conf.url !== undefined) {
315-
conf.url = this.validateURL(conf.url, `confirmations[${index}].url`);
315+
conf.url = this.validateURL(conf.url, `confirmations.${key}.url`);
316316
}
317-
return conf;
318317
});
319318
}
320319

320+
if (formData.notifications !== undefined) {
321+
validated.notifications = this.validateObject(formData.notifications, 'notifications');
322+
}
323+
321324
if (formData.schedule_start !== undefined) {
322325
validated.schedule_start = this.validateDate(formData.schedule_start, 'schedule_start');
323326
}

src/config/validators.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ export class FormsValidator {
8888
.array()
8989
)
9090
.field('confirmations', validate('confirmations')
91-
.array()
91+
.object()
9292
.custom((confirmations) => {
93-
if (Array.isArray(confirmations)) {
94-
confirmations.forEach((conf, index) => {
93+
if (confirmations && typeof confirmations === 'object') {
94+
Object.entries(confirmations).forEach(([key, conf]) => {
9595
if (conf.type === 'redirect' && conf.url !== undefined) {
96-
validate(`confirmations[${index}].url`)
96+
validate(`confirmations.${key}.url`)
9797
.required()
9898
.string()
9999
.url()
@@ -104,6 +104,9 @@ export class FormsValidator {
104104
return true;
105105
})
106106
)
107+
.field('notifications', validate('notifications')
108+
.object()
109+
)
107110
.field('schedule_start', validate('schedule_start')
108111
.string()
109112
.date()

src/tests/helpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export class MockHttpClient {
179179
this.requests = [];
180180
this.responses = new Map();
181181
this.defaultResponse = new MockResponse();
182+
this.defaults = { baseURL: 'https://test.example.com' };
182183
}
183184

184185
/**

src/tests/integration.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,12 @@ suite.test('Integration: Create test form', async () => {
154154
button: {
155155
text: 'Submit Test'
156156
},
157-
confirmations: [{
158-
type: 'message',
159-
message: 'Thank you for your test submission!'
160-
}]
157+
confirmations: {
158+
conf_1: {
159+
type: 'message',
160+
message: 'Thank you for your test submission!'
161+
}
162+
}
161163
};
162164

163165
const result = await client.createForm(formData);

src/tests/validation.test.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,12 @@ suite.test('Format Validation: URLs', async () => {
411411
await TestAssert.throwsAsync(
412412
() => client.createForm({
413413
title: 'Test',
414-
confirmations: [{
415-
type: 'redirect',
416-
url: 'not-a-url'
417-
}]
414+
confirmations: {
415+
conf_1: {
416+
type: 'redirect',
417+
url: 'not-a-url'
418+
}
419+
}
418420
}),
419421
'valid URL',
420422
'Should validate URL format'
@@ -427,10 +429,12 @@ suite.test('Format Validation: URLs', async () => {
427429

428430
await client.createForm({
429431
title: 'Test',
430-
confirmations: [{
431-
type: 'redirect',
432-
url: 'https://example.com'
433-
}]
432+
confirmations: {
433+
conf_1: {
434+
type: 'redirect',
435+
url: 'https://example.com'
436+
}
437+
}
434438
});
435439
});
436440

0 commit comments

Comments
 (0)