Skip to content

Commit dd325f5

Browse files
authored
Merge branch 'main' into dependabot/github_actions/bufbuild/buf-setup-action-1.18.0
2 parents 5f8c736 + ab6ff60 commit dd325f5

7 files changed

Lines changed: 148 additions & 126 deletions

File tree

.github/dependabot.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ updates:
33
- package-ecosystem: gomod
44
directory: "/"
55
schedule:
6-
interval: daily
7-
time: "04:00"
6+
interval: weekly
87
open-pull-requests-limit: 10
98
assignees:
109
- euskadi31

.golangci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ linters-settings:
4949
linters:
5050
disable-all: true
5151
enable:
52-
- deadcode
5352
- depguard
5453
- errcheck
5554
- gas
@@ -61,10 +60,8 @@ linters:
6160
- ineffassign
6261
- megacheck
6362
- misspell
64-
- structcheck
6563
- typecheck
6664
- unconvert
67-
- varcheck
6865
- gosimple
6966
- staticcheck
7067
- unused

auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/base64"
66
"strings"
77

8-
"github.com/grpc-ecosystem/go-grpc-middleware/v2/auth"
8+
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/auth"
99
"google.golang.org/grpc"
1010
"google.golang.org/grpc/codes"
1111
"google.golang.org/grpc/status"

auth_test.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package grpcoauth
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"google.golang.org/grpc"
9+
"google.golang.org/grpc/metadata"
10+
)
11+
12+
type FakeStreamServer struct {
13+
ctx context.Context
14+
}
15+
16+
func (f *FakeStreamServer) SetHeader(metadata.MD) error {
17+
return nil
18+
}
19+
20+
func (f *FakeStreamServer) SendHeader(metadata.MD) error {
21+
return nil
22+
}
23+
24+
func (f *FakeStreamServer) SetTrailer(metadata.MD) {
25+
}
26+
27+
func (f *FakeStreamServer) Context() context.Context {
28+
return f.ctx
29+
}
30+
31+
func (f *FakeStreamServer) SendMsg(m interface{}) error {
32+
return nil
33+
}
34+
35+
func (f *FakeStreamServer) RecvMsg(m interface{}) error {
36+
return nil
37+
}
38+
39+
func TestStreamServerInterceptor(t *testing.T) {
40+
authF := func(ctx context.Context, creds *OAuthCredentials) (context.Context, error) {
41+
assert.Equal(t, "foo", creds.ClientID)
42+
assert.Equal(t, "bar", creds.ClientSecret)
43+
44+
return ctx, nil
45+
}
46+
47+
fss := &FakeStreamServer{
48+
ctx: metadata.NewIncomingContext(context.Background(), metadata.MD{
49+
"authorization": []string{"basic Zm9vOmJhcg=="},
50+
}),
51+
}
52+
53+
err := StreamServerInterceptor(authF)(nil, fss, &grpc.StreamServerInfo{
54+
FullMethod: "/foo.bar",
55+
}, func(srv interface{}, stream grpc.ServerStream) error {
56+
57+
return nil
58+
})
59+
assert.NoError(t, err)
60+
}
61+
62+
func TestStreamServerInterceptorWithBadBasicAuthString(t *testing.T) {
63+
authF := func(ctx context.Context, creds *OAuthCredentials) (context.Context, error) {
64+
assert.Equal(t, "foo", creds.ClientID)
65+
assert.Equal(t, "bar", creds.ClientSecret)
66+
67+
return ctx, nil
68+
}
69+
70+
fss := &FakeStreamServer{
71+
ctx: metadata.NewIncomingContext(context.Background(), metadata.MD{
72+
"authorization": []string{"basic ="},
73+
}),
74+
}
75+
76+
err := StreamServerInterceptor(authF)(nil, fss, &grpc.StreamServerInfo{
77+
FullMethod: "/foo.bar",
78+
}, func(srv interface{}, stream grpc.ServerStream) error {
79+
80+
return nil
81+
})
82+
83+
assert.EqualError(t, err, "rpc error: code = Unauthenticated desc = Basic auth invalid")
84+
}
85+
86+
func TestStreamServerInterceptorWithBadBase64BasicAuthString(t *testing.T) {
87+
authF := func(ctx context.Context, creds *OAuthCredentials) (context.Context, error) {
88+
assert.Equal(t, "foo", creds.ClientID)
89+
assert.Equal(t, "bar", creds.ClientSecret)
90+
91+
return ctx, nil
92+
}
93+
94+
fss := &FakeStreamServer{
95+
ctx: metadata.NewIncomingContext(context.Background(), metadata.MD{
96+
"authorization": []string{"basic YmFk"},
97+
}),
98+
}
99+
100+
err := StreamServerInterceptor(authF)(nil, fss, &grpc.StreamServerInfo{
101+
FullMethod: "/foo.bar",
102+
}, func(srv interface{}, stream grpc.ServerStream) error {
103+
104+
return nil
105+
})
106+
107+
assert.EqualError(t, err, "rpc error: code = Unauthenticated desc = Basic auth invalid")
108+
}

