mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-06 12:08:20 +08:00
Compare commits
3 Commits
c56075e5be
...
9363400e78
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9363400e78 | ||
|
|
5f4f964325 | ||
|
|
d4e9693765 |
2
.github/workflows/gin.yml
vendored
2
.github/workflows/gin.yml
vendored
@ -78,6 +78,6 @@ jobs:
|
||||
run: make test
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v5
|
||||
uses: codecov/codecov-action@v6
|
||||
with:
|
||||
flags: ${{ matrix.os }},go-${{ matrix.go }},${{ matrix.test-tags }}
|
||||
|
||||
4
.github/workflows/trivy-scan.yml
vendored
4
.github/workflows/trivy-scan.yml
vendored
@ -27,7 +27,7 @@ jobs:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Run Trivy vulnerability scanner (source code)
|
||||
uses: aquasecurity/trivy-action@0.35.0
|
||||
uses: aquasecurity/trivy-action@v0.36.0
|
||||
with:
|
||||
scan-type: "fs"
|
||||
scan-ref: "."
|
||||
@ -44,7 +44,7 @@ jobs:
|
||||
sarif_file: "trivy-results.sarif"
|
||||
|
||||
- name: Run Trivy scanner (table output for logs)
|
||||
uses: aquasecurity/trivy-action@0.35.0
|
||||
uses: aquasecurity/trivy-action@v0.36.0
|
||||
if: always()
|
||||
with:
|
||||
scan-type: "fs"
|
||||
|
||||
64
binding/form_test.go
Normal file
64
binding/form_test.go
Normal file
@ -0,0 +1,64 @@
|
||||
// Copyright 2025 Gin Core Team. All rights reserved.
|
||||
// Use of this source code is governed by a MIT style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package binding
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestFormBindings_Names(t *testing.T) {
|
||||
assert.Equal(t, "form", Form.Name())
|
||||
assert.Equal(t, "form-urlencoded", FormPost.Name())
|
||||
assert.Equal(t, "multipart/form-data", FormMultipart.Name())
|
||||
}
|
||||
|
||||
func TestFormBinding_BasicPost(t *testing.T) {
|
||||
b := Form
|
||||
obj := FooBarStruct{}
|
||||
req := requestWithBody(http.MethodPost, "/", "foo=bar&bar=foo")
|
||||
req.Header.Add("Content-Type", MIMEPOSTForm)
|
||||
err := b.Bind(req, &obj)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "bar", obj.Foo)
|
||||
assert.Equal(t, "foo", obj.Bar)
|
||||
}
|
||||
|
||||
func TestFormPostBinding_Basic(t *testing.T) {
|
||||
b := FormPost
|
||||
obj := FooBarStruct{}
|
||||
req := requestWithBody(http.MethodPost, "/", "foo=bar&bar=foo")
|
||||
req.Header.Add("Content-Type", MIMEPOSTForm)
|
||||
err := b.Bind(req, &obj)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "bar", obj.Foo)
|
||||
assert.Equal(t, "foo", obj.Bar)
|
||||
}
|
||||
|
||||
func TestFormMultipartBinding_BasicMultipart(t *testing.T) {
|
||||
// reuse helper that exists in binding_test.go
|
||||
req := createFormMultipartRequest(t)
|
||||
var obj FooBarStruct
|
||||
err := FormMultipart.Bind(req, &obj)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "bar", obj.Foo)
|
||||
assert.Equal(t, "foo", obj.Bar)
|
||||
}
|
||||
|
||||
// ensure that a non-multipart POST with form content still binds with Form (ParseMultipartForm should be ignored)
|
||||
func TestFormBinding_NonMultipartPostIgnoresMultipartError(t *testing.T) {
|
||||
b := Form
|
||||
obj := FooBarStruct{}
|
||||
req := requestWithBody(http.MethodPost, "/", "foo=bar&bar=foo")
|
||||
// Intentionally do not set multipart content-type so ParseMultipartForm returns ErrNotMultipart and is ignored
|
||||
req.Header.Add("Content-Type", MIMEPOSTForm)
|
||||
err := b.Bind(req, &obj)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "bar", obj.Foo)
|
||||
assert.Equal(t, "foo", obj.Bar)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user