Skip to content

Commit

Permalink
Merge pull request #59 from zeroid/master
Browse files Browse the repository at this point in the history
Give priority to oidcIssuer in WebID profile
  • Loading branch information
bourgeoa authored Mar 4, 2022
2 parents 4fdbe5f + d98e023 commit 62e67c4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/preferred-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ function providerExists (uri) {
* provider URI was found, reject with an error.
*/
function discoverProviderFor (webId) {
return discoverFromHeaders(webId)
return discoverFromProfile(webId)

.then(providerFromHeaders => providerFromHeaders || discoverFromProfile(webId))
.then(providerFromProfile => providerFromProfile || discoverFromHeaders(webId))

.then(providerUri => {
validateProviderUri(providerUri, webId) // Throw an error if empty or invalid
Expand Down
19 changes: 19 additions & 0 deletions test/resources/sample-webid-profile-with-oidc-issuer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = `
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix pim: <http://www.w3.org/ns/pim/space#>.
@prefix schema: <http://schema.org/>.
@prefix ldp: <http://www.w3.org/ns/ldp#>.
<>
a foaf:PersonalProfileDocument ;
foaf:primaryTopic <#me> .
<#me>
a schema:Person ;
solid:account </> ; # link to the account uri
pim:storage </> ; # root storage
solid:oidcIssuer <https://provider.com> .
`
4 changes: 1 addition & 3 deletions test/resources/sample-webid-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ module.exports = `
a schema:Person ;
solid:account </> ; # link to the account uri
pim:storage </> ; # root storage
solid:oidcIssuer <https://provider.com> .
pim:storage </> . # root storage
`
10 changes: 10 additions & 0 deletions test/unit/oidc-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ chai.should()

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

const sampleProfileSrc = require('../resources/sample-webid-profile')

describe('OidcManager', () => {
afterEach(() => {
nock.cleanAll()
Expand Down Expand Up @@ -252,6 +254,10 @@ describe('OidcManager', () => {
sub: 'https://example.com/profile#me'
}

nock('https://example.com')
.get('/profile')
.reply(200, sampleProfileSrc)

nock('https://example.com')
.options('/profile')
.reply(204, 'No content', {
Expand All @@ -270,6 +276,10 @@ describe('OidcManager', () => {
sub: 'https://example.com/profile#me'
}

nock('https://example.com')
.get('/profile')
.reply(200, sampleProfileSrc)

nock('https://example.com')
.options('/profile')
.reply(204, 'No content', {
Expand Down
19 changes: 14 additions & 5 deletions test/unit/preferred-provider-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const expect = chai.expect
const serverUri = 'https://example.com'

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

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

it('should extract and validate the provider uri from link rel header', () => {
nock('https://example.com')
.get('/')
.reply(200, sampleProfileSrc)

nock(serverUri)
.options('/')
.reply(204, 'No content', {
Expand All @@ -35,6 +40,10 @@ describe('preferred-provider.js', () => {
})

it('should not drop the path from extracted provider uri', () => {
nock('https://example.com')
.get('/')
.reply(200, sampleProfileSrc)

nock(serverUri)
.options('/')
.reply(204, 'No content', {
Expand All @@ -48,13 +57,9 @@ describe('preferred-provider.js', () => {
})

it('should extract and validate the provider uri from the webid profile', () => {
nock(serverUri)
.options('/')
.reply(204, 'No content')

nock(serverUri)
.get('/')
.reply(200, sampleProfileSrc, {
.reply(200, sampleProfileSrcWithOidcIssuer, {
'Content-Type': 'text/turtle'
})

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

it('should discover preferred provider if no oidc capability at webid', () => {
nock('https://example.com')
.get('/profile')
.reply(200, sampleProfileSrc)

nock('https://example.com')
.head('/.well-known/openid-configuration')
.reply(404)
Expand Down

0 comments on commit 62e67c4

Please sign in to comment.