forked from JCMais/node-libcurl
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spike: investigate localhost resolution RFC6761
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import 'should' | ||
import { app, host, port, server } from '../helper/server' | ||
import { Curl } from '../../lib' | ||
|
||
let curl: Curl | ||
const urlLocalhost = `http://localhost:${port}/` | ||
const urlTestLocalhost = `http://test.localhost:${port}/` | ||
|
||
describe('DNS Resolution', () => { | ||
before((done) => { | ||
server.listen(port, host, () => done()) | ||
|
||
app.get('/', (req, res) => { | ||
res.send({ message: 'resolved', ip: req.ip }) | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
server.close() | ||
app._router.stack.pop() | ||
done() | ||
}) | ||
|
||
beforeEach(() => { | ||
curl = new Curl() | ||
}) | ||
|
||
afterEach(() => { | ||
curl.close() | ||
}) | ||
|
||
it('should resolve localhost to 127.0.0.1', (done) => { | ||
curl.setOpt('URL', urlLocalhost) | ||
|
||
curl.on('end', (status, data) => { | ||
if (status !== 200) { | ||
throw Error(`Invalid status code: ${status}`) | ||
} | ||
|
||
const result = JSON.parse(data as string) | ||
result.message.should.be.equal('resolved') | ||
result.ip.should.be.equal('::1') | ||
|
||
done() | ||
}) | ||
|
||
curl.on('error', done) | ||
curl.perform() | ||
}) | ||
|
||
it('should resolve test.localhost to 127.0.0.1', (done) => { | ||
curl.setOpt('URL', urlTestLocalhost) | ||
|
||
curl.on('end', (status, data) => { | ||
if (status !== 200) { | ||
throw Error(`Invalid status code: ${status}`) | ||
} | ||
|
||
const result = JSON.parse(data as string) | ||
result.message.should.be.equal('resolved') | ||
result.ip.should.be.equal('::1') | ||
|
||
done() | ||
}) | ||
|
||
curl.on('error', done) | ||
curl.perform() | ||
}) | ||
}) |