mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-13 09:18:15 +08:00
Compare commits
3 Commits
ba19e5f341
...
61efe85773
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61efe85773 | ||
|
|
3e44fdc4d1 | ||
|
|
d4e9693765 |
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.34.1
|
||||
uses: aquasecurity/trivy-action@0.34.2
|
||||
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.34.1
|
||||
uses: aquasecurity/trivy-action@0.34.2
|
||||
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