-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
look for typed services providing Auth2 token/logout (#3789)
- DRY search routines into functions defined in getServices - all routines should look for Auth2 types and Auth1 profiles - include search for uncoducmented Auth1 implementation of explicit probe service
- Loading branch information
Showing
5 changed files
with
143 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { v4 as uuid } from 'uuid'; | ||
import { | ||
anyAuthServices, getLogoutService, getProbeService, getTokenService, | ||
} from '../../../src/lib/getServices'; | ||
|
||
/** | ||
*/ | ||
function resourceFixtureWithService(props) { | ||
return { | ||
id: uuid(), | ||
services: [ | ||
{ ...props }, | ||
], | ||
type: 'Dataset', | ||
}; | ||
} | ||
|
||
/** | ||
*/ | ||
function actualLogoutServiceId(resource) { | ||
const service = getLogoutService(resource); | ||
return service | ||
&& service.id; | ||
} | ||
|
||
/** | ||
*/ | ||
function actualTokenServiceId(resource) { | ||
const service = getTokenService(resource); | ||
return service | ||
&& service.id; | ||
} | ||
|
||
/** | ||
*/ | ||
function actualProbeServiceId(resource) { | ||
const service = getProbeService(resource); | ||
return service | ||
&& service.id; | ||
} | ||
|
||
describe('anyAuthServices', () => { | ||
it('returns a filtered list', () => { | ||
const serviceId = uuid(); | ||
const auth0 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/0/anyService' }); | ||
expect(anyAuthServices(auth0).length).toEqual(1); | ||
const auth1 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/1/anyService' }); | ||
expect(anyAuthServices(auth1).length).toEqual(1); | ||
const auth2 = resourceFixtureWithService({ id: serviceId, type: 'AuthAnyService2' }); | ||
expect(anyAuthServices(auth2).length).toEqual(1); | ||
const notAuthProfile = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/not-auth/1/anyService' }); | ||
expect(anyAuthServices(notAuthProfile).length).toEqual(0); | ||
const notAuthType = resourceFixtureWithService({ id: serviceId, type: 'NotAuthAnyService2' }); | ||
expect(anyAuthServices(notAuthType).length).toEqual(0); | ||
}); | ||
}); | ||
|
||
describe('getLogoutService', () => { | ||
it('returns a Service', () => { | ||
const serviceId = uuid(); | ||
const auth0 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/0/logout' }); | ||
expect(actualLogoutServiceId(auth0)).toEqual(serviceId); | ||
const auth1 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/1/logout' }); | ||
expect(actualLogoutServiceId(auth1)).toEqual(serviceId); | ||
const auth2 = resourceFixtureWithService({ id: serviceId, type: 'AuthLogoutService2' }); | ||
expect(actualLogoutServiceId(auth2)).toEqual(serviceId); | ||
}); | ||
}); | ||
|
||
describe('getProbeService', () => { | ||
it('returns a Service', () => { | ||
const serviceId = uuid(); | ||
const auth1 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/1/probe' }); | ||
expect(actualProbeServiceId(auth1)).toEqual(serviceId); | ||
const auth2 = resourceFixtureWithService({ id: serviceId, type: 'AuthProbeService2' }); | ||
expect(actualProbeServiceId(auth2)).toEqual(serviceId); | ||
}); | ||
}); | ||
|
||
describe('getTokenService', () => { | ||
it('returns a Service', () => { | ||
const serviceId = uuid(); | ||
const auth0 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/0/token' }); | ||
expect(actualTokenServiceId(auth0)).toEqual(serviceId); | ||
const auth1 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/1/token' }); | ||
expect(actualTokenServiceId(auth1)).toEqual(serviceId); | ||
const auth2 = resourceFixtureWithService({ id: serviceId, type: 'AuthAccessTokenService2' }); | ||
expect(actualTokenServiceId(auth2)).toEqual(serviceId); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Utils } from 'manifesto.js'; | ||
import { filterByTypes } from './typeFilters'; | ||
|
||
/** | ||
*/ | ||
export function anyAuthServices(resource) { | ||
return resource | ||
&& Utils.getServices(resource).filter(s => (s.getProfile() | ||
&& s.getProfile().match(/http:\/\/iiif.io\/api\/auth\//)) | ||
|| (s.getProperty('type') | ||
&& s.getProperty('type').match(/^Auth.*2$/))); | ||
} | ||
|
||
/** | ||
*/ | ||
export function getProbeService(resource) { | ||
return resource | ||
&& ( | ||
Utils.getService(resource, 'http://iiif.io/api/auth/1/probe') | ||
|| filterByTypes(Utils.getServices(resource), 'AuthProbeService2')[0] | ||
); | ||
} | ||
|
||
/** | ||
*/ | ||
export function getTokenService(resource) { | ||
return resource | ||
&& ( | ||
Utils.getService(resource, 'http://iiif.io/api/auth/1/token') | ||
|| Utils.getService(resource, 'http://iiif.io/api/auth/0/token') | ||
|| filterByTypes(Utils.getServices(resource), 'AuthAccessTokenService2')[0] | ||
); | ||
} | ||
|
||
/** | ||
*/ | ||
export function getLogoutService(resource) { | ||
return resource | ||
&& ( | ||
Utils.getService(resource, 'http://iiif.io/api/auth/1/logout') | ||
|| Utils.getService(resource, 'http://iiif.io/api/auth/0/logout') | ||
|| filterByTypes(Utils.getServices(resource), 'AuthLogoutService2')[0] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters