• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-server / 1863989307

11 Jun 2025 08:38AM UTC coverage: 66.403% (+0.7%) from 65.731%
1863989307

Pull #720

gitlab-ci

mzedel
test(gui): made e2e tests work with changed tenant token expansion

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #720: MEN-8411 - billing/ organization split

29581 of 44548 relevant lines covered (66.4%)

1.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.67
/backend/pkg/contenttype/middleware.go
1
package contenttype
2

3
import (
4
        "mime"
5
        "net/http"
6
        "slices"
7

8
        "github.com/gin-gonic/gin"
9
        "github.com/pkg/errors"
10

11
        "github.com/mendersoftware/mender-server/pkg/rest.utils"
12
)
13

14
func CheckJSON() gin.HandlerFunc {
3✔
15
        return Middleware("application/json")
3✔
16
}
3✔
17

18
func Middleware(contentTypes ...string) gin.HandlerFunc {
3✔
19
        if len(contentTypes) == 0 {
3✔
20
                panic("contenttype.Middleware initialized with no parameters")
×
21
        }
22

23
        errMsg := "Bad Content-Type, expected "
3✔
24
        for i, ctype := range contentTypes {
6✔
25
                if i > 0 {
3✔
26
                        errMsg += ", "
×
27
                }
×
28
                errMsg += "'" + ctype + "'"
3✔
29
        }
30

31
        return func(c *gin.Context) {
6✔
32
                if c.Request.ContentLength > 0 {
6✔
33
                        contentType, _, err := mime.ParseMediaType(c.GetHeader("Content-Type"))
3✔
34
                        if err != nil {
3✔
35
                                rest.RenderError(c,
×
36
                                        http.StatusBadRequest,
×
37
                                        errors.WithMessage(err, "Invalid value for Content-Type header"),
×
38
                                )
×
39
                                c.Abort()
×
40
                                return
×
41
                        }
×
42

43
                        if !slices.Contains(contentTypes, contentType) {
3✔
44
                                rest.RenderError(c,
×
45
                                        http.StatusUnsupportedMediaType,
×
46
                                        errors.New(errMsg),
×
47
                                )
×
48
                                c.Abort()
×
49
                        }
×
50
                }
51
        }
52
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc