@@ -1298,10 +1298,16 @@ func TestService_StartFlow_WritesIntentAndConsent(t *testing.T) {
12981298 storedFlow = flow
12991299 }).Return (nil )
13001300
1301+ enabled := consent .NewService (slog .New (slog .NewTextHandler (io .Discard , nil )),
1302+ consent.Config {Enabled : true , Documents : map [string ]consent.DocumentConfig {
1303+ "terms_of_service" : {Title : "Terms & Conditions" , Version : "v2" , URL : "https://example.org/t" },
1304+ "privacy_policy" : {Title : "Privacy Policy" , Version : "v1" , URL : "https://example.org/p" },
1305+ }}, nil )
1306+
13011307 srv := authenticate .NewService (nil , authenticate.Config {
13021308 MailOTP : authenticate.MailOTPConfig {Validity : 10 * time .Minute },
13031309 TestUsers : testusers.Config {Enabled : true , OTP : "111111" , Domain : "example.com" },
1304- }, mockFlowRepo , mailer .NewMockDialer (), nil , nil , mockUserService , nil , nil , nil , nil )
1310+ }, mockFlowRepo , mailer .NewMockDialer (), nil , nil , mockUserService , nil , nil , nil , enabled )
13051311 srv .Now = func () time.Time { return timeNow }
13061312
13071313 _ , err := srv .StartFlow (ctx , request )
@@ -1453,25 +1459,35 @@ func TestService_StartFlow_Consent(t *testing.T) {
14531459 assert .ErrorIs (t , err , consent .ErrUnknownDocuments )
14541460 })
14551461
1456- t .Run ("a login checks nothing, because it writes no record" , func (t * testing.T ) {
1462+ t .Run ("a login checks nothing, and persists nothing, because it writes no record" , func (t * testing.T ) {
14571463 mockConsent := mocks .NewConsentService (t )
14581464
14591465 mockFlowRepo , mockUserService , _ , _ , _ := createMocks (t )
14601466 ctx := context .Background ()
14611467 mockUserService .EXPECT ().GetByID (ctx , email ).Return (user.User {ID : "user-id" , Email : email }, nil )
1462- mockFlowRepo .EXPECT ().Set (ctx , mock .Anything ).Return (nil )
1468+
1469+ var storedFlow * authenticate.Flow
1470+ mockFlowRepo .EXPECT ().Set (ctx , mock .Anything ).Run (func (_ context.Context , flow * authenticate.Flow ) {
1471+ storedFlow = flow
1472+ }).Return (nil )
14631473
14641474 srv := authenticate .NewService (nil , authenticate.Config {
14651475 MailOTP : authenticate.MailOTPConfig {Validity : 10 * time .Minute },
14661476 TestUsers : testusers.Config {Enabled : true , OTP : "111111" , Domain : "example.com" },
14671477 }, mockFlowRepo , mailer .NewMockDialer (), nil , nil , mockUserService , nil , nil , nil , mockConsent )
14681478
14691479 _ , err := srv .StartFlow (ctx , authenticate.RegistrationStartRequest {
1470- Method : authenticate .MailOTPAuthMethod .String (),
1471- Email : email ,
1472- Intent : authenticate .FlowIntentLogin ,
1480+ Method : authenticate .MailOTPAuthMethod .String (),
1481+ Email : email ,
1482+ Intent : authenticate .FlowIntentLogin ,
1483+ AcceptedDocumentIDs : acceptedIDs ,
1484+ IPAddress : "10.0.0.1" ,
14731485 })
14741486 require .NoError (t , err )
1487+ require .NotNil (t , storedFlow )
1488+
1489+ _ , ok := storedFlow .Consent ()
1490+ assert .False (t , ok , "a login must persist no consent block" )
14751491 })
14761492
14771493 t .Run ("a deployment with consent disabled ignores the ids rather than rejecting them" , func (t * testing.T ) {
@@ -1487,6 +1503,40 @@ func TestService_StartFlow_Consent(t *testing.T) {
14871503 require .NoError (t , err )
14881504 require .NotNil (t , got )
14891505 })
1506+
1507+ t .Run ("a deployment with consent disabled persists no consent onto the flow" , func (t * testing.T ) {
1508+ disabled := consent .NewService (slog .New (slog .NewTextHandler (io .Discard , nil )),
1509+ consent.Config {Enabled : false }, nil )
1510+
1511+ ctx := context .Background ()
1512+ mockFlowRepo , mockUserService , _ , _ , _ := createMocks (t )
1513+ mockUserService .EXPECT ().GetByID (ctx , email ).
1514+ Return (user.User {}, errors .New ("user not found" )).Maybe ()
1515+
1516+ var storedFlow * authenticate.Flow
1517+ mockFlowRepo .EXPECT ().Set (ctx , mock .Anything ).Run (func (_ context.Context , flow * authenticate.Flow ) {
1518+ storedFlow = flow
1519+ }).Return (nil )
1520+
1521+ srv := authenticate .NewService (nil , authenticate.Config {
1522+ MailOTP : authenticate.MailOTPConfig {Validity : 10 * time .Minute },
1523+ TestUsers : testusers.Config {Enabled : true , OTP : "111111" , Domain : "example.com" },
1524+ }, mockFlowRepo , mailer .NewMockDialer (), nil , nil , mockUserService , nil , nil , nil , disabled )
1525+
1526+ _ , err := srv .StartFlow (ctx , authenticate.RegistrationStartRequest {
1527+ Method : authenticate .MailOTPAuthMethod .String (),
1528+ Email : email ,
1529+ Intent : authenticate .FlowIntentSignup ,
1530+ AcceptedDocumentIDs : acceptedIDs ,
1531+ IPAddress : "10.0.0.1" ,
1532+ })
1533+ require .NoError (t , err )
1534+ require .NotNil (t , storedFlow )
1535+
1536+ _ , ok := storedFlow .Consent ()
1537+ assert .False (t , ok , "a disabled deployment must persist no consent block" )
1538+ assert .Equal (t , authenticate .FlowIntentSignup , storedFlow .Intent ())
1539+ })
14901540}
14911541
14921542// TestFlow_IntentAndConsent covers the accessors directly: the JSON round trip
0 commit comments