@@ -63,4 +63,36 @@ describe('ActiveDirectory auth method', () => {
63
63
configure ( passportStub ) ;
64
64
} ) ;
65
65
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
+
72
+ userPrincipalName :
'[email protected] ' ,
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' , '[email protected] ' ) ;
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
+
66
98
} ) ;
0 commit comments