Skip to content

Commit b795602

Browse files
committed
added test cases for relative webid change
1 parent 2a1f7e4 commit b795602

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

lib/models/account-template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class AccountTemplate {
8989
// this means the user's webId and server Uri are the same
9090
// therefore, we use a relative address
9191
if (userAccount.webId.indexOf(this.hostname) > -1) {
92-
realWebId = userAccount.webId.substring(userAccount.webId.indexOf(this.hostname))
92+
realWebId = path.join('/', userAccount.webId.substring(userAccount.webId.indexOf(this.hostname) + this.hostname.length))
9393
} else {
9494
realWebId = userAccount.webId
9595
}

test/integration/account-template-test.js

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ chai.use(sinonChai)
1010
chai.should()
1111

1212
const AccountTemplate = require('../../lib/models/account-template')
13-
13+
const UserAccount = require('../../lib/models/user-account')
1414
const templatePath = path.join(__dirname, '../../default-templates/new-account')
1515
const accountPath = path.join(__dirname, '../resources/new-account')
1616

@@ -62,4 +62,65 @@ describe('AccountTemplate', () => {
6262
})
6363
})
6464
})
65+
66+
describe('templateSubtitutionsFor()', () => {
67+
it('should not update the webid', () => {
68+
AccountTemplate.registerHostname('https://offexample.com/')
69+
70+
const userAccount = new UserAccount({
71+
webId: 'https://alice.example.com/#me',
72+
73+
name: 'Alice Q.'
74+
})
75+
76+
const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)
77+
78+
expect(substitutions.webId).to.equal('https://alice.example.com/#me')
79+
})
80+
81+
it('should update the webid', () => {
82+
AccountTemplate.registerHostname('http://localhost:8443/')
83+
84+
const userAccount = new UserAccount({
85+
webId: 'http://localhost:8443/alice/#me',
86+
87+
name: 'Alice Q.'
88+
})
89+
90+
const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)
91+
92+
expect(substitutions.webId).to.equal('/alice/#me')
93+
})
94+
})
95+
96+
describe('creating account where webId does match server Uri?', () => {
97+
it('should have a relative uri for the base path rather than a complete uri', () => {
98+
AccountTemplate.registerHostname('http://localhost:8443/')
99+
100+
const userAccount = new UserAccount({
101+
webId: 'http://localhost:8443/alice/#me',
102+
103+
name: 'Alice Q.'
104+
})
105+
106+
const substitutions = AccountTemplate.templateSubstitutionsFor(userAccount)
107+
const template = new AccountTemplate({ substitutions })
108+
return AccountTemplate.copyTemplateDir(templatePath, accountPath)
109+
.then(() => {
110+
return template.processAccount(accountPath)
111+
}).then(() => {
112+
const profile = fs.readFileSync(path.join(accountPath, '/profile/card$.ttl'), 'utf8')
113+
expect(profile).to.include('"Alice Q."')
114+
expect(profile).to.include('solid:oidcIssuer')
115+
// why does this need to be included?
116+
// with the current configuration, 'host' for
117+
// ldp is not set, therefore solid:oidcIssuer is empty
118+
// expect(profile).to.include('<https://example.com>')
119+
120+
const rootAcl = fs.readFileSync(path.join(accountPath, '.acl'), 'utf8')
121+
expect(rootAcl).to.include('<mailto:alice@')
122+
expect(rootAcl).to.include('</alice/#me>')
123+
})
124+
})
125+
})
65126
})

0 commit comments

Comments
 (0)