@@ -3606,3 +3606,93 @@ func TestDefaultAccountManager_UpdatePeerIP(t *testing.T) {
3606
3606
require .Error (t , err , "should fail with invalid peer ID" )
3607
3607
})
3608
3608
}
3609
+
3610
+ func TestAddNewUserToDomainAccountWithApproval (t * testing.T ) {
3611
+ manager , err := createManager (t )
3612
+ if err != nil {
3613
+ t .Fatal (err )
3614
+ }
3615
+
3616
+ // Create a domain-based account with user approval enabled
3617
+ existingAccountID := "existing-account"
3618
+ account := newAccountWithId (context .Background (), existingAccountID , "owner-user" , "example.com" , false )
3619
+ account .Settings .Extra = & types.ExtraSettings {
3620
+ UserApprovalRequired : true ,
3621
+ }
3622
+ err = manager .Store .SaveAccount (context .Background (), account )
3623
+ require .NoError (t , err )
3624
+
3625
+ // Set the account as domain primary account
3626
+ account .IsDomainPrimaryAccount = true
3627
+ account .DomainCategory = types .PrivateCategory
3628
+ err = manager .Store .SaveAccount (context .Background (), account )
3629
+ require .NoError (t , err )
3630
+
3631
+ // Test adding new user to existing account with approval required
3632
+ newUserID := "new-user-id"
3633
+ userAuth := nbcontext.UserAuth {
3634
+ UserId : newUserID ,
3635
+ Domain : "example.com" ,
3636
+ DomainCategory : types .PrivateCategory ,
3637
+ }
3638
+
3639
+ acc , err := manager .Store .GetAccount (context .Background (), existingAccountID )
3640
+ require .NoError (t , err )
3641
+ require .True (t , acc .IsDomainPrimaryAccount , "Account should be primary for the domain" )
3642
+ require .Equal (t , "example.com" , acc .Domain , "Account domain should match" )
3643
+
3644
+ returnedAccountID , err := manager .getAccountIDWithAuthorizationClaims (context .Background (), userAuth )
3645
+ require .NoError (t , err )
3646
+ require .Equal (t , existingAccountID , returnedAccountID )
3647
+
3648
+ // Verify user was created with pending approval
3649
+ user , err := manager .Store .GetUserByUserID (context .Background (), store .LockingStrengthNone , newUserID )
3650
+ require .NoError (t , err )
3651
+ assert .True (t , user .Blocked , "User should be blocked when approval is required" )
3652
+ assert .True (t , user .PendingApproval , "User should be pending approval" )
3653
+ assert .Equal (t , existingAccountID , user .AccountID )
3654
+ }
3655
+
3656
+ func TestAddNewUserToDomainAccountWithoutApproval (t * testing.T ) {
3657
+ manager , err := createManager (t )
3658
+ if err != nil {
3659
+ t .Fatal (err )
3660
+ }
3661
+
3662
+ // Create a domain-based account without user approval
3663
+ ownerUserAuth := nbcontext.UserAuth {
3664
+ UserId : "owner-user" ,
3665
+ Domain : "example.com" ,
3666
+ DomainCategory : types .PrivateCategory ,
3667
+ }
3668
+ existingAccountID , err := manager .getAccountIDWithAuthorizationClaims (context .Background (), ownerUserAuth )
3669
+ require .NoError (t , err )
3670
+
3671
+ // Modify the account to disable user approval
3672
+ account , err := manager .Store .GetAccount (context .Background (), existingAccountID )
3673
+ require .NoError (t , err )
3674
+ account .Settings .Extra = & types.ExtraSettings {
3675
+ UserApprovalRequired : false ,
3676
+ }
3677
+ err = manager .Store .SaveAccount (context .Background (), account )
3678
+ require .NoError (t , err )
3679
+
3680
+ // Test adding new user to existing account without approval required
3681
+ newUserID := "new-user-id"
3682
+ userAuth := nbcontext.UserAuth {
3683
+ UserId : newUserID ,
3684
+ Domain : "example.com" ,
3685
+ DomainCategory : types .PrivateCategory ,
3686
+ }
3687
+
3688
+ returnedAccountID , err := manager .getAccountIDWithAuthorizationClaims (context .Background (), userAuth )
3689
+ require .NoError (t , err )
3690
+ require .Equal (t , existingAccountID , returnedAccountID )
3691
+
3692
+ // Verify user was created without pending approval
3693
+ user , err := manager .Store .GetUserByUserID (context .Background (), store .LockingStrengthNone , newUserID )
3694
+ require .NoError (t , err )
3695
+ assert .False (t , user .Blocked , "User should not be blocked when approval is not required" )
3696
+ assert .False (t , user .PendingApproval , "User should not be pending approval" )
3697
+ assert .Equal (t , existingAccountID , user .AccountID )
3698
+ }
0 commit comments