forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolid-host-test.js
More file actions
108 lines (86 loc) · 3.23 KB
/
solid-host-test.js
File metadata and controls
108 lines (86 loc) · 3.23 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
'use strict'
const expect = require('chai').expect
const SolidHost = require('../../lib/models/solid-host')
const defaults = require('../../config/defaults')
describe('SolidHost', () => {
describe('from()', () => {
it('should init with port, serverUri and hostname', () => {
let config = {
port: 3000,
serverUri: 'https://localhost:3000'
}
let host = SolidHost.from(config)
expect(host.port).to.equal(3000)
expect(host.serverUri).to.equal('https://localhost:3000')
expect(host.hostname).to.equal('localhost')
})
it('should init to default port and serverUri values', () => {
let 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', () => {
let config = {
serverUri: 'https://test.local'
}
let 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', () => {
let 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
})
})
describe('cookieDomain getter', () => {
it('should return null for single-part domains (localhost)', () => {
let host = SolidHost.from({
serverUri: 'https://localhost:8443'
})
expect(host.cookieDomain).to.be.null
})
it('should return a cookie domain for multi-part domains', () => {
let 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', () => {
let host = SolidHost.from({
serverUri: 'https://localhost:8443'
})
let authUrl = host.authEndpoint
expect(authUrl.host).to.equal('localhost:8443')
expect(authUrl.path).to.equal('/authorize')
})
})
})