Skip to content

Commit 5df64e6

Browse files
committed
test: verify transfer-encoding: chunked works in mounted scenarios
1 parent de6c002 commit 5df64e6

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

test/client_auth/client_auth.test.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createPrivateKey, X509Certificate } from 'node:crypto';
22
import { readFileSync } from 'node:fs';
3+
import { request } from 'node:http';
34

4-
import got from 'got'; // eslint-disable-line import/no-unresolved
55
import nock from 'nock';
66
import { importJWK } from 'jose';
77
import sinon from 'sinon';
@@ -448,24 +448,42 @@ describe('client authentication options', () => {
448448
.expect(tokenAuthSucceeded);
449449
});
450450

451-
// TODO: not sure why when mounted everything crap out
452-
if (!process.env.MOUNT_VIA) {
453-
it('can use transfer-encoding: chunked', async () => {
454-
const { address, port } = global.server.address();
451+
it('can use transfer-encoding: chunked', function (done) {
452+
const { address, port } = global.server.address();
453+
454+
const req = request({
455+
hostname: address,
456+
port,
457+
path: this.suitePath(route),
458+
method: 'POST',
459+
headers: {
460+
'Content-Type': 'application/x-www-form-urlencoded',
461+
'Transfer-Encoding': 'chunked',
462+
},
463+
}, (res) => {
464+
let data = '';
455465

456-
const response = await got.post(`http://[${address}]:${port}${route}`, {
457-
throwHttpErrors: false,
458-
form: {
459-
grant_type: 'foo',
460-
client_id: 'client-post',
461-
client_secret: 'secret',
462-
},
463-
headers: { 'transfer-encoding': 'chunked' },
466+
res.on('data', (chunk) => {
467+
data += chunk;
468+
});
469+
470+
res.on('end', () => {
471+
try {
472+
expect(JSON.parse(data)).to.deep.eql(tokenAuthSucceeded);
473+
done();
474+
} catch (err) {
475+
done(err);
476+
}
464477
});
465478

466-
expect(JSON.parse(response.body)).to.deep.eql(tokenAuthSucceeded);
479+
res.on('error', done);
467480
});
468-
}
481+
482+
req.write('grant_type=foo&client_id');
483+
req.write('=client-post&client_secret=secret');
484+
req.end();
485+
req.on('error', done);
486+
});
469487

470488
it('accepts the auth (but client configured with basic)', function () {
471489
return this.agent.post(route)

0 commit comments

Comments
 (0)