webhook_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "gogs.io/gogs/internal/db"
  9. "gogs.io/gogs/internal/mock"
  10. )
  11. func Test_isLocalHostname(t *testing.T) {
  12. tests := []struct {
  13. hostname string
  14. want bool
  15. }{
  16. {hostname: "localhost", want: true},
  17. {hostname: "127.0.0.1", want: true},
  18. {hostname: "::1", want: true},
  19. {hostname: "0:0:0:0:0:0:0:1", want: true},
  20. {hostname: "gogs.io", want: false},
  21. }
  22. for _, test := range tests {
  23. t.Run("", func(t *testing.T) {
  24. assert.Equal(t, test.want, isLocalHostname(test.hostname))
  25. })
  26. }
  27. }
  28. func Test_validateWebhook(t *testing.T) {
  29. l := mock.NewLocale("en", func(s string, _ ...interface{}) string {
  30. return s
  31. })
  32. tests := []struct {
  33. name string
  34. actor *db.User
  35. webhook *db.Webhook
  36. expField string
  37. expMsg string
  38. expOK bool
  39. }{
  40. {
  41. name: "admin bypass local address check",
  42. actor: &db.User{IsAdmin: true},
  43. webhook: &db.Webhook{URL: "http://localhost:3306"},
  44. expOK: true,
  45. },
  46. {
  47. name: "local address not allowed",
  48. actor: &db.User{},
  49. webhook: &db.Webhook{URL: "http://localhost:3306"},
  50. expField: "PayloadURL",
  51. expMsg: "repo.settings.webhook.err_cannot_use_local_addresses",
  52. expOK: false,
  53. },
  54. }
  55. for _, test := range tests {
  56. t.Run(test.name, func(t *testing.T) {
  57. field, msg, ok := validateWebhook(test.actor, l, test.webhook)
  58. assert.Equal(t, test.expOK, ok)
  59. assert.Equal(t, test.expMsg, msg)
  60. assert.Equal(t, test.expField, field)
  61. })
  62. }
  63. }
PANIC: session(release): write data/sessions/d/4/d43160ba1e77797e: no space left on device

PANIC

session(release): write data/sessions/d/4/d43160ba1e77797e: no space left on device
github.com/go-macaron/session@v0.0.0-20190805070824-1a3cdc6f5659/session.go:199 (0x8b2934)
gopkg.in/macaron.v1@v1.3.9/context.go:79 (0x83d0a0)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/context.go:112 (0x84fdb5)
gopkg.in/macaron.v1@v1.3.9/recovery.go:161 (0x84fda8)
gopkg.in/macaron.v1@v1.3.9/logger.go:40 (0x840c73)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/router.go:187 (0x850fc6)
gopkg.in/macaron.v1@v1.3.9/router.go:303 (0x8493e5)
gopkg.in/macaron.v1@v1.3.9/macaron.go:220 (0x841fca)
net/http/server.go:2836 (0x7a79b2)
net/http/server.go:1924 (0x7a341b)
runtime/asm_amd64.s:1373 (0x46f9f0)