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

fogfish / scud / 44400335410

18 Nov 2026 09:19PM UTC coverage: 86.813% (+7.0%) from 79.768%
44400335410

Pull #45

github

fogfish
(fix) use Go 1.26 in CI workflows
Pull Request #45: (feat) improve scud for SaaS ops

666 of 701 new or added lines in 10 files covered. (95.01%)

6 existing lines in 3 files now uncovered.

1106 of 1274 relevant lines covered (86.81%)

0.96 hits per line

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

96.08
/authorizer/lambda.go
1
//
2
// Copyright (C) 2020 - 2025 Dmitry Kolesnikov
3
//
4
// This file may be modified and distributed under the terms
5
// of the MIT license.  See the LICENSE file for details.
6
// https://github.com/fogfish/scud
7
//
8

9
package authorizer
10

11
import (
12
        "encoding/base64"
13
        "strings"
14

15
        "github.com/aws/aws-lambda-go/events"
16
)
17

18
// Request is the event received by Lambda authorizer of HTTP API configured
19
// with SIMPLE response type (authorizer payload format 2.0), which is
20
// the default of scud.Gateway.NewAuthorizerLambda.
21
//
22
//        lambda.Start(func(req authorizer.Request) (authorizer.Response, error) {
23
//          key, ok := authorizer.Bearer(req)
24
//          if !ok {
25
//            return authorizer.Deny(), nil
26
//          }
27
//          ...
28
//          return authorizer.Allow(map[string]any{"sub": "..."}), nil
29
//        })
30
//
31
// The context of the response is delivered to the integration at
32
// requestContext.authorizer (integration payload format 1.0) or at
33
// requestContext.authorizer.lambda (integration payload format 2.0).
34
type Request = events.APIGatewayV2CustomAuthorizerV2Request
35

36
// Response is the simple response of Lambda authorizer.
37
type Response = events.APIGatewayV2CustomAuthorizerSimpleResponse
38

39
// Allow the request, the context is passed to the integration.
40
func Allow(context map[string]any) Response {
1 ✔
41
        return Response{IsAuthorized: true, Context: context}
1 ✔
42
}
1 ✔
43

44
// Deny the request, API Gateway answers 403 Forbidden to the client.
45
//
46
// Return Deny with nil error to refuse the request. A returned error
47
// is answered 500 Internal Server Error by API Gateway.
48
func Deny() Response {
1 ✔
49
        return Response{IsAuthorized: false}
1 ✔
50
}
1 ✔
51

52
// Header returns value of the request header, the name is case-insensitive.
53
func Header(req Request, name string) (string, bool) {
1 ✔
54
        if val, has := req.Headers[strings.ToLower(name)]; has {
2 ✔
55
                return val, true
1 ✔
56
        }
1 ✔
57

58
        for key, val := range req.Headers {
2 ✔
59
                if strings.EqualFold(key, name) {
2 ✔
60
                        return val, true
1 ✔
61
                }
1 ✔
62
        }
63

64
        return "", false
1 ✔
65
}
66

67
// Query returns value of the query string parameter.
68
func Query(req Request, name string) (string, bool) {
1 ✔
69
        val, has := req.QueryStringParameters[name]
1 ✔
70
        return val, has
1 ✔
71
}
1 ✔
72

73
// Authorization returns the scheme and credentials of Authorization header.
74
// The scheme is case-insensitive, it is returned as given by the client.
75
func Authorization(req Request) (scheme, credentials string, ok bool) {
1 ✔
76
        val, has := Header(req, "Authorization")
1 ✔
77
        if !has {
2 ✔
78
                return "", "", false
1 ✔
79
        }
1 ✔
80

81
        scheme, credentials, ok = strings.Cut(strings.TrimSpace(val), " ")
1 ✔
82
        if !ok {
2 ✔
83
                return "", "", false
1 ✔
84
        }
1 ✔
85

86
        credentials = strings.TrimSpace(credentials)
1 ✔
87
        if credentials == "" {
1 ✔
NEW
88
                return "", "", false
×
NEW
89
        }
×
90

91
        return scheme, credentials, true
1 ✔
92
}
93

94
// Bearer returns token of Authorization: Bearer <token> header.
95
func Bearer(req Request) (string, bool) {
1 ✔
96
        scheme, token, ok := Authorization(req)
1 ✔
97
        if !ok || !strings.EqualFold(scheme, "Bearer") {
2 ✔
98
                return "", false
1 ✔
99
        }
1 ✔
100
        return token, true
1 ✔
101
}
102

103
// BasicCredentials returns user and password of Authorization: Basic <base64> header.
104
// Both padded (RFC 7617) and unpadded base64 are accepted.
105
func BasicCredentials(req Request) (user, password string, ok bool) {
1 ✔
106
        scheme, credentials, ok := Authorization(req)
1 ✔
107
        if !ok || !strings.EqualFold(scheme, "Basic") {
2 ✔
108
                return "", "", false
1 ✔
109
        }
1 ✔
110

111
        c, err := base64.StdEncoding.DecodeString(credentials)
1 ✔
112
        if err != nil {
2 ✔
113
                c, err = base64.RawStdEncoding.DecodeString(credentials)
1 ✔
114
                if err != nil {
2 ✔
115
                        return "", "", false
1 ✔
116
                }
1 ✔
117
        }
118

119
        return strings.Cut(string(c), ":")
1 ✔
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc