Skip to content

Commit bd6e26f

Browse files
committed
Upgrade github.com/ory/kratos-client-go to latest v1.x version. Acceptance testing in UI but unit tests still failing
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 68b7847 commit bd6e26f

6 files changed

Lines changed: 75 additions & 47 deletions

File tree

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ require (
5151
github.com/olivere/elastic/v7 v7.0.12
5252
github.com/ory/dockertest/v3 v3.8.1
5353
github.com/ory/hydra-client-go v1.9.2
54-
github.com/ory/kratos-client-go v0.10.1
54+
github.com/ory/kratos-client-go v1.3.8
5555
github.com/phayes/freeport v0.0.0-20171002181615-b8543db493a5
5656
github.com/prometheus/client_golang v1.14.0
5757
github.com/prometheus/client_model v0.3.0
@@ -68,7 +68,7 @@ require (
6868
github.com/spf13/cobra v1.6.1
6969
github.com/spf13/pflag v1.0.5
7070
github.com/spf13/viper v1.8.1
71-
github.com/stretchr/testify v1.8.4
71+
github.com/stretchr/testify v1.10.0
7272
github.com/txn2/txeh v1.2.1
7373
github.com/vbauerster/mpb/v4 v4.11.0
7474
github.com/zenazn/goji v0.9.1-0.20160507202103-64eb34159fe5

go.sum

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,8 @@ github.com/ory/dockertest/v3 v3.8.1 h1:vU/8d1We4qIad2YM0kOwRVtnyue7ExvacPiw1yDm1
773773
github.com/ory/dockertest/v3 v3.8.1/go.mod h1:wSRQ3wmkz+uSARYMk7kVJFDBGm8x5gSxIhI7NDc+BAQ=
774774
github.com/ory/hydra-client-go v1.9.2 h1:sbp+8zwEJvhqSxcY8HiOkXeY2FspsfSOJ5ajJ07xPQo=
775775
github.com/ory/hydra-client-go v1.9.2/go.mod h1:TTg4Gt0SDC8+XoGtj5qzdtqxapfFW+Vmm41PFuC6n/E=
776-
github.com/ory/kratos-client-go v0.10.1 h1:kSRk+0leCJ1nPMS+FPho8b9WMzrKNpgszvta0Xo32QU=
777-
github.com/ory/kratos-client-go v0.10.1/go.mod h1:dOQIsar76K07wMPJD/6aMhrWyY+sFGEagLDLso1CpsA=
776+
github.com/ory/kratos-client-go v1.3.8 h1:S4D5dAURq5C6LbOUU+DgE4ZXxp37IlJG2GngemdF9h0=
777+
github.com/ory/kratos-client-go v1.3.8/go.mod h1:Dc+ANapsPxu+CfdC0yk8TxmvceCmrvNozW+ZGS/xq5o=
778778
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
779779
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
780780
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
@@ -907,8 +907,9 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
907907
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
908908
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
909909
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
910-
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
911910
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
911+
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
912+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
912913
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
913914
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
914915
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
@@ -919,8 +920,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
919920
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
920921
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
921922
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
922-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
923923
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
924+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
925+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
924926
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
925927
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
926928
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
@@ -1141,7 +1143,6 @@ golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4Iltr
11411143
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
11421144
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
11431145
golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
1144-
golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
11451146
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
11461147
golang.org/x/oauth2 v0.6.0 h1:Lh8GPgSKBfWSwFvtuWOfeI3aAAnbXTSutYxJiOJFgIw=
11471148
golang.org/x/oauth2 v0.6.0/go.mod h1:ycmewcwgD4Rpr3eZJLSB4Kyyljb3qDh40vJ8STE5HKw=

go_deps.bzl

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cloud/shared/idprovider/client.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ type hydraAdminClientService interface {
9696
}
9797

9898
type kratosPublicClientService interface {
99-
ToSession(context.Context) kratos.V0alpha2ApiApiToSessionRequest
99+
ToSession(context.Context) kratos.FrontendAPIToSessionRequest
100100
}
101101

102102
type kratosAdminClientService interface {
103-
AdminGetIdentity(context.Context, string) kratos.V0alpha2ApiApiAdminGetIdentityRequest
104-
AdminCreateIdentity(context.Context) kratos.V0alpha2ApiApiAdminCreateIdentityRequest
105-
AdminCreateSelfServiceRecoveryLink(context.Context) kratos.V0alpha2ApiApiAdminCreateSelfServiceRecoveryLinkRequest
103+
GetIdentity(context.Context, string) kratos.IdentityAPIGetIdentityRequest
104+
CreateIdentity(context.Context) kratos.IdentityAPICreateIdentityRequest
105+
CreateRecoveryLinkForIdentity(context.Context) kratos.IdentityAPICreateRecoveryLinkForIdentityRequest
106106
}
107107

108108
// HydraKratosClient implements the Client interface for the a Hydra and Kratos integration.
@@ -206,8 +206,8 @@ func NewHydraKratosClientFromConfig(cfg *HydraKratosConfig) (*HydraKratosClient,
206206
Config: cfg,
207207
httpClient: httpClient,
208208
hydraAdminClient: hydraAdminClient,
209-
kratosAdminClient: kratosAdminClient.V0alpha2Api,
210-
kratosPublicClient: kratosPublicClient.V0alpha2Api,
209+
kratosAdminClient: kratosAdminClient.IdentityAPI,
210+
kratosPublicClient: kratosPublicClient.FrontendAPI,
211211
}, nil
212212
}
213213

@@ -575,7 +575,7 @@ type KratosUserInfo struct {
575575

576576
// GetUserInfo returns the UserInfo for the userID.
577577
func (c *HydraKratosClient) GetUserInfo(ctx context.Context, userID string) (*KratosUserInfo, error) {
578-
id, _, err := c.kratosAdminClient.AdminGetIdentity(ctx, userID).Execute()
578+
id, _, err := c.kratosAdminClient.GetIdentity(ctx, userID).Execute()
579579
if err != nil {
580580
return nil, err
581581
}
@@ -611,8 +611,8 @@ type CreateIdentityResponse struct {
611611
func (c *HydraKratosClient) CreateIdentity(ctx context.Context, email string) (*CreateIdentityResponse, error) {
612612
schemaID := viper.GetString("kratos_schema_id")
613613

614-
body := kratos.NewAdminCreateIdentityBody(schemaID, map[string]interface{}{"email": email})
615-
idResp, _, err := c.kratosAdminClient.AdminCreateIdentity(ctx).AdminCreateIdentityBody(*body).Execute()
614+
body := kratos.NewCreateIdentityBody(schemaID, map[string]interface{}{"email": email})
615+
idResp, _, err := c.kratosAdminClient.CreateIdentity(ctx).CreateIdentityBody(*body).Execute()
616616
if err != nil {
617617
return nil, err
618618
}
@@ -635,9 +635,9 @@ type CreateInviteLinkForIdentityResponse struct {
635635

636636
// CreateInviteLinkForIdentity creates a Kratos recovery link for the identity, which can act like a one-time use invitelink.
637637
func (c *HydraKratosClient) CreateInviteLinkForIdentity(ctx context.Context, req *CreateInviteLinkForIdentityRequest) (*CreateInviteLinkForIdentityResponse, error) {
638-
body := kratos.NewAdminCreateSelfServiceRecoveryLinkBody(req.AuthProviderID)
638+
body := kratos.NewCreateRecoveryLinkForIdentityBody(req.AuthProviderID)
639639
body.SetExpiresIn(viper.GetString("kratos_recovery_link_lifetime"))
640-
recovery, _, err := c.kratosAdminClient.AdminCreateSelfServiceRecoveryLink(ctx).AdminCreateSelfServiceRecoveryLinkBody(*body).Execute()
640+
recovery, _, err := c.kratosAdminClient.CreateRecoveryLinkForIdentity(ctx).CreateRecoveryLinkForIdentityBody(*body).Execute()
641641
if err != nil {
642642
return nil, err
643643
}

src/cloud/shared/idprovider/client_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,15 @@ func makeClientFromConfig(t *testing.T, p *testClientConfig) (*HydraKratosClient
126126
func TestWhoami(t *testing.T) {
127127
client := HydraKratosClient{}
128128

129+
// Create a real kratos client with fake HTTP transport
129130
kratosPublicClient := &kratosFakeAPI{userID: "1234"}
130131
client.kratosPublicClient = kratosPublicClient
132+
client.kratosAdminClient = kratosPublicClient
133+
// kratosConfig := kratos.NewConfiguration()
134+
// kratosConfig.HTTPClient = fakeHTTPClient
135+
// kratosConfig.Servers = []kratos.ServerConfiguration{{URL: "http://fake"}}
136+
// kratosClient := kratos.NewAPIClient(kratosConfig)
137+
// client.kratosPublicClient = kratosClient.FrontendAPI
131138

132139
r := &http.Request{}
133140
r.Header = make(http.Header)
@@ -244,10 +251,11 @@ func TestAcceptHydraLogin(t *testing.T) {
244251
defer cleanup()
245252

246253
// Fake whoami response.
254+
userID := "user"
247255
whoami := &Whoami{
248256
kratosSession: &kratos.Session{
249-
Identity: kratos.Identity{
250-
Id: "user",
257+
Identity: &kratos.Identity{
258+
Id: userID,
251259
},
252260
},
253261
}

src/cloud/shared/idprovider/kratos_fake_test.go

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,65 @@ import (
2626
)
2727

2828
type kratosFakeAPI struct {
29-
kratos.V0alpha2Api
30-
3129
userID string
3230
recoveryLink string
3331
}
3432

35-
func (k kratosFakeAPI) ToSession(ctx context.Context) kratos.V0alpha2ApiApiToSessionRequest {
36-
return kratos.V0alpha2ApiApiToSessionRequest{
37-
ApiService: k,
38-
}
33+
// Create a custom request type that implements the method chaining
34+
type fakeToSessionRequest struct {
35+
kratosFakeAPI *kratosFakeAPI
36+
cookie string
37+
}
38+
39+
func (r *fakeToSessionRequest) Cookie(cookie string) kratos.FrontendAPIToSessionRequest {
40+
r.cookie = cookie
41+
return kratos.FrontendAPIToSessionRequest{}
3942
}
4043

41-
func (k kratosFakeAPI) ToSessionExecute(r kratos.V0alpha2ApiApiToSessionRequest) (*kratos.Session, *http.Response, error) {
44+
func (r *fakeToSessionRequest) Execute() (*kratos.Session, *http.Response, error) {
4245
return &kratos.Session{
43-
Identity: kratos.Identity{
44-
Id: k.userID,
46+
Identity: &kratos.Identity{
47+
Id: r.kratosFakeAPI.userID,
4548
},
4649
}, nil, nil
4750
}
4851

49-
func (k kratosFakeAPI) AdminCreateIdentity(ctx context.Context) kratos.V0alpha2ApiApiAdminCreateIdentityRequest {
50-
return kratos.V0alpha2ApiApiAdminCreateIdentityRequest{
51-
ApiService: k,
52-
}
52+
func (k kratosFakeAPI) ToSession(ctx context.Context) kratos.FrontendAPIToSessionRequest {
53+
return kratos.FrontendAPIToSessionRequest{}
54+
}
55+
56+
// func (k kratosFakeAPI) ToSessionExecute(r kratos.FrontendAPIToSessionRequest) (*kratos.Session, *http.Response, error) {
57+
// return &kratos.Session{
58+
// Identity: &kratos.Identity{
59+
// Id: k.userID,
60+
// },
61+
// }, nil, nil
62+
// }
63+
64+
func (k kratosFakeAPI) GetIdentity(ctx context.Context, id string) kratos.IdentityAPIGetIdentityRequest {
65+
return kratos.IdentityAPIGetIdentityRequest{}
5366
}
5467

55-
func (k kratosFakeAPI) AdminCreateIdentityExecute(r kratos.V0alpha2ApiApiAdminCreateIdentityRequest) (*kratos.Identity, *http.Response, error) {
68+
func (k kratosFakeAPI) GetIdentityExecute(r kratos.IdentityAPIGetIdentityRequest) (*kratos.Identity, *http.Response, error) {
5669
return &kratos.Identity{
5770
Id: k.userID,
5871
}, nil, nil
5972
}
6073

61-
func (k kratosFakeAPI) AdminCreateSelfServiceRecoveryLink(ctx context.Context) kratos.V0alpha2ApiApiAdminCreateSelfServiceRecoveryLinkRequest {
62-
return kratos.V0alpha2ApiApiAdminCreateSelfServiceRecoveryLinkRequest{
63-
ApiService: k,
64-
}
74+
func (k kratosFakeAPI) CreateIdentity(ctx context.Context) kratos.IdentityAPICreateIdentityRequest {
75+
return kratos.IdentityAPICreateIdentityRequest{}
6576
}
6677

67-
func (k kratosFakeAPI) AdminCreateSelfServiceRecoveryLinkExecute(r kratos.V0alpha2ApiApiAdminCreateSelfServiceRecoveryLinkRequest) (*kratos.SelfServiceRecoveryLink, *http.Response, error) {
68-
return &kratos.SelfServiceRecoveryLink{
69-
RecoveryLink: k.recoveryLink,
78+
func (k kratosFakeAPI) CreateIdentityExecute(r kratos.IdentityAPICreateIdentityRequest) (*kratos.Identity, *http.Response, error) {
79+
return &kratos.Identity{
80+
Id: k.userID,
7081
}, nil, nil
7182
}
83+
84+
func (k kratosFakeAPI) CreateRecoveryLinkForIdentity(ctx context.Context) kratos.IdentityAPICreateRecoveryLinkForIdentityRequest {
85+
return kratos.IdentityAPICreateRecoveryLinkForIdentityRequest{}
86+
}
87+
88+
func (k kratosFakeAPI) CreateRecoveryLinkForIdentityExecute(r kratos.IdentityAPICreateRecoveryLinkForIdentityRequest) (*kratos.CreateRecoveryLinkForIdentityBody, *http.Response, error) {
89+
return &kratos.CreateRecoveryLinkForIdentityBody{}, nil, nil
90+
}

0 commit comments

Comments
 (0)