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

mendersoftware / useradm / 1565757771

29 Nov 2024 07:56AM UTC coverage: 87.019%. Remained the same
1565757771

push

gitlab-ci

web-flow
Merge pull request #434 from alfrunes/1.22.x

chore(deps): Upgrade golang to latest

2869 of 3297 relevant lines covered (87.02%)

131.0 hits per line

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

81.82
/authz_simple.go
1
// Copyright 2021 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 main
15

16
import (
17
        "context"
18

19
        "github.com/mendersoftware/useradm/authz"
20
        "github.com/mendersoftware/useradm/jwt"
21
        "github.com/mendersoftware/useradm/scope"
22
)
23

24
// SimpleAuthz is a trivial authorizer, mostly ensuring
25
// proper permission check for the 'create initial user' case.
26
type SimpleAuthz struct {
27
}
28

29
// Authorize makes SimpleAuthz implement the Authorizer interface.
30
func (sa *SimpleAuthz) Authorize(
31
        _ context.Context,
32
        token *jwt.Token,
33
        resource,
34
        action string,
35
) error {
119✔
36
        if token == nil {
119✔
37
                return authz.ErrAuthzUnauthorized
×
38
        }
×
39

40
        tokenScope := token.Claims.Scope
119✔
41

119✔
42
        // allow all actions on all services for 'mender.*'
119✔
43
        if tokenScope == scope.All {
237✔
44
                return nil
118✔
45
        }
118✔
46

47
        return authz.ErrAuthzUnauthorized
1✔
48
}
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