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

mendersoftware / mender-server / 1893336421

27 Jun 2025 07:09AM UTC coverage: 65.651% (-0.08%) from 65.731%
1893336421

Pull #764

gitlab-ci

bahaa-ghazal
fix(useradm): Use contenttype middleware for login endpoint

Signed-off-by: Bahaa Aldeen Ghazal <bahaa.ghazal@northern.tech>
Pull Request #764: refactor(useradm): Migrate from ant0nie/go-json-rest to gin-gonic/gin

265 of 312 new or added lines in 6 files covered. (84.94%)

5 existing lines in 2 files now uncovered.

32387 of 49332 relevant lines covered (65.65%)

1.39 hits per line

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

96.3
/backend/pkg/routing/routing.go
1
// Copyright 2024 Northern.tech AS
2
//
3
//        Licensed under the Apache License, Version 2.0 (the "License");
4
//        you may not use this file except in compliance with the License.
5
//        You may obtain a copy of the License at
6
//
7
//            http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//        Unless required by applicable law or agreed to in writing, software
10
//        distributed under the License is distributed on an "AS IS" BASIS,
11
//        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//        See the License for the specific language governing permissions and
13
//        limitations under the License.
14
package routing
15

16
import (
17
        "net/http"
18
        "strings"
19

20
        "github.com/gin-gonic/gin"
21

22
        utils "github.com/mendersoftware/mender-server/pkg/strings"
23
)
24

25
type HttpOptionsGenerator func(methods []string) gin.HandlerFunc
26

27
func AllowHeaderOptionsGenerator(methods []string) gin.HandlerFunc {
3✔
28
        // return a dummy handler for now
3✔
29
        return func(c *gin.Context) {
4✔
30
                for _, m := range methods {
2✔
31
                        c.Writer.Header().Add("Allow", m)
1✔
32
                }
1✔
33
        }
34
}
35

36
func supportsMethod(method string, methods []string) bool {
3✔
37
        return utils.ContainsString(method, methods)
3✔
38
}
3✔
39

40
// Automatically add OPTIONS method support for each defined route,
41
// only if there's no OPTIONS handler for that route yet
42
func AutogenOptionsRoutes(router *gin.Engine, gen HttpOptionsGenerator) {
3✔
43

3✔
44
        routes := router.Routes()
3✔
45
        methodGroups := make(map[string][]string, len(routes))
3✔
46

3✔
47
        for _, route := range routes {
6✔
48
                if strings.HasPrefix(route.Path, "/api/internal") {
3✔
NEW
49
                        continue
×
50
                }
51
                methods, ok := methodGroups[route.Path]
3✔
52
                if !ok {
6✔
53
                        methods = make([]string, 0)
3✔
54
                }
3✔
55

56
                methodGroups[route.Path] = append(methods, route.Method)
3✔
57
        }
58

59
        for route, methods := range methodGroups {
6✔
60
                // skip if there's a handler for OPTIONS already
3✔
61
                if !supportsMethod(http.MethodOptions, methods) {
6✔
62
                        router.OPTIONS(route, gen(methods))
3✔
63
                }
3✔
64
        }
65

66
}
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