Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give priority to oidcIssuer in WebID profile #59

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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