Skip to content

fix: Fix reload errors due long matching conditions #1829

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

Merged
merged 29 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3cbc1ec
fix: fix reload errors due long matching conditions
salonichf5 Apr 9, 2024
26d766a
add redirect to export list
salonichf5 Apr 17, 2024
f0da36d
update based on reviews
salonichf5 Apr 22, 2024
a0e31b0
remove print statements
salonichf5 Apr 22, 2024
44c632d
fix unit test
salonichf5 Apr 22, 2024
e40a5cc
update unit tests
salonichf5 Apr 22, 2024
d96fcaa
Update internal/mode/static/nginx/config/generator.go
salonichf5 Apr 22, 2024
7897819
Update internal/mode/static/nginx/config/servers.go
salonichf5 Apr 22, 2024
81b5655
update key for match.json
salonichf5 Apr 22, 2024
6153ddb
format njs code
salonichf5 Apr 24, 2024
75cdb8f
Update internal/mode/static/nginx/config/generator.go
salonichf5 Apr 24, 2024
4ad2de1
Update internal/mode/static/nginx/config/servers.go
salonichf5 Apr 24, 2024
d0afa69
review comments
salonichf5 Apr 24, 2024
8f117c7
improve httpmatches.js
salonichf5 Apr 25, 2024
5ca49f7
address reviews
salonichf5 Apr 25, 2024
3683dd7
add more unit test coverage for njs unit tests
salonichf5 Apr 25, 2024
6e7e79e
Update internal/mode/static/nginx/config/servers.go
salonichf5 Apr 25, 2024
b459205
Update internal/mode/static/nginx/config/servers.go
salonichf5 Apr 25, 2024
02653ce
Update internal/mode/static/nginx/config/servers_test.go
salonichf5 Apr 25, 2024
7bf61f3
Update internal/mode/static/nginx/config/servers_test.go
salonichf5 Apr 25, 2024
0a4a7ac
Update internal/mode/static/nginx/config/servers.go
salonichf5 Apr 25, 2024
f63f317
Update internal/mode/static/nginx/config/servers.go
salonichf5 Apr 25, 2024
cc9a19e
update based on reviews
salonichf5 Apr 25, 2024
27f9e53
rearrange expect statements to avoid panic
salonichf5 Apr 25, 2024
c637c6d
fix unit test
salonichf5 Apr 25, 2024
07fbf39
fix httpmatches
salonichf5 Apr 29, 2024
2dcb7c4
update error message
salonichf5 Apr 29, 2024
b744b70
Merge branch 'main' into bug/http-match
salonichf5 Apr 29, 2024
377d9f7
Merge branch 'main' into bug/http-match
salonichf5 Apr 29, 2024
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
Prev Previous commit
Next Next commit
add more unit test coverage for njs unit tests
  • Loading branch information
salonichf5 committed Apr 25, 2024
commit 3683dd70751d97045ca86cc4caeb8b3a3cda624c
6 changes: 1 addition & 5 deletions internal/mode/static/nginx/modules/src/httpmatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
};

function redirect(r) {
let matchList;

Check warning on line 8 in internal/mode/static/nginx/modules/src/httpmatches.js

View check run for this annotation

Codecov / codecov/patch

internal/mode/static/nginx/modules/src/httpmatches.js#L8

Added line #L8 was not covered by tests

try {
matchList = extractMatchesFromRequest(r, matches);

Check warning on line 10 in internal/mode/static/nginx/modules/src/httpmatches.js

View check run for this annotation

Codecov / codecov/patch

internal/mode/static/nginx/modules/src/httpmatches.js#L10

Added line #L10 was not covered by tests
} catch (e) {
r.error(e.message);
r.return(HTTP_CODES.internalServerError);
return;
}

redirectForMatchList(r, matchList);
}

Check warning on line 17 in internal/mode/static/nginx/modules/src/httpmatches.js

View check run for this annotation

Codecov / codecov/patch

internal/mode/static/nginx/modules/src/httpmatches.js#L16-L17

Added lines #L16 - L17 were not covered by tests

function extractMatchesFromRequest(r, matches) {
let matchList;
Expand All @@ -42,9 +40,7 @@
try {
verifyMatchList(matchList);
} catch (e) {
r.error(e.message);
r.return(HTTP_CODES.internalServerError);
return;
throw Error(`cannot redirect the request; ${matchList} matches list is not valid`);
}

return matchList;
Expand Down
28 changes: 18 additions & 10 deletions internal/mode/static/nginx/modules/test/httpmatches.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,25 @@ describe('extractMatchesFromRequest', () => {
errSubstring: 'match_key is not defined',
},
{
name: 'throws if key does not exist on matches request',
request: createRequest({}),
matchesObject: { test: '["any": "true"]' },
name: 'throws if key does not exist on matches object',
request: createRequest({ matchKey: 'test' }),
matchesObject: {},
expectThrow: true,
errSubstring: 'match_key is not defined',
errSubstring: 'the key test is not defined on the matches object',
},
{
name: 'throws an error if matchList is not valid',
request: createRequest({ matchKey: 'test' }),
matchesObject: { test: {} },
expectThrow: true,
errSubstring: 'matches list is not valid',
},
{
name: 'does not throw if matches key is present & expected matchList is returned',
request: createRequest({ matchKey: 'test' }),
matchesObject: { test: '[]' },
matchesObject: { test: [{ match: 'value' }] },
expectThrow: false,
expected: [{ match: 'value' }],
},
];
tests.forEach((test) => {
Expand All @@ -67,9 +75,9 @@ describe('extractMatchesFromRequest', () => {
hm.extractMatchesFromRequest(test.request, test.matchesObject),
).to.throw(test.errSubstring);
} else {
expect(() =>
hm.extractMatchesFromRequest(test.request, test.matchesObject).to.not.throw(),
);
expect(
hm.extractMatchesFromRequest(test.request, test.matchesObject),
).to.deep.equal(test.expected);
}
});
});
Expand All @@ -85,9 +93,9 @@ describe('verifyMatchList', () => {
},
{
name: 'throws if the length of the matches variable is zero',
matchList: '[]',
matchList: [],
expectThrow: true,
errSubstring: 'expected a list of matches',
errSubstring: 'matches is an empty list',
},
{
name: 'does not throw if matches variable is expected list of matches',
Expand Down
Loading