credentials.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ import (
1212
func newOAuth2ClientIDCredentials(clientID string, secret string) credentials.PerRPCCredentials {
1313
token := base64.StdEncoding.EncodeToString([]byte(clientID + ":" + secret))
1414

15-
return oauth.NewOauthAccess(&oauth2.Token{
16-
AccessToken: token,
17-
TokenType: "basic",
18-
})
15+
return &oauth.TokenSource{
16+
TokenSource: oauth2.StaticTokenSource(&oauth2.Token{
17+
AccessToken: token,
18+
TokenType: "basic",
19+
}),
20+
}
1921
}
2022

2123
func newOAuth2AccessTokenCredentials(token string) credentials.PerRPCCredentials {
22-
return oauth.NewOauthAccess(&oauth2.Token{
23-
AccessToken: token,
24-
})
24+
return &oauth.TokenSource{
25+
TokenSource: oauth2.StaticTokenSource(&oauth2.Token{
26+
AccessToken: token,
27+
}),
28+
}
2529
}
2630

2731
// PerRPCClientIDCredentials returns a CallOption that sets credentials.PerRPCCredentials

go.mod

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@ module github.com/hyperscale-stack/grpcoauth
33
go 1.18
44

55
require (
6-
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2
6+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.5
77
github.com/stretchr/testify v1.8.2
8-
golang.org/x/oauth2 v0.7.0
9-
google.golang.org/grpc v1.54.0
8+
golang.org/x/oauth2 v0.8.0
9+
google.golang.org/grpc v1.55.0
10+
google.golang.org/protobuf v1.30.0
1011
)
1112

1213
require (
13-
cloud.google.com/go/compute v1.15.1 // indirect
14+
cloud.google.com/go/compute v1.18.0 // indirect
1415
cloud.google.com/go/compute/metadata v0.2.3 // indirect
1516
github.com/davecgh/go-spew v1.1.1 // indirect
16-
github.com/golang/protobuf v1.5.2 // indirect
17+
github.com/golang/protobuf v1.5.3 // indirect
1718
github.com/kr/pretty v0.1.0 // indirect
1819
github.com/pmezard/go-difflib v1.0.0 // indirect
19-
golang.org/x/net v0.9.0 // indirect
20-
golang.org/x/sys v0.7.0 // indirect
20+
golang.org/x/net v0.10.0 // indirect
21+
golang.org/x/sys v0.8.0 // indirect
2122
golang.org/x/text v0.9.0 // indirect
2223
google.golang.org/appengine v1.6.7 // indirect
23-
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
24-
google.golang.org/grpc/examples v0.0.0-20220902210910-60a3a7e969c4 // indirect
25-
google.golang.org/protobuf v1.28.1 // indirect
24+
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
2625
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
2726
gopkg.in/yaml.v3 v3.0.1 // indirect
2827
)

0 commit comments

Comments
 (0)