@@ -375,14 +375,26 @@ describe('#clients handler', () => {
375375 expect ( wasCreateCalled ) . to . be . equal ( true ) ;
376376 } ) ;
377377
378- it ( 'should get clients' , async ( ) => {
378+ it ( 'should ignore third-party clients if AUTH0_EXCLUDE_THIRD_PARTY_CLIENTS is true' , async ( ) => {
379+ let wasCreateCalled = false ;
380+ const thirdPartyClient = {
381+ name : 'Third-Party Client' ,
382+ is_first_party : false ,
383+ } ;
384+
379385 const auth0 = {
380386 clients : {
381- getAll : ( params ) =>
382- mockPagedData ( params , 'clients' , [
383- { name : 'test client' , client_id : 'FMfcgxvzLDvPsgpRFKkLVrnKqGgkHhQV' } ,
384- { name : 'deploy client' , client_id : 'client_id' } ,
385- ] ) ,
387+ create : function ( data ) {
388+ ( ( ) => expect ( this ) . to . not . be . undefined ) ( ) ;
389+ wasCreateCalled = true ;
390+ expect ( data ) . to . be . an ( 'object' ) ;
391+ expect ( data . name ) . to . equal ( 'Third-Party Client' ) ;
392+ expect ( data . is_first_party ) . to . equal ( false ) ;
393+ return Promise . resolve ( { data } ) ;
394+ } ,
395+ update : ( ) => Promise . resolve ( { data : [ ] } ) ,
396+ delete : ( ) => Promise . resolve ( { data : [ ] } ) ,
397+ getAll : ( params ) => mockPagedData ( params , 'clients' , [ ] ) ,
386398 } ,
387399 connectionProfiles : { getAll : ( params ) => mockPagedData ( params , 'connectionProfiles' , [ ] ) } ,
388400 userAttributeProfiles : {
@@ -391,12 +403,61 @@ describe('#clients handler', () => {
391403 pool,
392404 } ;
393405
394- const handler = new clients . default ( { client : pageClient ( auth0 ) , config } ) ;
395- const data = await handler . getType ( ) ;
396- expect ( data ) . to . deep . equal ( [
397- { client_id : 'FMfcgxvzLDvPsgpRFKkLVrnKqGgkHhQV' , name : 'test client' } ,
398- { client_id : 'client_id' , name : 'deploy client' } ,
399- ] ) ;
406+ const testConfig = function ( key ) {
407+ return testConfig . data && testConfig . data [ key ] ;
408+ } ;
409+ testConfig . data = {
410+ AUTH0_CLIENT_ID : 'client_id' ,
411+ AUTH0_ALLOW_DELETE : true ,
412+ AUTH0_EXCLUDE_THIRD_PARTY_CLIENTS : true ,
413+ } ;
414+
415+ const handler = new clients . default ( {
416+ client : pageClient ( auth0 ) ,
417+ config : testConfig ,
418+ } ) ;
419+ const stageFn = Object . getPrototypeOf ( handler ) . processChanges ;
420+ await stageFn . apply ( handler , [ { clients : [ thirdPartyClient ] } ] ) ;
421+ expect ( wasCreateCalled ) . to . be . equal ( false ) ;
422+ } ) ;
423+
424+ it ( 'should include third-party clients if AUTH0_EXCLUDE_THIRD_PARTY_CLIENTS is false' , async ( ) => {
425+ let wasCreateCalled = false ;
426+ const thirdPartyClient = {
427+ name : 'Third-Party Client' ,
428+ is_first_party : false ,
429+ } ;
430+
431+ const auth0 = {
432+ clients : {
433+ create : function ( data ) {
434+ ( ( ) => expect ( this ) . to . not . be . undefined ) ( ) ;
435+ wasCreateCalled = true ;
436+ return Promise . resolve ( { data } ) ;
437+ } ,
438+ update : ( ) => Promise . resolve ( { data : [ ] } ) ,
439+ delete : ( ) => Promise . resolve ( { data : [ ] } ) ,
440+ getAll : ( params ) => mockPagedData ( params , 'clients' , [ ] ) ,
441+ } ,
442+ pool,
443+ } ;
444+
445+ const testConfig = function ( key ) {
446+ return testConfig . data && testConfig . data [ key ] ;
447+ } ;
448+ testConfig . data = {
449+ AUTH0_CLIENT_ID : 'client_id' ,
450+ AUTH0_ALLOW_DELETE : true ,
451+ AUTH0_EXCLUDE_THIRD_PARTY_CLIENTS : false ,
452+ } ;
453+
454+ const handler = new clients . default ( {
455+ client : pageClient ( auth0 ) ,
456+ config : testConfig ,
457+ } ) ;
458+ const stageFn = Object . getPrototypeOf ( handler ) . processChanges ;
459+ await stageFn . apply ( handler , [ { clients : [ thirdPartyClient ] } ] ) ;
460+ expect ( wasCreateCalled ) . to . be . equal ( true ) ;
400461 } ) ;
401462
402463 it ( 'should get clients with is_first_party when AUTH0_EXCLUDE_THIRD_PARTY_CLIENTS is enabled' , async ( ) => {
0 commit comments