Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1783 #1784

Merged
merged 12 commits into from
Nov 5, 2024
2 changes: 1 addition & 1 deletion lib/models/account-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AccountManager {
*
* ```
* let options = { host, multiuser, store }
* let accontManager = AccountManager.from(options)
* let accountManager = AccountManager.from(options)
* ```
*
* @param [options={}] {Object} See the `constructor()` docstring.
Expand Down
5 changes: 4 additions & 1 deletion lib/models/account-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const recursiveRead = require('recursive-readdir')
const fsUtils = require('../common/fs-utils')
const templateUtils = require('../common/template-utils')
const LDP = require('../ldp')
const { URL } = require('url')

const TEMPLATE_EXTENSIONS = ['.acl', '.meta', '.json', '.hbs', '.handlebars']
const TEMPLATE_FILES = ['card']
Expand Down Expand Up @@ -72,9 +73,11 @@ class AccountTemplate {
* @return {Object}
*/
static templateSubstitutionsFor (userAccount) {
const webUri = new URL(userAccount.webId)
const podRelWebId = userAccount.webId.replace(webUri.origin, '')
const substitutions = {
name: userAccount.displayName,
webId: userAccount.webId,
webId: userAccount.externalWebId ? userAccount.webId : podRelWebId,
email: userAccount.email,
idp: userAccount.idp
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/account-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('AccountManager', () => {

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>')
expect(rootAcl).to.include('</profile/card#me>')
})
})
})
Expand Down
69 changes: 68 additions & 1 deletion test/integration/account-template-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ chai.use(sinonChai)
chai.should()

const AccountTemplate = require('../../lib/models/account-template')

const UserAccount = require('../../lib/models/user-account')
const templatePath = path.join(__dirname, '../../default-templates/new-account')
const accountPath = path.join(__dirname, '../resources/new-account')

Expand Down Expand Up @@ -62,4 +62,71 @@ describe('AccountTemplate', () => {
})
})
})

describe('templateSubtitutionsFor()', () => {
it('should not update the webid', () => {
const userAccount = new UserAccount({
webId: 'https://alice.example.com/#me',
email: '[email protected]',
name: 'Alice Q.'
})

const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)

expect(substitutions.webId).to.equal('/#me')
})

it('should not update the nested webid', () => {
const userAccount = new UserAccount({
webId: 'https://alice.example.com/alice/#me',
email: '[email protected]',
name: 'Alice Q.'
})

const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)

expect(substitutions.webId).to.equal('/alice/#me')
})

it('should update the webid', () => {
const userAccount = new UserAccount({
webId: 'http://localhost:8443/alice/#me',
email: '[email protected]',
name: 'Alice Q.'
})

const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)

expect(substitutions.webId).to.equal('/alice/#me')
})
})

describe('creating account where webId does match server Uri?', () => {
it('should have a relative uri for the base path rather than a complete uri', () => {
const userAccount = new UserAccount({
webId: 'http://localhost:8443/alice/#me',
email: '[email protected]',
name: 'Alice Q.'
})

const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)
const template = new AccountTemplate({ substitutions })
return AccountTemplate.copyTemplateDir(templatePath, accountPath)
.then(() => {
return template.processAccount(accountPath)
}).then(() => {
const profile = fs.readFileSync(path.join(accountPath, '/profile/card$.ttl'), 'utf8')
expect(profile).to.include('"Alice Q."')
expect(profile).to.include('solid:oidcIssuer')
// why does this need to be included?
// with the current configuration, 'host' for
// ldp is not set, therefore solid:oidcIssuer is empty
// expect(profile).to.include('<https://example.com>')

const rootAcl = fs.readFileSync(path.join(accountPath, '.acl'), 'utf8')
expect(rootAcl).to.include('<mailto:alice@')
expect(rootAcl).to.include('</alice/#me>')
})
})
})
})
2 changes: 1 addition & 1 deletion test/unit/account-template-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('AccountTemplate', () => {
const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)
expect(substitutions.name).to.equal('Alice Q.')
expect(substitutions.email).to.equal('[email protected]')
expect(substitutions.webId).to.equal('https://alice.example.com/profile/card#me')
expect(substitutions.webId).to.equal('/profile/card#me')
})
})
})
Loading