From d98e0231f27c84fa32acb46725bea3bc8d3d83e0 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Wed, 6 Jan 2021 16:18:51 -0700 Subject: [PATCH] Give priority to oidcIssuer in WebID profile --- src/preferred-provider.js | 4 ++-- .../sample-webid-profile-with-oidc-issuer.js | 19 +++++++++++++++++++ test/resources/sample-webid-profile.js | 4 +--- test/unit/oidc-manager-test.js | 10 ++++++++++ test/unit/preferred-provider-test.js | 19 ++++++++++++++----- 5 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 test/resources/sample-webid-profile-with-oidc-issuer.js diff --git a/src/preferred-provider.js b/src/preferred-provider.js index b4845d4..647a182 100644 --- a/src/preferred-provider.js +++ b/src/preferred-provider.js @@ -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 diff --git a/test/resources/sample-webid-profile-with-oidc-issuer.js b/test/resources/sample-webid-profile-with-oidc-issuer.js new file mode 100644 index 0000000..5312861 --- /dev/null +++ b/test/resources/sample-webid-profile-with-oidc-issuer.js @@ -0,0 +1,19 @@ +module.exports = ` +@prefix solid: . +@prefix foaf: . +@prefix pim: . +@prefix schema: . +@prefix ldp: . + +<> + a foaf:PersonalProfileDocument ; + foaf:primaryTopic <#me> . + +<#me> + a schema:Person ; + + solid:account ; # link to the account uri + pim:storage ; # root storage + + solid:oidcIssuer . +` diff --git a/test/resources/sample-webid-profile.js b/test/resources/sample-webid-profile.js index 5312861..fa434af 100644 --- a/test/resources/sample-webid-profile.js +++ b/test/resources/sample-webid-profile.js @@ -13,7 +13,5 @@ module.exports = ` a schema:Person ; solid:account ; # link to the account uri - pim:storage ; # root storage - - solid:oidcIssuer . + pim:storage . # root storage ` diff --git a/test/unit/oidc-manager-test.js b/test/unit/oidc-manager-test.js index 4f12084..fa09557 100644 --- a/test/unit/oidc-manager-test.js +++ b/test/unit/oidc-manager-test.js @@ -14,6 +14,8 @@ chai.should() const OidcManager = require('../../src/oidc-manager') +const sampleProfileSrc = require('../resources/sample-webid-profile') + describe('OidcManager', () => { afterEach(() => { nock.cleanAll() @@ -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', { @@ -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', { diff --git a/test/unit/preferred-provider-test.js b/test/unit/preferred-provider-test.js index e17a90e..d94f799 100644 --- a/test/unit/preferred-provider-test.js +++ b/test/unit/preferred-provider-test.js @@ -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(() => { @@ -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', { @@ -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', { @@ -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' }) @@ -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)