From b795602606ac0519afdf0977c9613bc4ce5b53d1 Mon Sep 17 00:00:00 2001 From: Zach Date: Fri, 10 May 2024 23:52:08 -0500 Subject: [PATCH] added test cases for relative webid change --- lib/models/account-template.js | 2 +- test/integration/account-template-test.js | 63 ++++++++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/lib/models/account-template.js b/lib/models/account-template.js index 3271f435..04dd8809 100644 --- a/lib/models/account-template.js +++ b/lib/models/account-template.js @@ -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 } diff --git a/test/integration/account-template-test.js b/test/integration/account-template-test.js index 6fa388eb..64005403 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,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: 'alice@example.com', + 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: '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', () => { + AccountTemplate.registerHostname('http://localhost:8443/') + + 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('') + }) + }) + }) })