11import Log from '../src/Log' ;
22import MetadataService from '../src/MetadataService' ;
33
4+ import StubJsonService from './StubJsonService' ;
5+
46import chai from 'chai' ;
57chai . should ( ) ;
68let assert = chai . assert ;
@@ -13,7 +15,7 @@ describe("MetadataService", function() {
1315 beforeEach ( function ( ) {
1416 settings = { } ;
1517 stubJsonService = new StubJsonService ( ) ;
16- subject = new MetadataService ( settings , stubJsonService ) ;
18+ subject = new MetadataService ( settings , ( ) => stubJsonService ) ;
1719 } ) ;
1820
1921 describe ( "constructor" , function ( ) {
@@ -163,6 +165,53 @@ describe("MetadataService", function() {
163165
164166 } ) ;
165167
168+ describe ( "getUserInfoUrl" , function ( ) {
169+
170+ it ( "should return a promise" , function ( ) {
171+ subject . getUserInfoUrl ( ) . should . be . instanceof ( Promise ) ;
172+ } ) ;
173+
174+ it ( "should use metadata on settings" , function ( done ) {
175+ settings . metadata = {
176+ userinfo_endpoint : "http://sts/userinfo"
177+ } ;
178+
179+ let p = subject . getUserInfoUrl ( ) ;
180+
181+ p . then ( result => {
182+ result . should . equal ( "http://sts/userinfo" ) ;
183+ done ( ) ;
184+ } ) ;
185+ } ) ;
186+
187+ it ( "should fail if no userinfo_endpoint on metadata" , function ( done ) {
188+ settings . metadata = {
189+ } ;
190+
191+ let p = subject . getUserInfoUrl ( ) ;
192+
193+ p . then ( null , err => {
194+ err . message . should . contain ( "userinfo_endpoint" ) ;
195+ done ( ) ;
196+ } ) ;
197+ } ) ;
198+
199+ it ( "should fail if json call to load metadata fails" , function ( done ) {
200+ settings . metadata = {
201+ metadataUrl :"http://sts/metadata"
202+ } ;
203+ stubJsonService . result = Promise . reject ( "test" ) ;
204+
205+ let p = subject . getUserInfoUrl ( ) ;
206+
207+ p . then ( null , err => {
208+ err . message . should . contain ( "userinfo" ) ;
209+ done ( ) ;
210+ } ) ;
211+ } ) ;
212+
213+ } ) ;
214+
166215 describe ( "getSigningKeys" , function ( ) {
167216
168217 it ( "should return a promise" , function ( ) {
@@ -249,10 +298,3 @@ describe("MetadataService", function() {
249298
250299 } ) ;
251300} ) ;
252-
253- class StubJsonService {
254- getJson ( url ) {
255- this . url = url ;
256- return this . result ;
257- }
258- }
0 commit comments