-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathsolid-host-test.mjs
More file actions
118 lines (97 loc) · 3.84 KB
/
solid-host-test.mjs
File metadata and controls
118 lines (97 loc) · 3.84 KB
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
import { describe, it, before } from 'mocha'
import { expect } from 'chai'
import SolidHost from '../../lib/models/solid-host.mjs'
import defaults from '../../config/defaults.mjs'
describe('SolidHost', () => {
describe('from()', () => {
it('should init with provided params', () => {
const config = {
port: 3000,
serverUri: 'https://localhost:3000',
live: true,
root: '/data/solid/',
multiuser: true,
webid: true
}
const host = SolidHost.from(config)
expect(host.port).to.equal(3000)
expect(host.serverUri).to.equal('https://localhost:3000')
expect(host.hostname).to.equal('localhost')
expect(host.live).to.be.true
expect(host.root).to.equal('/data/solid/')
expect(host.multiuser).to.be.true
expect(host.webid).to.be.true
})
it('should init to default port and serverUri values', () => {
const host = SolidHost.from({})
expect(host.port).to.equal(defaults.port)
expect(host.serverUri).to.equal(defaults.serverUri)
})
})
describe('accountUriFor()', () => {
it('should compose an account uri for an account name', () => {
const config = {
serverUri: 'https://test.local'
}
const host = SolidHost.from(config)
expect(host.accountUriFor('alice')).to.equal('https://alice.test.local')
})
it('should throw an error if no account name is passed in', () => {
const host = SolidHost.from()
expect(() => { host.accountUriFor() }).to.throw(TypeError)
})
})
describe('allowsSessionFor()', () => {
let host
before(() => {
host = SolidHost.from({
serverUri: 'https://test.local'
})
})
it('should allow an empty userId and origin', () => {
expect(host.allowsSessionFor('', '', [])).to.be.true
})
it('should allow a userId with empty origin', () => {
expect(host.allowsSessionFor('https://user.own/profile/card#me', '', [])).to.be.true
})
it('should allow a userId with the user subdomain as origin', () => {
expect(host.allowsSessionFor('https://user.own/profile/card#me', 'https://user.own', [])).to.be.true
})
it('should allow a userId with the server domain as origin', () => {
expect(host.allowsSessionFor('https://user.own/profile/card#me', 'https://test.local', [])).to.be.true
})
it('should allow a userId with a server subdomain as origin', () => {
expect(host.allowsSessionFor('https://user.own/profile/card#me', 'https://other.test.local', [])).to.be.true
})
it('should disallow a userId from a different domain', () => {
expect(host.allowsSessionFor('https://user.own/profile/card#me', 'https://other.remote', [])).to.be.false
})
it('should allow user from a trusted domain', () => {
expect(host.allowsSessionFor('https://user.own/profile/card#me', 'https://other.remote', ['https://other.remote'])).to.be.true
})
})
describe('cookieDomain getter', () => {
it('should return null for single-part domains (localhost)', () => {
const host = SolidHost.from({
serverUri: 'https://localhost:8443'
})
expect(host.cookieDomain).to.be.null
})
it('should return a cookie domain for multi-part domains', () => {
const host = SolidHost.from({
serverUri: 'https://example.com:8443'
})
expect(host.cookieDomain).to.equal('.example.com')
})
})
describe('authEndpoint getter', () => {
it('should return an /authorize url object', () => {
const host = SolidHost.from({
serverUri: 'https://localhost:8443'
})
const authUrl = host.authEndpoint
expect(authUrl.host).to.equal('localhost:8443')
expect(authUrl.pathname).to.equal('/authorize')
})
})
})