forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount-manager-test.js
More file actions
142 lines (122 loc) · 4.5 KB
/
account-manager-test.js
File metadata and controls
142 lines (122 loc) · 4.5 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'use strict'
/* eslint-disable no-unused-expressions */
const path = require('path')
const fs = require('fs-extra')
const chai = require('chai')
const expect = chai.expect
chai.should()
const LDP = require('../../lib/ldp')
const SolidHost = require('../../lib/models/solid-host')
const AccountManager = require('../../lib/models/account-manager')
const ResourceMapper = require('../../lib/resource-mapper')
const testAccountsDir = path.join(__dirname, '../resources/accounts')
const accountTemplatePath = path.join(__dirname, '../../default-templates/new-account')
let host
beforeEach(() => {
host = SolidHost.from({ serverUri: 'https://example.com' })
})
afterEach(() => {
fs.removeSync(path.join(__dirname, '../resources/accounts/alice.example.com'))
})
// FIXME #1502
describe.skip('AccountManager', () => {
describe('accountExists()', () => {
const host = SolidHost.from({ serverUri: 'https://localhost' })
describe('in multi user mode', () => {
const multiuser = true
const resourceMapper = new ResourceMapper({
rootUrl: 'https://localhost:8443/',
rootPath: process.cwd(),
includeHost: multiuser
})
const store = new LDP({ multiuser, resourceMapper })
const options = { multiuser, store, host }
const accountManager = AccountManager.from(options)
it('resolves to true if a directory for the account exists in root', () => {
// Note: test/resources/accounts/tim.localhost/ exists in this repo
return accountManager.accountExists('tim')
.then(exists => {
expect(exists).to.be.true
})
})
it('resolves to false if a directory for the account does not exist', () => {
// Note: test/resources/accounts/alice.localhost/ does NOT exist
return accountManager.accountExists('alice')
.then(exists => {
expect(exists).to.be.false
})
})
})
describe('in single user mode', () => {
const multiuser = false
it('resolves to true if root .acl exists in root storage', () => {
const resourceMapper = new ResourceMapper({
rootUrl: 'https://localhost:8443/',
includeHost: multiuser,
rootPath: path.join(testAccountsDir, 'tim.localhost')
})
const store = new LDP({
multiuser,
resourceMapper
})
const options = { multiuser, store, host }
const accountManager = AccountManager.from(options)
return accountManager.accountExists()
.then(exists => {
expect(exists).to.be.true
})
})
it('resolves to false if root .acl does not exist in root storage', () => {
const resourceMapper = new ResourceMapper({
rootUrl: 'https://localhost:8443/',
includeHost: multiuser,
rootPath: testAccountsDir
})
const store = new LDP({
multiuser,
resourceMapper
})
const options = { multiuser, store, host }
const accountManager = AccountManager.from(options)
return accountManager.accountExists()
.then(exists => {
expect(exists).to.be.false
})
})
})
})
describe('createAccountFor()', () => {
it('should create an account directory', () => {
const multiuser = true
const resourceMapper = new ResourceMapper({
rootUrl: 'https://localhost:8443/',
includeHost: multiuser,
rootPath: testAccountsDir
})
const store = new LDP({ multiuser, resourceMapper })
const options = { host, multiuser, store, accountTemplatePath }
const accountManager = AccountManager.from(options)
const userData = {
username: 'alice',
email: 'alice@example.com',
name: 'Alice Q.'
}
const userAccount = accountManager.userAccountFrom(userData)
const accountDir = accountManager.accountDirFor('alice')
return accountManager.createAccountFor(userAccount)
.then(() => {
return accountManager.accountExists('alice')
})
.then(found => {
expect(found).to.be.true
})
.then(() => {
const profile = fs.readFileSync(path.join(accountDir, '/profile/card$.ttl'), 'utf8')
expect(profile).to.include('"Alice Q."')
const rootAcl = fs.readFileSync(path.join(accountDir, '.acl'), 'utf8')
expect(rootAcl).to.include('<mailto:alice@')
expect(rootAcl).to.include('<https://alice.example.com/profile/card#me>')
})
})
})
})