diff --git a/lib/models/account-manager.js b/lib/models/account-manager.js index ecf73718..8ff4ab13 100644 --- a/lib/models/account-manager.js +++ b/lib/models/account-manager.js @@ -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. diff --git a/lib/models/account-template.js b/lib/models/account-template.js index f03b572e..ddb65c7f 100644 --- a/lib/models/account-template.js +++ b/lib/models/account-template.js @@ -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'] @@ -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 } diff --git a/test/integration/account-manager-test.js b/test/integration/account-manager-test.js index 6eaaa3b3..a939dfce 100644 --- a/test/integration/account-manager-test.js +++ b/test/integration/account-manager-test.js @@ -139,7 +139,7 @@ describe('AccountManager', () => { const rootAcl = fs.readFileSync(path.join(accountDir, '.acl'), 'utf8') expect(rootAcl).to.include('') + expect(rootAcl).to.include('') }) }) }) diff --git a/test/integration/account-template-test.js b/test/integration/account-template-test.js index 6fa388eb..02d195a5 100644 --- a/test/integration/account-template-test.js +++ b/test/integration/account-template-test.js @@ -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') @@ -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: 'alice@example.com', + 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: 'alice@example.com', + 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: 'alice@example.com', + 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: 'alice@example.com', + 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('') + + const rootAcl = fs.readFileSync(path.join(accountPath, '.acl'), 'utf8') + expect(rootAcl).to.include('') + }) + }) + }) }) diff --git a/test/unit/account-template-test.js b/test/unit/account-template-test.js index 67bdf18e..3a2bd43b 100644 --- a/test/unit/account-template-test.js +++ b/test/unit/account-template-test.js @@ -54,7 +54,7 @@ describe('AccountTemplate', () => { const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount) expect(substitutions.name).to.equal('Alice Q.') expect(substitutions.email).to.equal('alice@example.com') - expect(substitutions.webId).to.equal('https://alice.example.com/profile/card#me') + expect(substitutions.webId).to.equal('/profile/card#me') }) }) })