@@ -10,6 +10,13 @@ import (
10
10
"net/http/httptest"
11
11
"testing"
12
12
13
+ "google.golang.org/grpc/codes"
14
+ "google.golang.org/grpc/status"
15
+
16
+ grpc "google.golang.org/grpc"
17
+
18
+ iam "github.com/gitpod-io/gitpod/components/iam-api/go/v1"
19
+
13
20
connect "github.com/bufbuild/connect-go"
14
21
"github.com/gitpod-io/gitpod/common-go/experiments"
15
22
"github.com/gitpod-io/gitpod/common-go/experiments/experimentstest"
37
44
)
38
45
39
46
func TestOIDCService_CreateClientConfig (t * testing.T ) {
40
- t .Run ("feature flag disabled returns unathorized " , func (t * testing.T ) {
47
+ t .Run ("feature flag disabled returns unauthorized " , func (t * testing.T ) {
41
48
serverMock , client := setupOIDCService (t , withOIDCFeatureDisabled )
42
49
43
50
serverMock .EXPECT ().GetLoggedInUser (gomock .Any ()).Return (user , nil )
@@ -48,19 +55,29 @@ func TestOIDCService_CreateClientConfig(t *testing.T) {
48
55
require .Equal (t , connect .CodePermissionDenied , connect .CodeOf (err ))
49
56
})
50
57
51
- t .Run ("feature flag enabled returns unimplemented " , func (t * testing.T ) {
58
+ t .Run ("feature flag enabled returns created config " , func (t * testing.T ) {
52
59
serverMock , client := setupOIDCService (t , withOIDCFeatureEnabled )
53
60
54
61
serverMock .EXPECT ().GetLoggedInUser (gomock .Any ()).Return (user , nil )
55
62
56
- _ , err := client .CreateClientConfig (context .Background (), connect .NewRequest (& v1.CreateClientConfigRequest {}))
57
- require .Error (t , err )
58
- require .Equal (t , connect .CodeUnimplemented , connect .CodeOf (err ))
63
+ config := & v1.OIDCClientConfig {
64
+ OidcConfig : & v1.OIDCConfig {Issuer : "test-issuer" },
65
+ Oauth2Config : & v1.OAuth2Config {ClientId : "test-id" , ClientSecret : "test-secret" },
66
+ }
67
+ response , err := client .CreateClientConfig (context .Background (), connect .NewRequest (& v1.CreateClientConfigRequest {
68
+ Config : config ,
69
+ }))
70
+ require .NoError (t , err )
71
+ require .NotNil (t , response )
72
+ config .Oauth2Config .ClientSecret = "REDACTED"
73
+ requireEqualProto (t , & v1.CreateClientConfigResponse {
74
+ Config : config ,
75
+ }, response .Msg )
59
76
})
60
77
}
61
78
62
79
func TestOIDCService_GetClientConfig (t * testing.T ) {
63
- t .Run ("feature flag disabled returns unathorized " , func (t * testing.T ) {
80
+ t .Run ("feature flag disabled returns unauthorized " , func (t * testing.T ) {
64
81
serverMock , client := setupOIDCService (t , withOIDCFeatureDisabled )
65
82
66
83
serverMock .EXPECT ().GetLoggedInUser (gomock .Any ()).Return (user , nil )
@@ -83,7 +100,7 @@ func TestOIDCService_GetClientConfig(t *testing.T) {
83
100
}
84
101
85
102
func TestOIDCService_ListClientConfigs (t * testing.T ) {
86
- t .Run ("feature flag disabled returns unathorized " , func (t * testing.T ) {
103
+ t .Run ("feature flag disabled returns unauthorized " , func (t * testing.T ) {
87
104
serverMock , client := setupOIDCService (t , withOIDCFeatureDisabled )
88
105
89
106
serverMock .EXPECT ().GetLoggedInUser (gomock .Any ()).Return (user , nil )
@@ -106,7 +123,7 @@ func TestOIDCService_ListClientConfigs(t *testing.T) {
106
123
}
107
124
108
125
func TestOIDCService_UpdateClientConfig (t * testing.T ) {
109
- t .Run ("feature flag disabled returns unathorized " , func (t * testing.T ) {
126
+ t .Run ("feature flag disabled returns unauthorized " , func (t * testing.T ) {
110
127
serverMock , client := setupOIDCService (t , withOIDCFeatureDisabled )
111
128
112
129
serverMock .EXPECT ().GetLoggedInUser (gomock .Any ()).Return (user , nil )
@@ -129,7 +146,7 @@ func TestOIDCService_UpdateClientConfig(t *testing.T) {
129
146
}
130
147
131
148
func TestOIDCService_DeleteClientConfig (t * testing.T ) {
132
- t .Run ("feature flag disabled returns unathorized " , func (t * testing.T ) {
149
+ t .Run ("feature flag disabled returns unauthorized " , func (t * testing.T ) {
133
150
serverMock , client := setupOIDCService (t , withOIDCFeatureDisabled )
134
151
135
152
serverMock .EXPECT ().GetLoggedInUser (gomock .Any ()).Return (user , nil )
@@ -159,7 +176,7 @@ func setupOIDCService(t *testing.T, expClient experiments.Client) (*protocol.Moc
159
176
160
177
serverMock := protocol .NewMockAPIInterface (ctrl )
161
178
162
- svc := NewOIDCService (& FakeServerConnPool {api : serverMock }, expClient )
179
+ svc := NewOIDCService (& FakeServerConnPool {api : serverMock }, expClient , & stubOIDCServiceServer {} )
163
180
164
181
_ , handler := v1connect .NewOIDCServiceHandler (svc , connect .WithInterceptors (auth .NewServerInterceptor ()))
165
182
@@ -172,3 +189,24 @@ func setupOIDCService(t *testing.T, expClient experiments.Client) (*protocol.Moc
172
189
173
190
return serverMock , client
174
191
}
192
+
193
+ type stubOIDCServiceServer struct {
194
+ }
195
+
196
+ func (stubOIDCServiceServer ) CreateClientConfig (ctx context.Context , request * iam.CreateClientConfigRequest , options ... grpc.CallOption ) (* iam.CreateClientConfigResponse , error ) {
197
+ return & iam.CreateClientConfigResponse {
198
+ Config : request .GetConfig (),
199
+ }, nil
200
+ }
201
+ func (stubOIDCServiceServer ) GetClientConfig (context.Context , * iam.GetClientConfigRequest , ... grpc.CallOption ) (* iam.GetClientConfigResponse , error ) {
202
+ return nil , status .Errorf (codes .Unimplemented , "method GetClientConfig not implemented" )
203
+ }
204
+ func (stubOIDCServiceServer ) ListClientConfigs (context.Context , * iam.ListClientConfigsRequest , ... grpc.CallOption ) (* iam.ListClientConfigsResponse , error ) {
205
+ return nil , status .Errorf (codes .Unimplemented , "method ListClientConfigs not implemented" )
206
+ }
207
+ func (stubOIDCServiceServer ) UpdateClientConfig (context.Context , * iam.UpdateClientConfigRequest , ... grpc.CallOption ) (* iam.UpdateClientConfigResponse , error ) {
208
+ return nil , status .Errorf (codes .Unimplemented , "method UpdateClientConfig not implemented" )
209
+ }
210
+ func (stubOIDCServiceServer ) DeleteClientConfig (context.Context , * iam.DeleteClientConfigRequest , ... grpc.CallOption ) (* iam.DeleteClientConfigResponse , error ) {
211
+ return nil , status .Errorf (codes .Unimplemented , "method DeleteClientConfig not implemented" )
212
+ }
0 commit comments