You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.9 KiB
Go
109 lines
2.9 KiB
Go
7 years ago
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
2 years ago
|
package integration
|
||
7 years ago
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"testing"
|
||
|
|
||
|
"code.gitea.io/gitea/modules/setting"
|
||
2 years ago
|
"code.gitea.io/gitea/tests"
|
||
7 years ago
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestSettingShowUserEmailExplore(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
7 years ago
|
|
||
|
showUserEmail := setting.UI.ShowUserEmail
|
||
|
setting.UI.ShowUserEmail = true
|
||
|
|
||
|
session := loginUser(t, "user2")
|
||
|
req := NewRequest(t, "GET", "/explore/users")
|
||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||
|
assert.Contains(t,
|
||
|
htmlDoc.doc.Find(".ui.user.list").Text(),
|
||
6 years ago
|
"user4@example.com",
|
||
7 years ago
|
)
|
||
|
|
||
|
setting.UI.ShowUserEmail = false
|
||
|
|
||
|
req = NewRequest(t, "GET", "/explore/users")
|
||
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||
|
htmlDoc = NewHTMLParser(t, resp.Body)
|
||
|
assert.NotContains(t,
|
||
|
htmlDoc.doc.Find(".ui.user.list").Text(),
|
||
6 years ago
|
"user4@example.com",
|
||
7 years ago
|
)
|
||
|
|
||
|
setting.UI.ShowUserEmail = showUserEmail
|
||
|
}
|
||
|
|
||
|
func TestSettingShowUserEmailProfile(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
7 years ago
|
|
||
|
showUserEmail := setting.UI.ShowUserEmail
|
||
|
setting.UI.ShowUserEmail = true
|
||
|
|
||
|
session := loginUser(t, "user2")
|
||
|
req := NewRequest(t, "GET", "/user2")
|
||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||
|
assert.Contains(t,
|
||
|
htmlDoc.doc.Find(".user.profile").Text(),
|
||
|
"user2@example.com",
|
||
|
)
|
||
|
|
||
|
setting.UI.ShowUserEmail = false
|
||
|
|
||
|
req = NewRequest(t, "GET", "/user2")
|
||
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||
|
htmlDoc = NewHTMLParser(t, resp.Body)
|
||
6 years ago
|
// Should contain since this user owns the profile page
|
||
|
assert.Contains(t,
|
||
7 years ago
|
htmlDoc.doc.Find(".user.profile").Text(),
|
||
|
"user2@example.com",
|
||
|
)
|
||
|
|
||
|
setting.UI.ShowUserEmail = showUserEmail
|
||
6 years ago
|
|
||
|
session = loginUser(t, "user4")
|
||
|
req = NewRequest(t, "GET", "/user2")
|
||
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||
|
htmlDoc = NewHTMLParser(t, resp.Body)
|
||
|
assert.NotContains(t,
|
||
|
htmlDoc.doc.Find(".user.profile").Text(),
|
||
|
"user2@example.com",
|
||
|
)
|
||
7 years ago
|
}
|
||
6 years ago
|
|
||
|
func TestSettingLandingPage(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
6 years ago
|
|
||
|
landingPage := setting.LandingPageURL
|
||
|
|
||
|
setting.LandingPageURL = setting.LandingPageHome
|
||
|
req := NewRequest(t, "GET", "/")
|
||
|
MakeRequest(t, req, http.StatusOK)
|
||
|
|
||
|
setting.LandingPageURL = setting.LandingPageExplore
|
||
|
req = NewRequest(t, "GET", "/")
|
||
2 years ago
|
resp := MakeRequest(t, req, http.StatusSeeOther)
|
||
6 years ago
|
assert.Equal(t, "/explore", resp.Header().Get("Location"))
|
||
|
|
||
|
setting.LandingPageURL = setting.LandingPageOrganizations
|
||
|
req = NewRequest(t, "GET", "/")
|
||
2 years ago
|
resp = MakeRequest(t, req, http.StatusSeeOther)
|
||
6 years ago
|
assert.Equal(t, "/explore/organizations", resp.Header().Get("Location"))
|
||
|
|
||
5 years ago
|
setting.LandingPageURL = setting.LandingPageLogin
|
||
|
req = NewRequest(t, "GET", "/")
|
||
2 years ago
|
resp = MakeRequest(t, req, http.StatusSeeOther)
|
||
5 years ago
|
assert.Equal(t, "/user/login", resp.Header().Get("Location"))
|
||
|
|
||
6 years ago
|
setting.LandingPageURL = landingPage
|
||
|
}
|