@@ -63,4 +63,36 @@ describe('ActiveDirectory auth method', () => {
6363 configure ( passportStub ) ;
6464 } ) ;
6565
66+ it ( 'should authenticate a valid user and mark them as admin' , async ( ) => {
67+ const mockReq = { } ;
68+ const mockProfile = {
69+ _json : {
70+ sAMAccountName : 'test-user' ,
71+ mail : 'test@test.com' ,
72+ userPrincipalName : 'test@test.com' ,
73+ title : 'Test User' ,
74+ } ,
75+ displayName : 'Test User' ,
76+ } ;
77+
78+ ldapStub . isUserInAdGroup
79+ . onCall ( 0 ) . resolves ( true )
80+ . onCall ( 1 ) . resolves ( true ) ;
81+
82+ const done = sinon . spy ( ) ;
83+
84+ await strategyCallback ( mockReq , mockProfile , { } , done ) ;
85+
86+ expect ( done . calledOnce ) . to . be . true ;
87+ const [ err , user ] = done . firstCall . args ;
88+ expect ( err ) . to . be . null ;
89+ expect ( user ) . to . have . property ( 'username' , 'test-user' ) ;
90+ expect ( user ) . to . have . property ( 'email' , 'test@test.com' ) ;
91+ expect ( user ) . to . have . property ( 'displayName' , 'Test User' ) ;
92+ expect ( user ) . to . have . property ( 'admin' , true ) ;
93+ expect ( user ) . to . have . property ( 'title' , 'Test User' ) ;
94+
95+ expect ( dbStub . updateUser . calledOnce ) . to . be . true ;
96+ } ) ;
97+
6698} ) ;
0 commit comments