Skip to content

Commit c85ef9f

Browse files
committed
fix: response phase criteria
1 parent 260c16c commit c85ef9f

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

lib/utils/generateManifest/generateManifest.utils.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,17 @@ function jsToJson(config) {
306306
const cdnRule = {
307307
name: rule.name,
308308
phase: 'response',
309-
behaviors: [],
310-
criteria: rule.criteria || [],
311-
is_active: true,
312-
description: rule.description || '',
309+
criteria: [
310+
[
311+
{
312+
variable: `\${${rule.variable ?? 'uri'}}`,
313+
operator: 'matches',
314+
conditional: 'if',
315+
input_value: rule.match,
316+
},
317+
],
318+
],
319+
behaviors: rule.behaviors ? [...rule.behaviors] : [],
313320
};
314321

315322
if (rule.setCookie) {

lib/utils/generateManifest/generateManifest.utils.test.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ describe('Utils - generateManifest', () => {
5353
rules: {
5454
request: [
5555
{
56-
name: 'testRule',
57-
match: '/test',
56+
name: 'rewriteRule',
57+
match: '/path',
58+
capture: {
59+
match: '^(./)([^/])$',
60+
captured: 'other',
61+
subject: 'uri',
62+
},
5863
rewrite: {
5964
match: '^(./)([^/])$',
6065
set: (other) => `/${other[0]}/${other[1]}`,
@@ -70,8 +75,8 @@ describe('Utils - generateManifest', () => {
7075
expect.objectContaining({
7176
name: 'capture_match_groups',
7277
target: expect.objectContaining({
73-
captured_array: 'other',
7478
regex: '^(./)([^/])$',
79+
captured_array: 'other',
7580
// eslint-disable-next-line no-template-curly-in-string
7681
subject: '${uri}',
7782
}),
@@ -426,7 +431,7 @@ describe('Utils - generateManifest', () => {
426431
);
427432
});
428433

429-
it('should throw an error if setHeaders is not a string', () => {
434+
it('should throw an error if setHeaders is not an array of strings', () => {
430435
const azionConfig = {
431436
rules: {
432437
request: [
@@ -440,7 +445,7 @@ describe('Utils - generateManifest', () => {
440445
};
441446

442447
expect(() => jsToJson(azionConfig)).toThrow(
443-
"The 'setHeaders' field must be a string or null.",
448+
"The 'setHeaders' field must be an array of strings.",
444449
);
445450
});
446451

@@ -491,14 +496,14 @@ describe('Utils - generateManifest', () => {
491496
);
492497
});
493498

494-
it('should correctly add setHeaders behavior with a valid string', () => {
499+
it('should correctly add setHeaders behavior with a valid array', () => {
495500
const azionConfig = {
496501
rules: {
497502
request: [
498503
{
499504
name: 'testRule',
500505
match: '/',
501-
setHeaders: 'Authorization: Bearer abc123',
506+
setHeaders: ['Authorization: Bearer abc123'], // Corretamente definido como uma array de strings
502507
},
503508
],
504509
},

0 commit comments

Comments
 (0)