Skip to content

Commit

Permalink
added test cases for relative webid change
Browse files Browse the repository at this point in the history
  • Loading branch information
zg009 committed May 11, 2024
1 parent 2a1f7e4 commit b795602
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/models/account-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class AccountTemplate {
// this means the user's webId and server Uri are the same
// therefore, we use a relative address
if (userAccount.webId.indexOf(this.hostname) > -1) {
realWebId = userAccount.webId.substring(userAccount.webId.indexOf(this.hostname))
realWebId = path.join('/', userAccount.webId.substring(userAccount.webId.indexOf(this.hostname) + this.hostname.length))
} else {
realWebId = userAccount.webId
}
Expand Down
63 changes: 62 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,65 @@ describe('AccountTemplate', () => {
})
})
})

describe('templateSubtitutionsFor()', () => {
it('should not update the webid', () => {
AccountTemplate.registerHostname('https://offexample.com/')

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('https://alice.example.com/#me')
})

it('should update the webid', () => {
AccountTemplate.registerHostname('http://localhost:8443/')

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', () => {
AccountTemplate.registerHostname('http://localhost:8443/')

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>')
})
})
})
})

0 comments on commit b795602

Please sign in to comment.