mirror of
https://github.com/go-gitea/gitea
synced 2025-01-07 00:14:25 +00:00
Remove some unnecessary template helpers (#33069)
DisableGitHooks and DisableImportLocal are only used when editing a user, so only set them in `editUserCommon`
This commit is contained in:
parent
57eb9d0b64
commit
2564c15cb0
@ -13,8 +13,9 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Security settings
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Security settings
|
|
||||||
InstallLock bool
|
InstallLock bool
|
||||||
SecretKey string
|
SecretKey string
|
||||||
InternalToken string // internal access token
|
InternalToken string // internal access token
|
||||||
@ -27,7 +28,7 @@ var (
|
|||||||
ReverseProxyTrustedProxies []string
|
ReverseProxyTrustedProxies []string
|
||||||
MinPasswordLength int
|
MinPasswordLength int
|
||||||
ImportLocalPaths bool
|
ImportLocalPaths bool
|
||||||
DisableGitHooks bool
|
DisableGitHooks = true
|
||||||
DisableWebhooks bool
|
DisableWebhooks bool
|
||||||
OnlyAllowPushIfGiteaEnvironmentSet bool
|
OnlyAllowPushIfGiteaEnvironmentSet bool
|
||||||
PasswordComplexity []string
|
PasswordComplexity []string
|
||||||
|
@ -131,15 +131,9 @@ func NewFuncMap() template.FuncMap {
|
|||||||
"EnableTimetracking": func() bool {
|
"EnableTimetracking": func() bool {
|
||||||
return setting.Service.EnableTimetracking
|
return setting.Service.EnableTimetracking
|
||||||
},
|
},
|
||||||
"DisableGitHooks": func() bool {
|
|
||||||
return setting.DisableGitHooks
|
|
||||||
},
|
|
||||||
"DisableWebhooks": func() bool {
|
"DisableWebhooks": func() bool {
|
||||||
return setting.DisableWebhooks
|
return setting.DisableWebhooks
|
||||||
},
|
},
|
||||||
"DisableImportLocal": func() bool {
|
|
||||||
return !setting.ImportLocalPaths
|
|
||||||
},
|
|
||||||
"UserThemeName": userThemeName,
|
"UserThemeName": userThemeName,
|
||||||
"NotificationSettings": func() map[string]any {
|
"NotificationSettings": func() map[string]any {
|
||||||
return map[string]any{
|
return map[string]any{
|
||||||
|
@ -313,6 +313,8 @@ func editUserCommon(ctx *context.Context) {
|
|||||||
ctx.Data["PageIsAdminUsers"] = true
|
ctx.Data["PageIsAdminUsers"] = true
|
||||||
ctx.Data["DisableRegularOrgCreation"] = setting.Admin.DisableRegularOrgCreation
|
ctx.Data["DisableRegularOrgCreation"] = setting.Admin.DisableRegularOrgCreation
|
||||||
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
|
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
|
||||||
|
ctx.Data["DisableGitHooks"] = setting.DisableGitHooks
|
||||||
|
ctx.Data["DisableImportLocal"] = !setting.ImportLocalPaths
|
||||||
ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice()
|
ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice()
|
||||||
ctx.Data["DisableGravatar"] = setting.Config().Picture.DisableGravatar.Value(ctx)
|
ctx.Data["DisableGravatar"] = setting.Config().Picture.DisableGravatar.Value(ctx)
|
||||||
}
|
}
|
||||||
|
@ -128,16 +128,16 @@
|
|||||||
<input name="restricted" type="checkbox" {{if .User.IsRestricted}}checked{{end}}>
|
<input name="restricted" type="checkbox" {{if .User.IsRestricted}}checked{{end}}>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="inline field {{if DisableGitHooks}}tw-hidden{{end}}">
|
<div class="inline field {{if .DisableGitHooks}}tw-hidden{{end}}">
|
||||||
<div class="ui checkbox" data-tooltip-content="{{ctx.Locale.Tr "admin.users.allow_git_hook_tooltip"}}">
|
<div class="ui checkbox" data-tooltip-content="{{ctx.Locale.Tr "admin.users.allow_git_hook_tooltip"}}">
|
||||||
<label><strong>{{ctx.Locale.Tr "admin.users.allow_git_hook"}}</strong></label>
|
<label><strong>{{ctx.Locale.Tr "admin.users.allow_git_hook"}}</strong></label>
|
||||||
<input name="allow_git_hook" type="checkbox" {{if .User.CanEditGitHook}}checked{{end}} {{if DisableGitHooks}}disabled{{end}}>
|
<input name="allow_git_hook" type="checkbox" {{if .User.CanEditGitHook}}checked{{end}} {{if .DisableGitHooks}}disabled{{end}}>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="inline field {{if or (DisableImportLocal) (.DisableMigrations)}}tw-hidden{{end}}">
|
<div class="inline field {{if or (.DisableImportLocal) (.DisableMigrations)}}tw-hidden{{end}}">
|
||||||
<div class="ui checkbox">
|
<div class="ui checkbox">
|
||||||
<label><strong>{{ctx.Locale.Tr "admin.users.allow_import_local"}}</strong></label>
|
<label><strong>{{ctx.Locale.Tr "admin.users.allow_import_local"}}</strong></label>
|
||||||
<input name="allow_import_local" type="checkbox" {{if .User.CanImportLocal}}checked{{end}} {{if DisableImportLocal}}disabled{{end}}>
|
<input name="allow_import_local" type="checkbox" {{if .User.CanImportLocal}}checked{{end}} {{if .DisableImportLocal}}disabled{{end}}>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{if not .DisableRegularOrgCreation}}
|
{{if not .DisableRegularOrgCreation}}
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
echo "TestGitHookScript"
|
||||||
echo Hello, World!
|
|
||||||
|
@ -12,185 +12,190 @@ import (
|
|||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
"code.gitea.io/gitea/modules/test"
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testHookContent = `#!/bin/bash
|
func TestAPIGitHooks(t *testing.T) {
|
||||||
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
defer test.MockVariableValue(&setting.DisableGitHooks, false)()
|
||||||
|
|
||||||
echo Hello, World!
|
const testHookContent = `#!/bin/bash
|
||||||
|
echo "TestGitHookScript"
|
||||||
`
|
`
|
||||||
|
|
||||||
func TestAPIListGitHooks(t *testing.T) {
|
t.Run("ListGitHooks", func(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 37})
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 37})
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||||
|
|
||||||
// user1 is an admin user
|
// user1 is an admin user
|
||||||
session := loginUser(t, "user1")
|
session := loginUser(t, "user1")
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
||||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git", owner.Name, repo.Name).
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git", owner.Name, repo.Name).
|
||||||
AddTokenAuth(token)
|
AddTokenAuth(token)
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
var apiGitHooks []*api.GitHook
|
var apiGitHooks []*api.GitHook
|
||||||
DecodeJSON(t, resp, &apiGitHooks)
|
DecodeJSON(t, resp, &apiGitHooks)
|
||||||
assert.Len(t, apiGitHooks, 3)
|
assert.Len(t, apiGitHooks, 3)
|
||||||
for _, apiGitHook := range apiGitHooks {
|
for _, apiGitHook := range apiGitHooks {
|
||||||
if apiGitHook.Name == "pre-receive" {
|
if apiGitHook.Name == "pre-receive" {
|
||||||
assert.True(t, apiGitHook.IsActive)
|
assert.True(t, apiGitHook.IsActive)
|
||||||
assert.Equal(t, testHookContent, apiGitHook.Content)
|
assert.Equal(t, testHookContent, apiGitHook.Content)
|
||||||
} else {
|
} else {
|
||||||
|
assert.False(t, apiGitHook.IsActive)
|
||||||
|
assert.Empty(t, apiGitHook.Content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("NoGitHooks", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||||
|
|
||||||
|
// user1 is an admin user
|
||||||
|
session := loginUser(t, "user1")
|
||||||
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
||||||
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git", owner.Name, repo.Name).
|
||||||
|
AddTokenAuth(token)
|
||||||
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
|
var apiGitHooks []*api.GitHook
|
||||||
|
DecodeJSON(t, resp, &apiGitHooks)
|
||||||
|
assert.Len(t, apiGitHooks, 3)
|
||||||
|
for _, apiGitHook := range apiGitHooks {
|
||||||
assert.False(t, apiGitHook.IsActive)
|
assert.False(t, apiGitHook.IsActive)
|
||||||
assert.Empty(t, apiGitHook.Content)
|
assert.Empty(t, apiGitHook.Content)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
|
||||||
|
t.Run("ListGitHooksNoAccess", func(t *testing.T) {
|
||||||
func TestAPIListGitHooksNoHooks(t *testing.T) {
|
defer tests.PrintCurrentTest(t)()
|
||||||
defer tests.PrepareTestEnv(t)()
|
|
||||||
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
|
||||||
|
session := loginUser(t, owner.Name)
|
||||||
// user1 is an admin user
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
||||||
session := loginUser(t, "user1")
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git", owner.Name, repo.Name).
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
AddTokenAuth(token)
|
||||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git", owner.Name, repo.Name).
|
MakeRequest(t, req, http.StatusForbidden)
|
||||||
AddTokenAuth(token)
|
})
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
|
||||||
var apiGitHooks []*api.GitHook
|
t.Run("GetGitHook", func(t *testing.T) {
|
||||||
DecodeJSON(t, resp, &apiGitHooks)
|
defer tests.PrintCurrentTest(t)()
|
||||||
assert.Len(t, apiGitHooks, 3)
|
|
||||||
for _, apiGitHook := range apiGitHooks {
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 37})
|
||||||
assert.False(t, apiGitHook.IsActive)
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||||
assert.Empty(t, apiGitHook.Content)
|
|
||||||
}
|
// user1 is an admin user
|
||||||
}
|
session := loginUser(t, "user1")
|
||||||
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
||||||
func TestAPIListGitHooksNoAccess(t *testing.T) {
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name).
|
||||||
defer tests.PrepareTestEnv(t)()
|
AddTokenAuth(token)
|
||||||
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
var apiGitHook *api.GitHook
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
DecodeJSON(t, resp, &apiGitHook)
|
||||||
|
assert.True(t, apiGitHook.IsActive)
|
||||||
session := loginUser(t, owner.Name)
|
assert.Equal(t, testHookContent, apiGitHook.Content)
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
})
|
||||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git", owner.Name, repo.Name).
|
t.Run("GetGitHookNoAccess", func(t *testing.T) {
|
||||||
AddTokenAuth(token)
|
defer tests.PrintCurrentTest(t)()
|
||||||
MakeRequest(t, req, http.StatusForbidden)
|
|
||||||
}
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||||
func TestAPIGetGitHook(t *testing.T) {
|
|
||||||
defer tests.PrepareTestEnv(t)()
|
session := loginUser(t, owner.Name)
|
||||||
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 37})
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name).
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
AddTokenAuth(token)
|
||||||
|
MakeRequest(t, req, http.StatusForbidden)
|
||||||
// user1 is an admin user
|
})
|
||||||
session := loginUser(t, "user1")
|
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
t.Run("EditGitHook", func(t *testing.T) {
|
||||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name).
|
defer tests.PrintCurrentTest(t)()
|
||||||
AddTokenAuth(token)
|
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
var apiGitHook *api.GitHook
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||||
DecodeJSON(t, resp, &apiGitHook)
|
|
||||||
assert.True(t, apiGitHook.IsActive)
|
// user1 is an admin user
|
||||||
assert.Equal(t, testHookContent, apiGitHook.Content)
|
session := loginUser(t, "user1")
|
||||||
}
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
||||||
|
|
||||||
func TestAPIGetGitHookNoAccess(t *testing.T) {
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/hooks/git/pre-receive",
|
||||||
defer tests.PrepareTestEnv(t)()
|
owner.Name, repo.Name)
|
||||||
|
req := NewRequestWithJSON(t, "PATCH", urlStr, &api.EditGitHookOption{
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
Content: testHookContent,
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
}).AddTokenAuth(token)
|
||||||
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
session := loginUser(t, owner.Name)
|
var apiGitHook *api.GitHook
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
DecodeJSON(t, resp, &apiGitHook)
|
||||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name).
|
assert.True(t, apiGitHook.IsActive)
|
||||||
AddTokenAuth(token)
|
assert.Equal(t, testHookContent, apiGitHook.Content)
|
||||||
MakeRequest(t, req, http.StatusForbidden)
|
|
||||||
}
|
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name).
|
||||||
|
AddTokenAuth(token)
|
||||||
func TestAPIEditGitHook(t *testing.T) {
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
defer tests.PrepareTestEnv(t)()
|
var apiGitHook2 *api.GitHook
|
||||||
|
DecodeJSON(t, resp, &apiGitHook2)
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
assert.True(t, apiGitHook2.IsActive)
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
assert.Equal(t, testHookContent, apiGitHook2.Content)
|
||||||
|
})
|
||||||
// user1 is an admin user
|
|
||||||
session := loginUser(t, "user1")
|
t.Run("EditGitHookNoAccess", func(t *testing.T) {
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/hooks/git/pre-receive",
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
owner.Name, repo.Name)
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||||
req := NewRequestWithJSON(t, "PATCH", urlStr, &api.EditGitHookOption{
|
|
||||||
Content: testHookContent,
|
session := loginUser(t, owner.Name)
|
||||||
}).AddTokenAuth(token)
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name)
|
||||||
var apiGitHook *api.GitHook
|
req := NewRequestWithJSON(t, "PATCH", urlStr, &api.EditGitHookOption{
|
||||||
DecodeJSON(t, resp, &apiGitHook)
|
Content: testHookContent,
|
||||||
assert.True(t, apiGitHook.IsActive)
|
}).AddTokenAuth(token)
|
||||||
assert.Equal(t, testHookContent, apiGitHook.Content)
|
MakeRequest(t, req, http.StatusForbidden)
|
||||||
|
})
|
||||||
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name).
|
|
||||||
AddTokenAuth(token)
|
t.Run("DeleteGitHook", func(t *testing.T) {
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
defer tests.PrintCurrentTest(t)()
|
||||||
var apiGitHook2 *api.GitHook
|
|
||||||
DecodeJSON(t, resp, &apiGitHook2)
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 37})
|
||||||
assert.True(t, apiGitHook2.IsActive)
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||||
assert.Equal(t, testHookContent, apiGitHook2.Content)
|
|
||||||
}
|
// user1 is an admin user
|
||||||
|
session := loginUser(t, "user1")
|
||||||
func TestAPIEditGitHookNoAccess(t *testing.T) {
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
||||||
defer tests.PrepareTestEnv(t)()
|
|
||||||
|
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name).
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
AddTokenAuth(token)
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
MakeRequest(t, req, http.StatusNoContent)
|
||||||
|
|
||||||
session := loginUser(t, owner.Name)
|
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name).
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
AddTokenAuth(token)
|
||||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name)
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
req := NewRequestWithJSON(t, "PATCH", urlStr, &api.EditGitHookOption{
|
var apiGitHook2 *api.GitHook
|
||||||
Content: testHookContent,
|
DecodeJSON(t, resp, &apiGitHook2)
|
||||||
}).AddTokenAuth(token)
|
assert.False(t, apiGitHook2.IsActive)
|
||||||
MakeRequest(t, req, http.StatusForbidden)
|
assert.Empty(t, apiGitHook2.Content)
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestAPIDeleteGitHook(t *testing.T) {
|
t.Run("DeleteGitHookNoAccess", func(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 37})
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||||
|
|
||||||
// user1 is an admin user
|
session := loginUser(t, owner.Name)
|
||||||
session := loginUser(t, "user1")
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name).
|
||||||
|
AddTokenAuth(token)
|
||||||
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name).
|
MakeRequest(t, req, http.StatusForbidden)
|
||||||
AddTokenAuth(token)
|
})
|
||||||
MakeRequest(t, req, http.StatusNoContent)
|
|
||||||
|
|
||||||
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name).
|
|
||||||
AddTokenAuth(token)
|
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
|
||||||
var apiGitHook2 *api.GitHook
|
|
||||||
DecodeJSON(t, resp, &apiGitHook2)
|
|
||||||
assert.False(t, apiGitHook2.IsActive)
|
|
||||||
assert.Empty(t, apiGitHook2.Content)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAPIDeleteGitHookNoAccess(t *testing.T) {
|
|
||||||
defer tests.PrepareTestEnv(t)()
|
|
||||||
|
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
|
||||||
|
|
||||||
session := loginUser(t, owner.Name)
|
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
|
||||||
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name).
|
|
||||||
AddTokenAuth(token)
|
|
||||||
MakeRequest(t, req, http.StatusForbidden)
|
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,6 @@ COLORIZE = true
|
|||||||
LEVEL = Debug
|
LEVEL = Debug
|
||||||
|
|
||||||
[security]
|
[security]
|
||||||
DISABLE_GIT_HOOKS = false
|
|
||||||
INSTALL_LOCK = true
|
INSTALL_LOCK = true
|
||||||
SECRET_KEY = 9pCviYTWSb
|
SECRET_KEY = 9pCviYTWSb
|
||||||
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ
|
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ
|
||||||
|
@ -94,7 +94,6 @@ COLORIZE = true
|
|||||||
LEVEL = Debug
|
LEVEL = Debug
|
||||||
|
|
||||||
[security]
|
[security]
|
||||||
DISABLE_GIT_HOOKS = false
|
|
||||||
INSTALL_LOCK = true
|
INSTALL_LOCK = true
|
||||||
SECRET_KEY = 9pCviYTWSb
|
SECRET_KEY = 9pCviYTWSb
|
||||||
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ
|
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ
|
||||||
|
@ -94,7 +94,6 @@ COLORIZE = true
|
|||||||
LEVEL = Debug
|
LEVEL = Debug
|
||||||
|
|
||||||
[security]
|
[security]
|
||||||
DISABLE_GIT_HOOKS = false
|
|
||||||
INSTALL_LOCK = true
|
INSTALL_LOCK = true
|
||||||
SECRET_KEY = 9pCviYTWSb
|
SECRET_KEY = 9pCviYTWSb
|
||||||
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ
|
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ
|
||||||
|
@ -93,7 +93,6 @@ COLORIZE = true
|
|||||||
LEVEL = Debug
|
LEVEL = Debug
|
||||||
|
|
||||||
[security]
|
[security]
|
||||||
DISABLE_GIT_HOOKS = false
|
|
||||||
INSTALL_LOCK = true
|
INSTALL_LOCK = true
|
||||||
SECRET_KEY = 9pCviYTWSb
|
SECRET_KEY = 9pCviYTWSb
|
||||||
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTI3OTU5ODN9.OQkH5UmzID2XBdwQ9TAI6Jj2t1X-wElVTjbE7aoN4I8
|
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTI3OTU5ODN9.OQkH5UmzID2XBdwQ9TAI6Jj2t1X-wElVTjbE7aoN4I8
|
||||||
|
Loading…
Reference in New Issue
Block a user