@@ -226,45 +226,20 @@ func TestLDAPUserSync(t *testing.T) {
226226 addAuthSourceLDAP (t , "" , "" )
227227 auth .SyncExternalUsers (context .Background (), true )
228228
229- session := loginUser (t , "user1" )
230229 // Check if users exists
231- for _ , u := range gitLDAPUsers {
232- req := NewRequest (t , "GET" , "/admin/users?q=" + u .UserName )
233- resp := session .MakeRequest (t , req , http .StatusOK )
234-
235- htmlDoc := NewHTMLParser (t , resp .Body )
236-
237- tr := htmlDoc .doc .Find ("table.table tbody tr" )
238- if ! assert .True (t , tr .Length () == 1 ) {
239- continue
240- }
241- tds := tr .Find ("td" )
242- if ! assert .True (t , tds .Length () > 0 ) {
243- continue
244- }
245- assert .Equal (t , u .UserName , strings .TrimSpace (tds .Find ("td:nth-child(2) a" ).Text ()))
246- assert .Equal (t , u .Email , strings .TrimSpace (tds .Find ("td:nth-child(3) span" ).Text ()))
247- if u .IsAdmin {
248- assert .True (t , tds .Find ("td:nth-child(5) svg" ).HasClass ("octicon-check" ))
249- } else {
250- assert .True (t , tds .Find ("td:nth-child(5) svg" ).HasClass ("octicon-x" ))
251- }
252- if u .IsRestricted {
253- assert .True (t , tds .Find ("td:nth-child(6) svg" ).HasClass ("octicon-check" ))
254- } else {
255- assert .True (t , tds .Find ("td:nth-child(6) svg" ).HasClass ("octicon-x" ))
256- }
230+ for _ , gitLDAPUser := range gitLDAPUsers {
231+ dbUser , err := user_model .GetUserByName (db .DefaultContext , gitLDAPUser .UserName )
232+ assert .NoError (t , err )
233+ assert .Equal (t , gitLDAPUser .UserName , dbUser .Name )
234+ assert .Equal (t , gitLDAPUser .Email , dbUser .Email )
235+ assert .Equal (t , gitLDAPUser .IsAdmin , dbUser .IsAdmin )
236+ assert .Equal (t , gitLDAPUser .IsRestricted , dbUser .IsRestricted )
257237 }
258238
259239 // Check if no users exist
260- for _ , u := range otherLDAPUsers {
261- req := NewRequest (t , "GET" , "/admin/users?q=" + u .UserName )
262- resp := session .MakeRequest (t , req , http .StatusOK )
263-
264- htmlDoc := NewHTMLParser (t , resp .Body )
265-
266- tr := htmlDoc .doc .Find ("table.table tbody tr" )
267- assert .True (t , tr .Length () == 0 )
240+ for _ , otherLDAPUser := range otherLDAPUsers {
241+ _ , err := user_model .GetUserByName (db .DefaultContext , otherLDAPUser .UserName )
242+ assert .True (t , user_model .IsErrUserNotExist (err ))
268243 }
269244}
270245
0 commit comments