@@ -10,6 +10,13 @@ import bootstrap, { skipConsent, assertNoPendingInterceptors, mock } from '../te
1010
1111const sinon = createSandbox ( ) ;
1212
13+ async function consumeBody ( body ) {
14+ if ( typeof body === 'string' ) return body ;
15+ const chunks = [ ] ;
16+ for await ( const chunk of body ) chunks . push ( chunk ) ;
17+ return Buffer . concat ( chunks ) . toString ( ) ;
18+ }
19+
1320describe ( 'Back-Channel Logout 1.0' , ( ) => {
1421 before ( bootstrap ( import . meta. url ) ) ;
1522
@@ -24,20 +31,20 @@ describe('Back-Channel Logout 1.0', () => {
2431 . intercept ( {
2532 path : '/backchannel_logout' ,
2633 method : 'POST' ,
27- body ( value ) {
28- expect ( value ) . to . match ( / ^ l o g o u t _ t o k e n = ( ( [ \w - ] + \. ? ) { 3 } ) $ / ) ;
29- const header = JSON . parse ( base64url . decode ( RegExp . $1 . split ( '.' ) [ 0 ] ) ) ;
30- expect ( header ) . to . have . property ( 'typ' , 'logout+jwt' ) ;
31- const decoded = JSON . parse ( base64url . decode ( RegExp . $1 . split ( '.' ) [ 1 ] ) ) ;
32- expect ( decoded ) . to . have . all . keys ( 'sub' , 'events' , 'iat' , 'exp' , 'aud' , 'iss' , 'jti' , 'sid' ) ;
33- expect ( decoded ) . to . have . property ( 'events' ) . and . eql ( { 'http://schemas.openid.net/event/backchannel-logout' : { } } ) ;
34- expect ( decoded ) . to . have . property ( 'aud' , 'client' ) ;
35- expect ( decoded ) . to . have . property ( 'sub' , 'subject' ) ;
36- expect ( decoded ) . to . have . property ( 'sid' , 'foo' ) ;
37- return true ;
38- } ,
3934 } )
40- . reply ( 200 ) ;
35+ . reply ( 200 , async ( opts ) => {
36+ const value = await consumeBody ( opts . body ) ;
37+ expect ( value ) . to . match ( / ^ l o g o u t _ t o k e n = ( ( [ \w - ] + \. ? ) { 3 } ) $ / ) ;
38+ const header = JSON . parse ( base64url . decode ( RegExp . $1 . split ( '.' ) [ 0 ] ) ) ;
39+ expect ( header ) . to . have . property ( 'typ' , 'logout+jwt' ) ;
40+ const decoded = JSON . parse ( base64url . decode ( RegExp . $1 . split ( '.' ) [ 1 ] ) ) ;
41+ expect ( decoded ) . to . have . all . keys ( 'sub' , 'events' , 'iat' , 'exp' , 'aud' , 'iss' , 'jti' , 'sid' ) ;
42+ expect ( decoded ) . to . have . property ( 'events' ) . and . eql ( { 'http://schemas.openid.net/event/backchannel-logout' : { } } ) ;
43+ expect ( decoded ) . to . have . property ( 'aud' , 'client' ) ;
44+ expect ( decoded ) . to . have . property ( 'sub' , 'subject' ) ;
45+ expect ( decoded ) . to . have . property ( 'sid' , 'foo' ) ;
46+ return '' ;
47+ } ) ;
4148
4249 return client . backchannelLogout ( 'subject' , 'foo' ) ;
4350 } ) ;
@@ -49,18 +56,18 @@ describe('Back-Channel Logout 1.0', () => {
4956 . intercept ( {
5057 path : '/backchannel_logout' ,
5158 method : 'POST' ,
52- body ( value ) {
53- expect ( value ) . to . match ( / ^ l o g o u t _ t o k e n = ( ( [ \w - ] + \. ? ) { 3 } ) $ / ) ;
54- const decoded = JSON . parse ( base64url . decode ( RegExp . $1 . split ( '.' ) [ 1 ] ) ) ;
55- expect ( decoded ) . to . have . all . keys ( 'sub' , 'events' , 'iat' , 'exp' , 'aud' , 'iss' , 'jti' ) ;
56- expect ( decoded ) . to . have . property ( 'events' ) . and . eql ( { 'http://schemas.openid.net/event/backchannel-logout' : { } } ) ;
57- expect ( decoded ) . to . have . property ( 'aud' , 'no-sid' ) ;
58- expect ( decoded ) . to . have . property ( 'sub' , 'subject' ) ;
59- expect ( decoded ) . not . to . have . property ( 'sid' ) ;
60- return true ;
61- } ,
6259 } )
63- . reply ( 200 ) ;
60+ . reply ( 200 , async ( opts ) => {
61+ const value = await consumeBody ( opts . body ) ;
62+ expect ( value ) . to . match ( / ^ l o g o u t _ t o k e n = ( ( [ \w - ] + \. ? ) { 3 } ) $ / ) ;
63+ const decoded = JSON . parse ( base64url . decode ( RegExp . $1 . split ( '.' ) [ 1 ] ) ) ;
64+ expect ( decoded ) . to . have . all . keys ( 'sub' , 'events' , 'iat' , 'exp' , 'aud' , 'iss' , 'jti' ) ;
65+ expect ( decoded ) . to . have . property ( 'events' ) . and . eql ( { 'http://schemas.openid.net/event/backchannel-logout' : { } } ) ;
66+ expect ( decoded ) . to . have . property ( 'aud' , 'no-sid' ) ;
67+ expect ( decoded ) . to . have . property ( 'sub' , 'subject' ) ;
68+ expect ( decoded ) . not . to . have . property ( 'sid' ) ;
69+ return '' ;
70+ } ) ;
6471
6572 return client . backchannelLogout ( 'subject' , 'foo' ) ;
6673 } ) ;
0 commit comments