Skip to content

Commit bb41d04

Browse files
committed
catch error iri#issue
1 parent 90b4d0c commit bb41d04

3 files changed

Lines changed: 56 additions & 13 deletions

File tree

src/authn/SolidAuthnLogic.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ export class SolidAuthnLogic implements AuthnLogic {
1717
currentUser(): NamedNode | null {
1818
const app = appContext()
1919
if (app.viewingNoAuthPage) {
20-
debug.log(`currentUser: viewingNoAuthPage webId=${app.webId}`)
2120
return sym(app.webId)
2221
}
2322
if (this && this.session && this.session.info && this.session.info.webId && this.session.info.isLoggedIn) {
24-
debug.log(`currentUser: session webId=${this.session.info.webId}`)
2523
return sym(this.session.info.webId)
2624
}
27-
debug.log('currentUser: no user found, falling back to offlineTestID')
2825
return offlineTestID() // null unless testing
2926
}
3027

src/typeIndex/typeIndexLogic.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic):
2727
debug.warn(message)
2828
}
2929
let publicTypeIndex
30-
if (suggestion) {
31-
try {
32-
publicTypeIndex = await utilityLogic.followOrCreateLink(user, ns.solid('publicTypeIndex') as NamedNode, suggestion, profile)
33-
} catch (err) {
34-
const message = `User ${user} has no pointer in profile to publicTypeIndex file.`
35-
debug.warn(message)
36-
}
30+
try {
31+
publicTypeIndex =
32+
store.any(user, ns.solid('publicTypeIndex'), undefined, profile) ||
33+
(suggestion
34+
? await utilityLogic.followOrCreateLink(user, ns.solid('publicTypeIndex') as NamedNode, suggestion, profile)
35+
: null)
36+
} catch (err) {
37+
const message = `User ${user} has no pointer in profile to publicTypeIndex file: ${err}`
38+
debug.warn(message)
3739
}
3840
const publicScopes = publicTypeIndex ? [{ label: 'public', index: publicTypeIndex as NamedNode, agent: user }] : []
3941

@@ -62,7 +64,7 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic):
6264
? await utilityLogic.followOrCreateLink(user, ns.solid('privateTypeIndex') as NamedNode, suggestedPrivateTypeIndex, preferencesFile)
6365
: null)
6466
} catch (err) {
65-
const message = `User ${user} has no pointer in preference file to privateTypeIndex file.`
67+
const message = `User ${user} has no pointer in preference file to privateTypeIndex file: ${err}`
6668
debug.warn(message)
6769
}
6870
privateScopes = privateTypeIndex ? [{ label: 'private', index: privateTypeIndex as NamedNode, agent: user }] : []

test/typeIndexLogic.test.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @jest-environment jsdom
33
*
44
*/
5-
import { Fetcher, Store, sym, UpdateManager } from 'rdflib'
5+
import { Fetcher, parse, Store, sym, UpdateManager } from 'rdflib'
66
import { createAclLogic } from '../src/acl/aclLogic'
77
import { createProfileLogic } from '../src/profile/profileLogic'
88
import { createTypeIndexLogic} from '../src/typeIndex/typeIndexLogic'
@@ -51,7 +51,7 @@ describe('TypeIndex logic NEW', () => {
5151
requests = []
5252
statustoBeReturned = 200
5353

54-
fetchMock.mockIf(/^https?.*$/, async req => {
54+
fetchMock.mockIf(/^(https?|mailto):.*$/, async req => {
5555

5656
if (req.method !== 'GET') {
5757
requests.push(req)
@@ -131,6 +131,50 @@ describe('TypeIndex logic NEW', () => {
131131
expect(store.statementsMatching(null, null, null, AlicePrivateTypeIndex).length).toEqual(8)
132132
expect(store.statementsMatching(null, null, null, AlicePublicTypeIndex).length).toEqual(8)
133133
})
134+
it('uses existing publicTypeIndex when suggestion fails', async () => {
135+
const carol = sym('urn:uuid:carol#me')
136+
const CarolProfileDoc = carol.doc()
137+
const CarolPreferencesFile = sym('https://carol.example.com/settings/prefs.ttl')
138+
const CarolPublicTypeIndex = sym('https://carol.example.com/profile/public-type-index.ttl')
139+
const CarolPrivateTypeIndex = sym('https://carol.example.com/settings/private-type-index.ttl')
140+
141+
const CarolProfile = `
142+
<#me> a vcard:Individual;
143+
space:preferencesFile ${CarolPreferencesFile};
144+
solid:publicTypeIndex ${CarolPublicTypeIndex}.
145+
`
146+
const CarolPreferences = `
147+
${carol} solid:privateTypeIndex ${CarolPrivateTypeIndex} .
148+
`
149+
150+
web[CarolPreferencesFile.uri] = CarolPreferences
151+
web[CarolPublicTypeIndex.uri] = `
152+
:t solid:forClass wf:Tracker; solid:instance <../publicStuff/actionItems.ttl#this> .
153+
`
154+
web[CarolPrivateTypeIndex.uri] = `
155+
:t solid:forClass wf:Tracker; solid:instance <../privateStuff/ToDo.ttl#this> .
156+
`
157+
158+
const util = createUtilityLogic(store, createAclLogic(store), createContainerLogic(store))
159+
const profileLogic = {
160+
loadProfile: async (user) => {
161+
parse(prefixes + CarolProfile, store, CarolProfileDoc.uri, 'text/turtle')
162+
return user.doc()
163+
},
164+
silencedLoadPreferences: async () => {
165+
parse(prefixes + CarolPreferences, store, CarolPreferencesFile.uri, 'text/turtle')
166+
return CarolPreferencesFile
167+
}
168+
}
169+
const typeIndexLogicWithStub = createTypeIndexLogic(store, authn, profileLogic as any, util)
170+
171+
const result = await typeIndexLogicWithStub.loadTypeIndexesFor(carol)
172+
expect(result).toEqual([
173+
{ label: 'public', index: CarolPublicTypeIndex as any, agent: carol as any },
174+
{ label: 'private', index: CarolPrivateTypeIndex as any, agent: carol as any }
175+
])
176+
expect(requests.length).toEqual(0)
177+
})
134178
})
135179

136180
const ClubScopes =

0 commit comments

Comments
 (0)