forked from remotestorage/armadietto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_finger_spec.js
158 lines (145 loc) · 5.74 KB
/
web_finger_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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* eslint-env mocha, chai, node */
const chai = require('chai');
const chaiHttp = require('chai-http');
const spies = require('chai-spies');
const expect = chai.expect;
const Armadietto = require('../../lib/armadietto');
chai.use(chaiHttp);
chai.use(spies);
const store = {};
const port = '4569';
const host = `http://localhost:${port}`;
const req = chai.request(host);
const get = async (path) => {
const ret = await req.get(path).buffer(true);
return ret;
};
// trim all whitespaces to be a single space (' ') for text compares
const trim = (what) => what.replace(/\s+/gm, ' ').trim();
describe('WebFinger', () => {
before((done) => {
(async () => {
this._server = new Armadietto({
store,
http: { port },
logging: { log_dir: './test-log', stdout: [], log_files: ['error'] }
});
await this._server.boot();
done();
})();
});
after((done) => {
(async () => {
await this._server.stop();
done();
})();
});
it('returns webfinger data as JRD+JSON', async () => {
const res = await get('/.well-known/webfinger');
expect(res).to.have.status(200);
expect(res).to.have.header('Access-Control-Allow-Origin', '*');
expect(res).to.have.header('Content-Type', 'application/jrd+json');
expect(res.body).to.be.deep.equal({
links: [
{
rel: 'lrdd',
template: host + '/webfinger/jrd?resource={uri}'
}
]
});
});
it('returns host metadata as JSON', async () => {
const res = await get('/.well-known/host-meta.json');
expect(res).to.have.status(200);
expect(res).to.have.header('Access-Control-Allow-Origin', '*');
expect(res).to.have.header('Content-Type', 'application/json');
expect(res.body).to.be.deep.equal({
links: [
{
rel: 'lrdd',
template: host + '/webfinger/jrd?resource={uri}'
}
]
});
});
it('returns host metadata as XML', async () => {
const res = await get('/.well-known/host-meta');
expect(res).to.have.status(200);
expect(res).to.have.header('Access-Control-Allow-Origin', '*');
expect(res).to.have.header('Content-Type', 'application/xrd+xml');
expect(trim(res.text)).to.be.equal(trim(`
<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Link rel="lrdd" type="application/xrd+xml" template="${host}/webfinger/xrd?resource={uri}" />
</XRD>`));
});
it('returns account metadata as JSON', async () => {
const res = await get('/webfinger/jrd?resource=acct:zebcoe@locog');
expect(res).to.have.status(200);
expect(res).to.have.header('Access-Control-Allow-Origin', '*');
expect(res).to.have.header('Content-Type', 'application/jrd+json');
expect(res.body).to.have.deep.equal({
links: [
{
rel: 'remoteStorage',
api: 'simple',
auth: host + '/oauth/zebcoe',
template: host + '/storage/zebcoe/{category}'
}
]
});
});
it('returns account metadata as XML', async () => {
const res = await get('/webfinger/xrd?resource=acct:zebcoe@locog');
expect(res).to.have.status(200);
expect(res).to.have.header('Access-Control-Allow-Origin', '*');
expect(res).to.have.header('Content-Type', 'application/xrd+xml');
expect(trim(res.text)).to.be.equal(trim(`
<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Link rel="remoteStorage" api="simple" auth="${host}/oauth/zebcoe" template="${host}/storage/zebcoe/{category}" />
</XRD>`));
});
it('returns resource metadata as JSON', async () => {
const res = await get('/.well-known/host-meta.json?resource=acct:zebcoe@locog');
expect(res).to.have.status(200);
expect(res).to.have.header('Access-Control-Allow-Origin', '*');
expect(res).to.have.header('Content-Type', 'application/json');
// check_status( 200 )
// check_header( "Access-Control-Allow-Origin", "*" )
// check_header( "Content-Type", "application/json" )
expect(res.body).to.have.deep.equal({
links: [
{
href: host + '/storage/zebcoe',
rel: 'remotestorage',
type: 'draft-dejong-remotestorage-01',
properties: {
'auth-method': 'http://tools.ietf.org/html/rfc6749#section-4.2',
'auth-endpoint': host + '/oauth/zebcoe',
'http://remotestorage.io/spec/version': 'draft-dejong-remotestorage-01',
'http://tools.ietf.org/html/rfc6749#section-4.2': host + '/oauth/zebcoe',
'http://tools.ietf.org/html/rfc6750#section-2.3': true
}
}
]
});
});
it('returns resource metadata as XML', async () => {
const res = await get('/.well-known/host-meta?resource=acct:zebcoe@locog');
expect(res).to.have.status(200);
expect(res).to.have.header('Access-Control-Allow-Origin', '*');
expect(res).to.have.header('Content-Type', 'application/xrd+xml');
expect(trim(res.text)).to.be.equal(trim(`
<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Link href="http://localhost:${port}/storage/zebcoe" rel="remotestorage" type="draft-dejong-remotestorage-01">
<Property type="auth-method">http://tools.ietf.org/html/rfc6749#section-4.2</Property>
<Property type="auth-endpoint">http://localhost:${port}/oauth/zebcoe</Property>
<Property type="http://remotestorage.io/spec/version">draft-dejong-remotestorage-01</Property>
<Property type="http://tools.ietf.org/html/rfc6750#section-2.3">true</Property>
<Property type="http://tools.ietf.org/html/rfc6749#section-4.2">http://localhost:${port}/oauth/zebcoe</Property>
</Link>
</XRD>`));
});
});