This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathrequest-api.spec.js
77 lines (69 loc) · 2.24 KB
/
request-api.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* eslint-env mocha */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const isNode = require('detect-node')
const ipfsAPI = require('../src/index.js')
const async = require('async')
describe('\'deal with HTTP weirdness\' tests', () => {
it('does not crash if no content-type header is provided', (done) => {
if (!isNode) { return done() }
// go-ipfs always (currently) adds a content-type header, even if no content is present,
// the standard behaviour for an http-api is to omit this header if no content is present
const server = require('http').createServer((req, res) => {
res.writeHead(200)
res.end()
})
server.listen(6001, () => {
ipfsAPI('/ip4/127.0.0.1/tcp/6001').config.replace('test/fixtures/r-config.json', (err) => {
expect(err).to.not.exist()
server.close(done)
})
})
})
})
describe('client cert options', function () {
it('accepts client cert, key', function (done) {
// not sure how to automate client certs in browsers
if (!isNode) { return done() }
async.waterfall([
(cb) => {
require('pem').createCertificate({selfSigned: true}, cb)
},
(serverPEM, cb) => {
require('pem').createCertificate({
serviceKey: serverPEM.clientKey,
serviceCertificate: serverPEM.certificate,
commonName: 'test'
}, (err, clientPEM) => cb(err, serverPEM, clientPEM))
},
(serverPEM, clientPEM, cb) => {
const server = require('https').createServer({
requestCert: true,
rejectUnauthorized: true,
ca: [serverPEM.certificate],
key: serverPEM.clientKey,
cert: serverPEM.certificate
}, (req, res) => {
res.end()
})
server.listen(6001, () => {
const ipfs = ipfsAPI({
host: 'localhost',
port: '6001',
protocol: 'https',
key: clientPEM.clientKey,
cert: clientPEM.certificate,
ca: [serverPEM.certificate]
})
ipfs.id((err, res) => {
expect(err).to.not.exist()
server.close(cb)
})
})
}
], done)
})
})