mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package utils
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/git/models/unittest"
|
|
"github.com/hanzoai/git/modules/structs"
|
|
"github.com/hanzoai/git/services/contexttest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTestHookValidation(t *testing.T) {
|
|
unittest.PrepareTestEnv(t)
|
|
|
|
t.Run("Test Validation", func(t *testing.T) {
|
|
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/hooks")
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
contexttest.LoadRepoCommit(t, ctx)
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
|
|
checkCreateHookOption(ctx, &structs.CreateHookOption{
|
|
Type: "native",
|
|
Config: map[string]string{
|
|
"content_type": "json",
|
|
"url": "https://example.com/webhook",
|
|
},
|
|
})
|
|
assert.Equal(t, 0, ctx.Resp.WrittenStatus()) // not written yet
|
|
})
|
|
|
|
t.Run("Test Validation with invalid URL", func(t *testing.T) {
|
|
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/hooks")
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
contexttest.LoadRepoCommit(t, ctx)
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
|
|
checkCreateHookOption(ctx, &structs.CreateHookOption{
|
|
Type: "native",
|
|
Config: map[string]string{
|
|
"content_type": "json",
|
|
"url": "example.com/webhook",
|
|
},
|
|
})
|
|
assert.Equal(t, http.StatusUnprocessableEntity, ctx.Resp.WrittenStatus())
|
|
})
|
|
|
|
t.Run("Test Validation with invalid webhook type", func(t *testing.T) {
|
|
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/hooks")
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
contexttest.LoadRepoCommit(t, ctx)
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
|
|
checkCreateHookOption(ctx, &structs.CreateHookOption{
|
|
Type: "unknown",
|
|
Config: map[string]string{
|
|
"content_type": "json",
|
|
"url": "example.com/webhook",
|
|
},
|
|
})
|
|
assert.Equal(t, http.StatusUnprocessableEntity, ctx.Resp.WrittenStatus())
|
|
})
|
|
|
|
t.Run("Test Validation with empty content type", func(t *testing.T) {
|
|
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/hooks")
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
contexttest.LoadRepoCommit(t, ctx)
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
|
|
checkCreateHookOption(ctx, &structs.CreateHookOption{
|
|
Type: "unknown",
|
|
Config: map[string]string{
|
|
"url": "https://example.com/webhook",
|
|
},
|
|
})
|
|
assert.Equal(t, http.StatusUnprocessableEntity, ctx.Resp.WrittenStatus())
|
|
})
|
|
}
|