Skip to content

Commit 0692df7

Browse files
aeneasrory-bot
authored andcommitted
chore: remove CreateLoginRequest*
GitOrigin-RevId: 869ab94dc08fd760523dcee330bc5426fc5503f6
1 parent 35a6403 commit 0692df7

File tree

10 files changed

+99
-459
lines changed

10 files changed

+99
-459
lines changed

cmd/cli/handler_janitor_test.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,36 +57,6 @@ func TestJanitorHandler_PurgeTokenNotAfter(t *testing.T) {
5757
}
5858
}
5959

60-
func TestJanitorHandler_PurgeLoginConsentNotAfter(t *testing.T) {
61-
ctx := context.Background()
62-
63-
for k, v := range testhelpers.NotAfterTestCycles {
64-
jt := testhelpers.NewConsentJanitorTestHelper(t, k)
65-
reg, err := jt.GetRegistry(ctx, k)
66-
require.NoError(t, err)
67-
68-
t.Run(fmt.Sprintf("case=%s", k), func(t *testing.T) {
69-
// Setup the test
70-
t.Run("step=setup", jt.LoginConsentNotAfterSetup(ctx, reg.ConsentManager(), reg.ClientManager()))
71-
// Run the cleanup routine
72-
t.Run("step=cleanup", func(t *testing.T) {
73-
cmdx.ExecNoErr(t, newJanitorCmd(),
74-
"janitor",
75-
fmt.Sprintf("--%s=%s", cli.KeepIfYounger, v.String()),
76-
fmt.Sprintf("--%s=%s", cli.ConsentRequestLifespan, jt.GetConsentRequestLifespan(ctx).String()),
77-
fmt.Sprintf("--%s", cli.OnlyRequests),
78-
jt.GetDSN(),
79-
)
80-
})
81-
82-
notAfter := time.Now().Round(time.Second).Add(-v)
83-
consentLifespan := time.Now().Round(time.Second).Add(-jt.GetConsentRequestLifespan(ctx))
84-
t.Run("step=validate", jt.LoginConsentNotAfterValidate(ctx, notAfter, consentLifespan, reg))
85-
})
86-
}
87-
88-
}
89-
9060
func TestJanitorHandler_Arguments(t *testing.T) {
9161
cmdx.ExecNoErr(t, cmd.NewRootCmd(nil, nil),
9262
"janitor",

consent/handler_test.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,17 @@ func TestGetLoginRequest(t *testing.T) {
105105
if tc.exists {
106106
cl := &client.Client{ID: "client" + key}
107107
require.NoError(t, reg.ClientManager().CreateClient(context.Background(), cl))
108-
f, err := reg.ConsentManager().CreateLoginRequest(context.Background(), &flow.LoginRequest{
109-
Client: cl,
108+
109+
f := &flow.Flow{
110110
ID: challenge,
111+
Client: cl,
111112
RequestURL: requestURL,
112113
RequestedAt: time.Now(),
113-
})
114-
require.NoError(t, err)
114+
State: flow.FlowStateLoginInitialized,
115+
NID: reg.Persister().NetworkID(ctx),
116+
}
117+
118+
var err error
115119
challenge, err = f.ToLoginChallenge(ctx, reg)
116120
require.NoError(t, err)
117121

@@ -170,14 +174,17 @@ func TestGetConsentRequest(t *testing.T) {
170174
if tc.exists {
171175
cl := &client.Client{ID: "client" + key}
172176
require.NoError(t, reg.ClientManager().CreateClient(ctx, cl))
173-
lr := &flow.LoginRequest{
177+
178+
f := &flow.Flow{
174179
ID: "login-" + challenge,
175180
Client: cl,
176181
RequestURL: requestURL,
177182
RequestedAt: time.Now(),
183+
State: flow.FlowStateLoginInitialized,
184+
NID: reg.Persister().NetworkID(ctx),
178185
}
179-
f, err := reg.ConsentManager().CreateLoginRequest(ctx, lr)
180-
require.NoError(t, err)
186+
187+
var err error
181188
challenge, err = f.ToLoginChallenge(ctx, reg)
182189
require.NoError(t, err)
183190
_, err = reg.ConsentManager().HandleLoginRequest(ctx, f, challenge, &flow.HandledLoginRequest{
@@ -242,14 +249,15 @@ func TestGetLoginRequestWithDuplicateAccept(t *testing.T) {
242249

243250
cl := &client.Client{ID: "client"}
244251
require.NoError(t, reg.ClientManager().CreateClient(ctx, cl))
245-
f, err := reg.ConsentManager().CreateLoginRequest(ctx, &flow.LoginRequest{
252+
f := flow.Flow{
246253
Client: cl,
247254
ID: challenge,
248255
RequestURL: requestURL,
249256
RequestedAt: time.Now(),
250-
})
251-
require.NoError(t, err)
252-
challenge, err = f.ToLoginChallenge(ctx, reg)
257+
NID: reg.Persister().NetworkID(ctx),
258+
State: flow.FlowStateLoginInitialized,
259+
}
260+
challenge, err := f.ToLoginChallenge(ctx, reg)
253261
require.NoError(t, err)
254262

255263
h := NewHandler(reg, reg.Config())

consent/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ type (
4646
RevokeSubjectLoginSession(ctx context.Context, user string) error
4747
ConfirmLoginSession(ctx context.Context, loginSession *flow.LoginSession) error
4848

49-
CreateLoginRequest(ctx context.Context, req *flow.LoginRequest) (*flow.Flow, error)
50-
CreateLoginRequestFromDeviceRequest(ctx context.Context, f *flow.Flow, req *flow.LoginRequest) (*flow.Flow, error)
5149
GetLoginRequest(ctx context.Context, challenge string) (*flow.LoginRequest, error)
5250
HandleLoginRequest(ctx context.Context, f *flow.Flow, challenge string, r *flow.HandledLoginRequest) (*flow.LoginRequest, error)
5351
VerifyAndInvalidateLoginRequest(ctx context.Context, verifier string) (*flow.HandledLoginRequest, error)
@@ -68,6 +66,8 @@ type (
6866
GetDeviceUserAuthRequest(ctx context.Context, challenge string) (*flow.DeviceUserAuthRequest, error)
6967
HandleDeviceUserAuthRequest(ctx context.Context, f *flow.Flow, challenge string, r *flow.HandledDeviceUserAuthRequest) (*flow.DeviceUserAuthRequest, error)
7068
VerifyAndInvalidateDeviceUserAuthRequest(ctx context.Context, verifier string) (*flow.HandledDeviceUserAuthRequest, error)
69+
70+
NetworkID(ctx context.Context) uuid.UUID
7171
}
7272

7373
ManagerProvider interface {

consent/strategy_default.go

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -256,35 +256,46 @@ func (s *DefaultStrategy) forwardAuthenticationRequest(
256256

257257
// Set the session
258258
cl := sanitizeClientFromRequest(ar)
259-
loginRequest := &flow.LoginRequest{
260-
ID: challenge,
261-
Verifier: verifier,
262-
CSRF: csrf,
263-
Skip: skip,
264-
RequestedScope: []string(ar.GetRequestedScopes()),
265-
RequestedAudience: []string(ar.GetRequestedAudience()),
266-
Subject: subject,
267-
Client: cl,
268-
RequestURL: requestURL,
269-
AuthenticatedAt: sqlxx.NullTime(authenticatedAt),
270-
RequestedAt: time.Now().Truncate(time.Second).UTC(),
271-
SessionID: sqlxx.NullString(sessionID),
272-
OpenIDConnectContext: &flow.OAuth2ConsentRequestOpenIDConnectContext{
273-
IDTokenHintClaims: idTokenHintClaims,
274-
ACRValues: stringsx.Splitx(ar.GetRequestForm().Get("acr_values"), " "),
275-
UILocales: stringsx.Splitx(ar.GetRequestForm().Get("ui_locales"), " "),
276-
Display: ar.GetRequestForm().Get("display"),
277-
LoginHint: ar.GetRequestForm().Get("login_hint"),
278-
},
279-
}
280-
var err error
259+
281260
if f == nil {
282-
f, err = s.r.ConsentManager().CreateLoginRequest(ctx, loginRequest)
261+
// Regular grant
262+
f = &flow.Flow{
263+
ID: challenge,
264+
RequestedScope: []string(ar.GetRequestedScopes()),
265+
RequestedAudience: []string(ar.GetRequestedAudience()),
266+
LoginSkip: skip,
267+
Subject: subject,
268+
OpenIDConnectContext: &flow.OAuth2ConsentRequestOpenIDConnectContext{
269+
IDTokenHintClaims: idTokenHintClaims,
270+
ACRValues: stringsx.Splitx(ar.GetRequestForm().Get("acr_values"), " "),
271+
UILocales: stringsx.Splitx(ar.GetRequestForm().Get("ui_locales"), " "),
272+
Display: ar.GetRequestForm().Get("display"),
273+
LoginHint: ar.GetRequestForm().Get("login_hint"),
274+
},
275+
Client: cl,
276+
ClientID: cl.ID,
277+
RequestURL: requestURL,
278+
SessionID: sqlxx.NullString(sessionID),
279+
LoginWasUsed: false,
280+
LoginVerifier: verifier,
281+
LoginCSRF: csrf,
282+
LoginAuthenticatedAt: sqlxx.NullTime(authenticatedAt),
283+
RequestedAt: time.Now().Truncate(time.Second).UTC(),
284+
State: flow.FlowStateLoginInitialized,
285+
NID: s.r.ConsentManager().NetworkID(ctx),
286+
}
283287
} else {
284-
f, err = s.r.ConsentManager().CreateLoginRequestFromDeviceRequest(ctx, f, loginRequest)
285-
}
286-
if err != nil {
287-
return err
288+
// Device auth grant
289+
f.ID = challenge
290+
f.LoginSkip = skip
291+
f.Subject = subject
292+
f.SessionID = sqlxx.NullString(sessionID)
293+
f.LoginVerifier = verifier
294+
f.LoginCSRF = csrf
295+
f.LoginAuthenticatedAt = sqlxx.NullTime(authenticatedAt)
296+
f.RequestedAt = time.Now().Truncate(time.Second).UTC()
297+
f.State = flow.FlowStateLoginInitialized
298+
f.NID = s.r.ConsentManager().NetworkID(ctx)
288299
}
289300

290301
store, err := s.r.CookieStore(ctx)

consent/test/manager_test_helpers.go

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func MockAuthRequest(key string, authAt bool, network string) (c *flow.LoginRequ
183183
}
184184

185185
f = flow.NewFlow(c)
186+
f.NID = uuid.FromStringOrNil(network)
186187

187188
var err = &flow.RequestDeniedError{
188189
Name: "error_name" + key,
@@ -305,8 +306,6 @@ func SaneMockAuthRequest(t *testing.T, m consent.Manager, ls *flow.LoginSession,
305306
ID: uuid.Must(uuid.NewV4()).String(),
306307
Verifier: uuid.Must(uuid.NewV4()).String(),
307308
}
308-
_, err := m.CreateLoginRequest(context.Background(), c)
309-
require.NoError(t, err)
310309
return c
311310
}
312311

@@ -323,15 +322,16 @@ func TestHelperNID(r interface {
323322
ID: "2022-03-11-ls-nid-test-1",
324323
Subject: "2022-03-11-test-1-sub",
325324
}
326-
testLR := flow.LoginRequest{
327-
ID: "2022-03-11-lr-nid-test-1",
328-
Subject: "2022-03-11-test-1-sub",
329-
Verifier: "2022-03-11-test-1-ver",
330-
RequestedAt: time.Now(),
331-
Client: &client.Client{ID: "2022-03-11-client-nid-test-1"},
325+
testLR := flow.Flow{
326+
ID: "2022-03-11-lr-nid-test-1",
327+
Subject: "2022-03-11-test-1-sub",
328+
LoginVerifier: "2022-03-11-test-1-ver",
329+
RequestedAt: time.Now(),
330+
Client: &client.Client{ID: "2022-03-11-client-nid-test-1"},
331+
NID: t1ValidNID.NetworkID(context.Background()),
332+
State: flow.FlowStateLoginInitialized,
332333
}
333334
testHLR := flow.HandledLoginRequest{
334-
LoginRequest: &testLR,
335335
RememberFor: 120,
336336
Remember: true,
337337
ID: testLR.ID,
@@ -350,19 +350,16 @@ func TestHelperNID(r interface {
350350
require.Error(t, t2InvalidNID.CreateLoginSession(ctx, &testLS))
351351
require.NoError(t, t1ValidNID.CreateLoginSession(ctx, &testLS))
352352

353-
_, err := t2InvalidNID.CreateLoginRequest(ctx, &testLR)
354-
require.Error(t, err)
355-
f, err := t1ValidNID.CreateLoginRequest(ctx, &testLR)
353+
var err error
354+
testLR.ID, err = testLR.ToLoginChallenge(ctx, r)
356355
require.NoError(t, err)
357-
358-
testLR.ID = x.Must(f.ToLoginChallenge(ctx, r))
359356
_, err = t2InvalidNID.GetLoginRequest(ctx, testLR.ID)
360357
require.Error(t, err)
361358
_, err = t1ValidNID.GetLoginRequest(ctx, testLR.ID)
362359
require.NoError(t, err)
363-
_, err = t2InvalidNID.HandleLoginRequest(ctx, f, testLR.ID, &testHLR)
360+
_, err = t2InvalidNID.HandleLoginRequest(ctx, &testLR, testLR.ID, &testHLR)
364361
require.Error(t, err)
365-
_, err = t1ValidNID.HandleLoginRequest(ctx, f, testLR.ID, &testHLR)
362+
_, err = t1ValidNID.HandleLoginRequest(ctx, &testLR, testLR.ID, &testHLR)
366363
require.NoError(t, err)
367364
require.Error(t, t2InvalidNID.ConfirmLoginSession(ctx, &testLS))
368365
require.NoError(t, t1ValidNID.ConfirmLoginSession(ctx, &testLS))
@@ -409,9 +406,6 @@ func ManagerTests(deps Deps, m consent.Manager, clientManager client.Manager, fo
409406
AuthenticatedAt: sqlxx.NullTime(time.Now()),
410407
RequestedAt: time.Now(),
411408
}
412-
413-
_, err := m.CreateLoginRequest(ctx, lr[k])
414-
require.NoError(t, err)
415409
}
416410
})
417411

@@ -585,9 +579,7 @@ func ManagerTests(deps Deps, m consent.Manager, clientManager client.Manager, fo
585579
_, err := m.GetLoginRequest(ctx, loginChallenge)
586580
require.Error(t, err)
587581

588-
f, err = m.CreateLoginRequest(ctx, c)
589-
require.NoError(t, err)
590-
582+
f.NID = deps.Contextualizer().Network(context.Background(), uuid.Nil)
591583
loginChallenge = x.Must(f.ToLoginChallenge(ctx, deps))
592584

593585
got1, err := m.GetLoginRequest(ctx, loginChallenge)
@@ -847,10 +839,10 @@ func ManagerTests(deps Deps, m consent.Manager, clientManager client.Manager, fo
847839
})
848840

849841
t.Run("case=list-used-consent-requests", func(t *testing.T) {
850-
f1, err := m.CreateLoginRequest(ctx, lr["rv1"])
851-
require.NoError(t, err)
852-
f2, err := m.CreateLoginRequest(ctx, lr["rv2"])
853-
require.NoError(t, err)
842+
f1 := flow.NewFlow(lr["rv1"])
843+
f1.NID = deps.Contextualizer().Network(context.Background(), uuid.Nil)
844+
f2 := flow.NewFlow(lr["rv2"])
845+
f2.NID = deps.Contextualizer().Network(context.Background(), uuid.Nil)
854846

855847
cr1, hcr1, _ := MockConsentRequest("rv1", true, 0, false, false, false, "fk-login-challenge", network)
856848
cr2, hcr2, _ := MockConsentRequest("rv2", false, 0, false, false, false, "fk-login-challenge", network)
@@ -873,7 +865,7 @@ func ManagerTests(deps Deps, m consent.Manager, clientManager client.Manager, fo
873865
flow.WithConsentCSRF(cr2.CSRF),
874866
)
875867

876-
_, err = m.HandleConsentRequest(ctx, f1, hcr1)
868+
_, err := m.HandleConsentRequest(ctx, f1, hcr1)
877869
require.NoError(t, err)
878870
_, err = m.HandleConsentRequest(ctx, f2, hcr2)
879871
require.NoError(t, err)
@@ -1169,18 +1161,17 @@ func ManagerTests(deps Deps, m consent.Manager, clientManager client.Manager, fo
11691161
require.NoError(t, m.CreateLoginSession(ctx, &s))
11701162
require.NoError(t, m.ConfirmLoginSession(ctx, &s))
11711163

1172-
lr := &flow.LoginRequest{
1173-
ID: uuid.Must(uuid.NewV4()).String(),
1174-
Subject: uuid.Must(uuid.NewV4()).String(),
1175-
Verifier: uuid.Must(uuid.NewV4()).String(),
1176-
Client: cl,
1177-
AuthenticatedAt: sqlxx.NullTime(time.Now()),
1178-
RequestedAt: time.Now(),
1179-
SessionID: sqlxx.NullString(s.ID),
1164+
f := &flow.Flow{
1165+
ID: uuid.Must(uuid.NewV4()).String(),
1166+
Subject: uuid.Must(uuid.NewV4()).String(),
1167+
LoginVerifier: uuid.Must(uuid.NewV4()).String(),
1168+
Client: cl,
1169+
LoginAuthenticatedAt: sqlxx.NullTime(time.Now()),
1170+
RequestedAt: time.Now(),
1171+
SessionID: sqlxx.NullString(s.ID),
1172+
NID: deps.Contextualizer().Network(ctx, uuid.Nil),
11801173
}
11811174

1182-
f, err := m.CreateLoginRequest(ctx, lr)
1183-
require.NoError(t, err)
11841175
expected := &flow.OAuth2ConsentRequest{
11851176
ConsentRequestID: uuid.Must(uuid.NewV4()).String(),
11861177
Skip: true,
@@ -1189,7 +1180,7 @@ func ManagerTests(deps Deps, m consent.Manager, clientManager client.Manager, fo
11891180
Client: cl,
11901181
ClientID: cl.ID,
11911182
RequestURL: "",
1192-
LoginChallenge: sqlxx.NullString(lr.ID),
1183+
LoginChallenge: sqlxx.NullString(f.ID),
11931184
LoginSessionID: sqlxx.NullString(s.ID),
11941185
Verifier: uuid.Must(uuid.NewV4()).String(),
11951186
CSRF: uuid.Must(uuid.NewV4()).String(),

0 commit comments

Comments
 (0)