This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathindex.spec.js
123 lines (92 loc) · 2.76 KB
/
index.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* eslint-env mocha */
'use strict'
const { expect } = require('aegir/utils/chai')
const Daemon = require('../')
const fetch = require('node-fetch')
const WebSocket = require('ws')
const os = require('os')
function createDaemon () {
return new Daemon({
init: {
bits: 512
},
repo: `${os.tmpdir()}/ipfs-test-${Math.random()}`,
config: {
Addresses: {
Swarm: [
'/ip4/0.0.0.0/tcp/0',
'/ip4/127.0.0.1/tcp/0/ws'
],
API: '/ip4/127.0.0.1/tcp/0',
Gateway: '/ip4/127.0.0.1/tcp/0',
RPC: '/ip4/127.0.0.1/tcp/0'
}
}
})
}
describe('daemon', function () {
// slow ci is slow
this.timeout(60 * 1000)
let daemon
it('should start a http api server', async () => {
daemon = createDaemon()
await daemon.start()
const {
uri
} = daemon._httpApi._apiServers[0].info
const idFromCore = await daemon._ipfs.id()
const httpId = await fetch(`${uri}/api/v0/id`, {
method: 'POST'
})
await expect(httpId.json()).to.eventually.have.property('PublicKey', idFromCore.publicKey)
await daemon.stop()
})
it('should start a http gateway server', async () => {
daemon = createDaemon()
await daemon.start()
const {
uri
} = daemon._httpGateway._gatewayServers[0].info
const result = await fetch(`${uri}/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn`, {
method: 'POST'
})
await expect(result.text()).to.eventually.include('Index of /ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/')
await daemon.stop()
})
it('should start a gRPC server', async () => {
daemon = createDaemon()
await daemon.start()
const {
uri
} = daemon._grpcServer.info
const socket = new WebSocket(`${uri}/ipfs.Root/id`)
let received = Buffer.alloc(0)
await new Promise((resolve) => {
socket.on('open', () => {
socket.send(Buffer.from('Y29udGVudC10eXBlOiBhcHBsaWNhdGlvbi9ncnBjLXdlYitwcm90bw0KeC1ncnBjLXdlYjogMQ0K', 'base64'))
socket.send(Buffer.from('AAAAAAAA', 'base64'))
})
socket.on('message', (data) => {
received = Buffer.concat([received, data], received.byteLength + data.byteLength)
})
socket.on('close', () => {
resolve()
})
})
const apiId = await daemon._ipfs.id()
// don't try to decode protobuf, just look for embedded string
expect(received.toString('utf8')).to.include(apiId.id)
await daemon.stop()
})
it('should stop', async () => {
daemon = createDaemon()
await daemon.start()
await daemon.stop()
const {
uri
} = daemon._httpApi._apiServers[0].info
await expect(fetch(`${uri}/api/v0/id`, {
method: 'POST'
})).to.eventually.be.rejectedWith(/ECONNREFUSED/)
})
})