comparison stream_js_fetch.t @ 1812:f98884ad7700

Test: avoiding forbidden Host header in js fetch tests.
author Dmitry Volyntsev <xeioex@nginx.com>
date Fri, 02 Dec 2022 17:46:32 -0800
parents 520fb74cce4c
children
comparison
equal deleted inserted replaced
1811:520fb74cce4c 1812:f98884ad7700
43 server_name localhost; 43 server_name localhost;
44 44
45 location /njs { 45 location /njs {
46 js_content test.njs; 46 js_content test.njs;
47 } 47 }
48 }
49
50 server {
51 listen 127.0.0.1:8080;
52 server_name aaa;
53 48
54 location /validate { 49 location /validate {
55 js_content test.validate; 50 js_content test.validate;
56 } 51 }
57 52
116 111
117 if (collect.length >= 4 && collect.readUInt16BE(0) == 0xabcd) { 112 if (collect.length >= 4 && collect.readUInt16BE(0) == 0xabcd) {
118 s.off('upstream'); 113 s.off('upstream');
119 114
120 let reply = await ngx.fetch('http://127.0.0.1:$p/validate', 115 let reply = await ngx.fetch('http://127.0.0.1:$p/validate',
121 {body: collect.slice(2,4), 116 {body: collect.slice(2,4)});
122 headers: {Host:'aaa'}});
123 117
124 (reply.status == 200) ? s.done(): s.deny(); 118 (reply.status == 200) ? s.done(): s.deny();
125 119
126 } else if (collect.length) { 120 } else if (collect.length) {
127 s.deny(); 121 s.deny();
137 131
138 if (collect.length >= 4 && collect.readUInt16BE(0) == 0xabcd) { 132 if (collect.length >= 4 && collect.readUInt16BE(0) == 0xabcd) {
139 s.off('upstream'); 133 s.off('upstream');
140 134
141 let reply = await ngx.fetch('http://127.0.0.1:$p/validate', 135 let reply = await ngx.fetch('http://127.0.0.1:$p/validate',
142 {body: collect.slice(2,4), 136 {body: collect.slice(2,4)});
143 headers: {Host:'aaa'}});
144 137
145 if (reply.status == 200) { 138 if (reply.status == 200) {
146 s.send(collect.slice(4), flags); 139 s.send(collect.slice(4), flags);
147 140
148 } else { 141 } else {
151 } 144 }
152 }); 145 });
153 } 146 }
154 147
155 async function access_ok(s) { 148 async function access_ok(s) {
156 let reply = await ngx.fetch('http://127.0.0.1:$p/success', 149 let reply = await ngx.fetch('http://127.0.0.1:$p/success');
157 {headers: {Host:'aaa'}});
158 150
159 (reply.status == 200) ? s.allow(): s.deny(); 151 (reply.status == 200) ? s.allow(): s.deny();
160 } 152 }
161 153
162 async function access_nok(s) { 154 async function access_nok(s) {
163 let reply = await ngx.fetch('http://127.0.0.1:$p/fail', 155 let reply = await ngx.fetch('http://127.0.0.1:$p/fail');
164 {headers: {Host:'aaa'}});
165 156
166 (reply.status == 200) ? s.allow(): s.deny(); 157 (reply.status == 200) ? s.allow(): s.deny();
167 } 158 }
168 159
169 export default {njs: test_njs, validate, preread_verify, filter_verify, 160 export default {njs: test_njs, validate, preread_verify, filter_verify,