Skip to content

Commit 62e67c4

Browse files
authored
Merge pull request #59 from zeroid/master
Give priority to oidcIssuer in WebID profile
2 parents 4fdbe5f + d98e023 commit 62e67c4

File tree

5 files changed

+46
-10
lines changed

5 files changed

+46
-10
lines changed

src/preferred-provider.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ function providerExists (uri) {
6262
* provider URI was found, reject with an error.
6363
*/
6464
function discoverProviderFor (webId) {
65-
return discoverFromHeaders(webId)
65+
return discoverFromProfile(webId)
6666

67-
.then(providerFromHeaders => providerFromHeaders || discoverFromProfile(webId))
67+
.then(providerFromProfile => providerFromProfile || discoverFromHeaders(webId))
6868

6969
.then(providerUri => {
7070
validateProviderUri(providerUri, webId) // Throw an error if empty or invalid
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = `
2+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
3+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
4+
@prefix pim: <http://www.w3.org/ns/pim/space#>.
5+
@prefix schema: <http://schema.org/>.
6+
@prefix ldp: <http://www.w3.org/ns/ldp#>.
7+
8+
<>
9+
a foaf:PersonalProfileDocument ;
10+
foaf:primaryTopic <#me> .
11+
12+
<#me>
13+
a schema:Person ;
14+
15+
solid:account </> ; # link to the account uri
16+
pim:storage </> ; # root storage
17+
18+
solid:oidcIssuer <https://provider.com> .
19+
`

test/resources/sample-webid-profile.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,5 @@ module.exports = `
1313
a schema:Person ;
1414
1515
solid:account </> ; # link to the account uri
16-
pim:storage </> ; # root storage
17-
18-
solid:oidcIssuer <https://provider.com> .
16+
pim:storage </> . # root storage
1917
`

test/unit/oidc-manager-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ chai.should()
1414

1515
const OidcManager = require('../../src/oidc-manager')
1616

17+
const sampleProfileSrc = require('../resources/sample-webid-profile')
18+
1719
describe('OidcManager', () => {
1820
afterEach(() => {
1921
nock.cleanAll()
@@ -252,6 +254,10 @@ describe('OidcManager', () => {
252254
sub: 'https://example.com/profile#me'
253255
}
254256

257+
nock('https://example.com')
258+
.get('/profile')
259+
.reply(200, sampleProfileSrc)
260+
255261
nock('https://example.com')
256262
.options('/profile')
257263
.reply(204, 'No content', {
@@ -270,6 +276,10 @@ describe('OidcManager', () => {
270276
sub: 'https://example.com/profile#me'
271277
}
272278

279+
nock('https://example.com')
280+
.get('/profile')
281+
.reply(200, sampleProfileSrc)
282+
273283
nock('https://example.com')
274284
.options('/profile')
275285
.reply(204, 'No content', {

test/unit/preferred-provider-test.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const expect = chai.expect
1212
const serverUri = 'https://example.com'
1313

1414
const sampleProfileSrc = require('../resources/sample-webid-profile')
15+
const sampleProfileSrcWithOidcIssuer = require('../resources/sample-webid-profile-with-oidc-issuer')
1516

1617
describe('preferred-provider.js', () => {
1718
afterEach(() => {
@@ -22,6 +23,10 @@ describe('preferred-provider.js', () => {
2223
const webId = 'https://example.com/#me'
2324

2425
it('should extract and validate the provider uri from link rel header', () => {
26+
nock('https://example.com')
27+
.get('/')
28+
.reply(200, sampleProfileSrc)
29+
2530
nock(serverUri)
2631
.options('/')
2732
.reply(204, 'No content', {
@@ -35,6 +40,10 @@ describe('preferred-provider.js', () => {
3540
})
3641

3742
it('should not drop the path from extracted provider uri', () => {
43+
nock('https://example.com')
44+
.get('/')
45+
.reply(200, sampleProfileSrc)
46+
3847
nock(serverUri)
3948
.options('/')
4049
.reply(204, 'No content', {
@@ -48,13 +57,9 @@ describe('preferred-provider.js', () => {
4857
})
4958

5059
it('should extract and validate the provider uri from the webid profile', () => {
51-
nock(serverUri)
52-
.options('/')
53-
.reply(204, 'No content')
54-
5560
nock(serverUri)
5661
.get('/')
57-
.reply(200, sampleProfileSrc, {
62+
.reply(200, sampleProfileSrcWithOidcIssuer, {
5863
'Content-Type': 'text/turtle'
5964
})
6065

@@ -147,6 +152,10 @@ describe('preferred-provider.js', () => {
147152
})
148153

149154
it('should discover preferred provider if no oidc capability at webid', () => {
155+
nock('https://example.com')
156+
.get('/profile')
157+
.reply(200, sampleProfileSrc)
158+
150159
nock('https://example.com')
151160
.head('/.well-known/openid-configuration')
152161
.reply(404)

0 commit comments

Comments
 (0)