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
119 lines (99 loc) · 3.68 KB
/
Copy pathaccount-manager-test.js
File metadata and controls
119 lines (99 loc) · 3.68 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
'use strict'
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 testAccountsDir = path.join(__dirname, '../resources/accounts')
const accountTemplatePath = path.join(__dirname, '../../default-templates/new-account')
var host
beforeEach(() => {
host = SolidHost.from({ serverUri: 'https://example.com' })
})
afterEach(() => {
fs.removeSync(path.join(__dirname, '../resources/accounts/alice.example.com'))
})
describe('AccountManager', () => {
describe('accountExists()', () => {
let host = SolidHost.from({ serverUri: 'https://localhost' })
describe('in multi user mode', () => {
let multiuser = true
let store = new LDP({ root: testAccountsDir, multiuser })
let options = { multiuser, store, host }
let 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', () => {
let multiuser = false
it('resolves to true if root .acl exists in root storage', () => {
let store = new LDP({
root: path.join(testAccountsDir, 'tim.localhost'),
multiuser
})
let options = { multiuser, store, host }
let 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', () => {
let store = new LDP({
root: testAccountsDir,
multiuser
})
let options = { multiuser, store, host }
let accountManager = AccountManager.from(options)
return accountManager.accountExists()
.then(exists => {
expect(exists).to.be.false
})
})
})
})
describe('createAccountFor()', () => {
it('should create an account directory', () => {
let multiuser = true
let store = new LDP({ root: testAccountsDir, multiuser })
let options = { host, multiuser, store, accountTemplatePath }
let accountManager = AccountManager.from(options)
let userData = {
username: 'alice',
email: 'alice@example.com',
name: 'Alice Q.'
}
let userAccount = accountManager.userAccountFrom(userData)
let accountDir = accountManager.accountDirFor('alice')
return accountManager.createAccountFor(userAccount)
.then(() => {
return accountManager.accountExists('alice')
})
.then(found => {
expect(found).to.be.true
})
.then(() => {
let profile = fs.readFileSync(path.join(accountDir, '/profile/card'), 'utf8')
expect(profile).to.include('"Alice Q."')
let 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>')
})
})
})
})