|
|
@ -226,45 +226,20 @@ func TestLDAPUserSync(t *testing.T) { |
|
|
|
addAuthSourceLDAP(t, "", "") |
|
|
|
addAuthSourceLDAP(t, "", "") |
|
|
|
auth.SyncExternalUsers(context.Background(), true) |
|
|
|
auth.SyncExternalUsers(context.Background(), true) |
|
|
|
|
|
|
|
|
|
|
|
session := loginUser(t, "user1") |
|
|
|
|
|
|
|
// Check if users exists
|
|
|
|
// Check if users exists
|
|
|
|
for _, u := range gitLDAPUsers { |
|
|
|
for _, gitLDAPUser := range gitLDAPUsers { |
|
|
|
req := NewRequest(t, "GET", "/admin/users?q="+u.UserName) |
|
|
|
dbUser, err := user_model.GetUserByName(db.DefaultContext, gitLDAPUser.UserName) |
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK) |
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
assert.Equal(t, gitLDAPUser.UserName, dbUser.Name) |
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body) |
|
|
|
assert.Equal(t, gitLDAPUser.Email, dbUser.Email) |
|
|
|
|
|
|
|
assert.Equal(t, gitLDAPUser.IsAdmin, dbUser.IsAdmin) |
|
|
|
tr := htmlDoc.doc.Find("table.table tbody tr") |
|
|
|
assert.Equal(t, gitLDAPUser.IsRestricted, dbUser.IsRestricted) |
|
|
|
if !assert.True(t, tr.Length() == 1) { |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tds := tr.Find("td") |
|
|
|
|
|
|
|
if !assert.True(t, tds.Length() > 0) { |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
assert.Equal(t, u.UserName, strings.TrimSpace(tds.Find("td:nth-child(2) a").Text())) |
|
|
|
|
|
|
|
assert.Equal(t, u.Email, strings.TrimSpace(tds.Find("td:nth-child(3) span").Text())) |
|
|
|
|
|
|
|
if u.IsAdmin { |
|
|
|
|
|
|
|
assert.True(t, tds.Find("td:nth-child(5) svg").HasClass("octicon-check")) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
assert.True(t, tds.Find("td:nth-child(5) svg").HasClass("octicon-x")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if u.IsRestricted { |
|
|
|
|
|
|
|
assert.True(t, tds.Find("td:nth-child(6) svg").HasClass("octicon-check")) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
assert.True(t, tds.Find("td:nth-child(6) svg").HasClass("octicon-x")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check if no users exist
|
|
|
|
// Check if no users exist
|
|
|
|
for _, u := range otherLDAPUsers { |
|
|
|
for _, otherLDAPUser := range otherLDAPUsers { |
|
|
|
req := NewRequest(t, "GET", "/admin/users?q="+u.UserName) |
|
|
|
_, err := user_model.GetUserByName(db.DefaultContext, otherLDAPUser.UserName) |
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK) |
|
|
|
assert.True(t, user_model.IsErrUserNotExist(err)) |
|
|
|
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tr := htmlDoc.doc.Find("table.table tbody tr") |
|
|
|
|
|
|
|
assert.True(t, tr.Length() == 0) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|