Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fa7e7e5

Browse files
authoredNov 5, 2024··
Merge pull request #1784 from nodeSolidServer/fix#1783
Fix #1783
2 parents 1b1989e + cb804ab commit fa7e7e5

File tree

5 files changed

+75
-5
lines changed

5 files changed

+75
-5
lines changed
 

‎lib/models/account-manager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class AccountManager {
5757
*
5858
* ```
5959
* let options = { host, multiuser, store }
60-
* let accontManager = AccountManager.from(options)
60+
* let accountManager = AccountManager.from(options)
6161
* ```
6262
*
6363
* @param [options={}] {Object} See the `constructor()` docstring.

‎lib/models/account-template.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const recursiveRead = require('recursive-readdir')
66
const fsUtils = require('../common/fs-utils')
77
const templateUtils = require('../common/template-utils')
88
const LDP = require('../ldp')
9+
const { URL } = require('url')
910

1011
const TEMPLATE_EXTENSIONS = ['.acl', '.meta', '.json', '.hbs', '.handlebars']
1112
const TEMPLATE_FILES = ['card']
@@ -72,9 +73,11 @@ class AccountTemplate {
7273
* @return {Object}
7374
*/
7475
static templateSubstitutionsFor (userAccount) {
76+
const webUri = new URL(userAccount.webId)
77+
const podRelWebId = userAccount.webId.replace(webUri.origin, '')
7578
const substitutions = {
7679
name: userAccount.displayName,
77-
webId: userAccount.webId,
80+
webId: userAccount.externalWebId ? userAccount.webId : podRelWebId,
7881
email: userAccount.email,
7982
idp: userAccount.idp
8083
}

‎test/integration/account-manager-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe('AccountManager', () => {
139139

140140
const rootAcl = fs.readFileSync(path.join(accountDir, '.acl'), 'utf8')
141141
expect(rootAcl).to.include('<mailto:alice@')
142-
expect(rootAcl).to.include('<https://alice.example.com/profile/card#me>')
142+
expect(rootAcl).to.include('</profile/card#me>')
143143
})
144144
})
145145
})

‎test/integration/account-template-test.js

+68-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ chai.use(sinonChai)
1010
chai.should()
1111

1212
const AccountTemplate = require('../../lib/models/account-template')
13-
13+
const UserAccount = require('../../lib/models/user-account')
1414
const templatePath = path.join(__dirname, '../../default-templates/new-account')
1515
const accountPath = path.join(__dirname, '../resources/new-account')
1616

@@ -62,4 +62,71 @@ describe('AccountTemplate', () => {
6262
})
6363
})
6464
})
65+
66+
describe('templateSubtitutionsFor()', () => {
67+
it('should not update the webid', () => {
68+
const userAccount = new UserAccount({
69+
webId: 'https://alice.example.com/#me',
70+
email: 'alice@example.com',
71+
name: 'Alice Q.'
72+
})
73+
74+
const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)
75+
76+
expect(substitutions.webId).to.equal('/#me')
77+
})
78+
79+
it('should not update the nested webid', () => {
80+
const userAccount = new UserAccount({
81+
webId: 'https://alice.example.com/alice/#me',
82+
email: 'alice@example.com',
83+
name: 'Alice Q.'
84+
})
85+
86+
const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)
87+
88+
expect(substitutions.webId).to.equal('/alice/#me')
89+
})
90+
91+
it('should update the webid', () => {
92+
const userAccount = new UserAccount({
93+
webId: 'http://localhost:8443/alice/#me',
94+
email: 'alice@example.com',
95+
name: 'Alice Q.'
96+
})
97+
98+
const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)
99+
100+
expect(substitutions.webId).to.equal('/alice/#me')
101+
})
102+
})
103+
104+
describe('creating account where webId does match server Uri?', () => {
105+
it('should have a relative uri for the base path rather than a complete uri', () => {
106+
const userAccount = new UserAccount({
107+
webId: 'http://localhost:8443/alice/#me',
108+
email: 'alice@example.com',
109+
name: 'Alice Q.'
110+
})
111+
112+
const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)
113+
const template = new AccountTemplate({ substitutions })
114+
return AccountTemplate.copyTemplateDir(templatePath, accountPath)
115+
.then(() => {
116+
return template.processAccount(accountPath)
117+
}).then(() => {
118+
const profile = fs.readFileSync(path.join(accountPath, '/profile/card$.ttl'), 'utf8')
119+
expect(profile).to.include('"Alice Q."')
120+
expect(profile).to.include('solid:oidcIssuer')
121+
// why does this need to be included?
122+
// with the current configuration, 'host' for
123+
// ldp is not set, therefore solid:oidcIssuer is empty
124+
// expect(profile).to.include('<https://example.com>')
125+
126+
const rootAcl = fs.readFileSync(path.join(accountPath, '.acl'), 'utf8')
127+
expect(rootAcl).to.include('<mailto:alice@')
128+
expect(rootAcl).to.include('</alice/#me>')
129+
})
130+
})
131+
})
65132
})

‎test/unit/account-template-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('AccountTemplate', () => {
5454
const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)
5555
expect(substitutions.name).to.equal('Alice Q.')
5656
expect(substitutions.email).to.equal('alice@example.com')
57-
expect(substitutions.webId).to.equal('https://alice.example.com/profile/card#me')
57+
expect(substitutions.webId).to.equal('/profile/card#me')
5858
})
5959
})
6060
})

0 commit comments

Comments
 (0)
Please sign in to comment.