11import OidcClientService from '../src/OidcClientService' ;
2+ import SignoutRequest from '../src/SignoutRequest' ;
3+ import Log from '../src/Log' ;
4+
5+ import StubMetadataService from './StubMetadataService' ;
26
37import chai from 'chai' ;
48chai . should ( ) ;
@@ -7,12 +11,17 @@ let assert = chai.assert;
711describe ( "OidcClientService" , function ( ) {
812 let settings ;
913 let subject ;
14+ let stubMetadataService ;
1015
1116 beforeEach ( function ( ) {
17+ Log . setLogger ( console ) ;
18+ Log . level = Log . NONE ;
19+
1220 settings = { } ;
13- subject = new OidcClientService ( settings ) ;
21+ stubMetadataService = new StubMetadataService ( ) ;
22+ subject = new OidcClientService ( settings , ( ) => stubMetadataService ) ;
1423 } ) ;
15-
24+
1625 describe ( "constructor" , function ( ) {
1726 it ( "should require a settings param" , function ( ) {
1827 try {
@@ -25,4 +34,54 @@ describe("OidcClientService", function() {
2534 } ) ;
2635
2736 } ) ;
37+
38+ describe ( "createSignoutRequest" , function ( ) {
39+
40+ it ( "should return a promise" , function ( ) {
41+ stubMetadataService . getEndSessionEndpointResult = Promise . resolve ( "http://sts/signout" ) ;
42+ subject . createSignoutRequest ( ) . should . be . instanceof ( Promise ) ;
43+ } ) ;
44+
45+ it ( "should return SignoutRequest" , function ( done ) {
46+ stubMetadataService . getEndSessionEndpointResult = Promise . resolve ( "http://sts/signout" ) ;
47+
48+ var p = subject . createSignoutRequest ( ) ;
49+
50+ p . then ( request => {
51+ request . should . be . instanceof ( SignoutRequest ) ;
52+ done ( ) ;
53+ } ) ;
54+ } ) ;
55+
56+ it ( "should pass params to SignoutRequest" , function ( done ) {
57+ stubMetadataService . getEndSessionEndpointResult = Promise . resolve ( "http://sts/signout" ) ;
58+
59+ var p = subject . createSignoutRequest ( {
60+ state :'foo' ,
61+ post_logout_redirect_uri :"bar" ,
62+ id_token_hint :"baz"
63+ } ) ;
64+
65+ p . then ( request => {
66+ var url = request . signoutUrl ;
67+ url . should . contain ( "http://sts/signout" ) ;
68+ url . should . contain ( "foo" ) ;
69+ url . should . contain ( "bar" ) ;
70+ url . should . contain ( "baz" ) ;
71+ done ( ) ;
72+ } ) ;
73+ } ) ;
74+
75+ it ( "should fail if metadata fails" , function ( done ) {
76+ stubMetadataService . getEndSessionEndpointResult = Promise . reject ( "test" ) ;
77+
78+ var p = subject . createSignoutRequest ( ) ;
79+
80+ p . then ( null , err => {
81+ err . message . should . contain ( "signout" ) ;
82+ done ( ) ;
83+ } ) ;
84+ } ) ;
85+
86+ } ) ;
2887} ) ;
0 commit comments