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

Webcrypto preliminary patches. #843

Merged
merged 5 commits into from
Jan 23, 2025
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
62 changes: 4 additions & 58 deletions nginx/t/js.t
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ http {
return 200 $test_global;
}

location /body {
js_content test.request_body;
}

location /in_file {
client_body_in_file_only on;
js_content test.request_body;
}

location /status {
js_content test.status;
}
Expand All @@ -100,14 +91,6 @@ http {
js_content test.buffer_variable;
}

location /request_body {
js_content test.request_body;
}

location /request_body_cache {
js_content test.request_body_cache;
}

location /send {
js_content test.send;
}
Expand Down Expand Up @@ -194,22 +177,6 @@ $t->write_file('test.js', <<EOF);
r.finish();
}

function request_body(r) {
try {
var body = r.requestText;
r.return(200, body);

} catch (e) {
r.return(500, e.message);
}
}

function request_body_cache(r) {
function t(v) {return Buffer.isBuffer(v) ? 'buffer' : (typeof v);}
r.return(200,
`requestText:\${t(r.requestText)} requestBuffer:\${t(r.requestBuffer)}`);
}

function send(r) {
var a, s;
r.status = 200;
Expand Down Expand Up @@ -271,14 +238,13 @@ $t->write_file('test.js', <<EOF);
}

export default {njs:test_njs, method, version, addr, uri, buffer,
variable, global_obj, status, request_body, internal,
request_body_cache, send, return_method, sub_internal,
type, log, buffer_variable, except, content_except,
content_empty, send_buffer};
variable, global_obj, status, internal, send,
return_method, sub_internal, type, log, buffer_variable,
except, content_except, content_empty, send_buffer};

EOF

$t->try_run('no njs available')->plan(29);
$t->try_run('no njs available')->plan(25);

###############################################################################

Expand All @@ -289,12 +255,6 @@ like(http_get('/uri'), qr/uri=\/uri/, 'r.uri');

like(http_get('/status'), qr/204 No Content/, 'r.status');

like(http_post('/body'), qr/REQ-BODY/, 'request body');
like(http_post('/in_file'), qr/request body is in a file/,
'request body in file');
like(http_post_big('/body'), qr/200.*^(1234567890){1024}$/ms,
'request body big');

like(http_get('/send?foo=12345&n=11&foo-2=bar&ndd=&foo-3=z'),
qr/n=foo, v=12 n=foo-2, v=ba n=foo-3, v=z/, 'r.send');

Expand Down Expand Up @@ -323,8 +283,6 @@ like(http_post('/type?path=requestText'), qr/200 OK.*type: string$/s,
'requestText type');
like(http_post('/type?path=requestBuffer'), qr/200 OK.*type: buffer$/s,
'requestBuffer type');
like(http_post('/request_body_cache'),
qr/requestText:string requestBuffer:buffer$/s, 'request body cache');

like(http_get('/var'), qr/variable=127.0.0.1/, 'r.variables');
like(http_get('/global'), qr/global=njs/, 'global code');
Expand Down Expand Up @@ -414,16 +372,4 @@ sub http_post {
return http($p, %extra);
}

sub http_post_big {
my ($url, %extra) = @_;

my $p = "POST $url HTTP/1.0" . CRLF .
"Host: localhost" . CRLF .
"Content-Length: 10240" . CRLF .
CRLF .
("1234567890" x 1024);

return http($p, %extra);
}

###############################################################################
30 changes: 28 additions & 2 deletions nginx/t/js_request_body.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,23 @@ http {
client_body_in_file_only on;
js_content test.body;
}

location /read_body_from_temp_file {
client_body_in_file_only clean;
js_content test.read_body_from_temp_file;
}

location /request_body_cache {
js_content test.request_body_cache;
}
}
}

EOF

$t->write_file('test.js', <<EOF);
import fs from 'fs';

function body(r) {
try {
var body = r.requestText;
Expand All @@ -67,11 +78,22 @@ $t->write_file('test.js', <<EOF);
}
}

export default {body};
function read_body_from_temp_file(r) {
let fn = r.variables.request_body_file;
r.return(200, fs.readFileSync(fn));
}

function request_body_cache(r) {
function t(v) {return Buffer.isBuffer(v) ? 'buffer' : (typeof v);}
r.return(200,
`requestText:\${t(r.requestText)} requestBuffer:\${t(r.requestBuffer)}`);
}

export default {body, read_body_from_temp_file, request_body_cache};

EOF

$t->try_run('no njs request body')->plan(3);
$t->try_run('no njs request body')->plan(5);

###############################################################################

Expand All @@ -80,6 +102,10 @@ like(http_post('/in_file'), qr/request body is in a file/,
'request body in file');
like(http_post_big('/body'), qr/200.*^(1234567890){1024}$/ms,
'request body big');
like(http_post_big('/read_body_from_temp_file'),
qr/200.*^(1234567890){1024}$/ms, 'request body big from temp file');
like(http_post('/request_body_cache'),
qr/requestText:string requestBuffer:buffer$/s, 'request body cache');

###############################################################################

Expand Down
Loading