resolve review comments

This commit is contained in:
Tim Möhlmann 2023-02-28 16:55:48 +02:00
parent c9ab349d63
commit 08fab97786
4 changed files with 9 additions and 178 deletions

View file

@ -199,7 +199,7 @@ func TestClientIDFromRequest(t *testing.T) {
wantAuthenticated: false,
},
{
name: "unauthenticated",
name: "authenticated",
args: args{
body: strings.NewReader(
url.Values{}.Encode(),
@ -251,144 +251,3 @@ func TestClientIDFromRequest(t *testing.T) {
})
}
}
/*
func TestClientFromRequest(t *testing.T) {
publicClient := func() op.Client {
c := mock.NewMockClient(gomock.NewController(t))
c.EXPECT().AuthMethod().Return(oidc.AuthMethodNone)
return c
}
privateClient := func() op.Client {
c := mock.NewMockClient(gomock.NewController(t))
c.EXPECT().AuthMethod().Return(oidc.AuthMethodPrivateKeyJWT)
return c
}
type args struct {
body io.Reader
p op.ClientProvider
}
type basicAuth struct {
username string
password string
}
tests := []struct {
name string
args args
basicAuth *basicAuth
wantClient bool
wantErr bool
}{
{
name: "missing client id",
args: args{
body: strings.NewReader(
url.Values{}.Encode(),
),
p: testClientProvider{
storage: mock.NewStorage(t),
},
},
wantErr: true,
},
{
name: "get client error",
args: args{
body: strings.NewReader(
url.Values{}.Encode(),
),
p: testClientProvider{
storage: func() op.Storage {
s := mock.NewMockStorage(gomock.NewController(t))
s.EXPECT().AuthorizeClientIDSecret(context.Background(), "foo", "bar").Return(nil)
s.EXPECT().GetClientByClientID(context.Background(), "foo").Return(nil, errors.New("something"))
return s
}(),
},
},
basicAuth: &basicAuth{
username: "foo",
password: "bar",
},
wantErr: true,
},
{
name: "authenticated",
args: args{
body: strings.NewReader(
url.Values{}.Encode(),
),
p: testClientProvider{
storage: func() op.Storage {
s := mock.NewMockStorage(gomock.NewController(t))
s.EXPECT().AuthorizeClientIDSecret(context.Background(), "foo", "bar").Return(nil)
s.EXPECT().GetClientByClientID(context.Background(), "foo").Return(mock.NewClient(t), nil)
return s
}(),
},
},
basicAuth: &basicAuth{
username: "foo",
password: "bar",
},
wantClient: true,
},
{
name: "public",
args: args{
body: strings.NewReader(
url.Values{
"client_id": []string{"foo"},
}.Encode(),
),
p: testClientProvider{
storage: func() op.Storage {
s := mock.NewMockStorage(gomock.NewController(t))
s.EXPECT().GetClientByClientID(context.Background(), "foo").Return(publicClient(), nil)
return s
}(),
},
},
wantClient: true,
},
{
name: "false public",
args: args{
body: strings.NewReader(
url.Values{
"client_id": []string{"foo"},
}.Encode(),
),
p: testClientProvider{
storage: func() op.Storage {
s := mock.NewMockStorage(gomock.NewController(t))
s.EXPECT().GetClientByClientID(context.Background(), "foo").Return(privateClient(), nil)
return s
}(),
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := httptest.NewRequest(http.MethodPost, "/foo", tt.args.body)
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
if tt.basicAuth != nil {
r.SetBasicAuth(tt.basicAuth.username, tt.basicAuth.password)
}
got, err := op.ClientFromRequest(r, tt.args.p)
if tt.wantErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
if tt.wantClient {
assert.NotNil(t, got)
}
})
}
}
*/