Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/solid/node-solid-server int…
Browse files Browse the repository at this point in the history
…o main
  • Loading branch information
bourgeoa committed Nov 6, 2024
2 parents a3ab58e + fa7e7e5 commit 4ce0c0e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
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')
})
})
})

0 comments on commit 4ce0c0e

Please sign in to comment.